Move conditional opcodes close to enum ccode definition
authorCyrill Gorcunov <gorcunov@gmail.com>
Sun, 3 Mar 2013 10:34:31 +0000 (14:34 +0400)
committerCyrill Gorcunov <gorcunov@gmail.com>
Sun, 3 Mar 2013 10:34:31 +0000 (14:34 +0400)
Thus if someone need to rework this code he won't need
to jump between files trying to figure out where enum
and opcodes lay.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
assemble.c
nasm.h

index 7ed0892..a798d17 100644 (file)
@@ -1218,11 +1218,6 @@ static void gencode(int32_t segment, int64_t offset, int bits,
                     insn * ins, const struct itemplate *temp,
                     int64_t insn_end)
 {
-    static const char condval[] = {   /* conditional opcodes */
-        0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xF, 0xD, 0xC, 0xE, 0x6, 0x2,
-        0x3, 0x7, 0x3, 0x5, 0xE, 0xC, 0xD, 0xF, 0x1, 0xB, 0x9, 0x5,
-        0x0, 0xA, 0xA, 0xB, 0x8, 0x4
-    };
     uint8_t c;
     uint8_t bytes[4];
     int64_t size;
@@ -1561,7 +1556,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
             break;
 
         case 0330:
-            *bytes = *codes++ ^ condval[ins->condition];
+            *bytes = *codes++ ^ get_cond_opcode(ins->condition);
             out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG);
             offset += 1;
             break;
diff --git a/nasm.h b/nasm.h
index a9bff49..97cef3c 100644 (file)
--- a/nasm.h
+++ b/nasm.h
@@ -466,6 +466,17 @@ enum ccode { /* condition code names */
     C_none = -1
 };
 
+static inline uint8_t get_cond_opcode(enum ccode c)
+{
+    static const uint8_t ccode_opcodes[] = {
+        0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xf, 0xd, 0xc, 0xe, 0x6, 0x2,
+        0x3, 0x7, 0x3, 0x5, 0xe, 0xc, 0xd, 0xf, 0x1, 0xb, 0x9, 0x5,
+        0x0, 0xa, 0xa, 0xb, 0x8, 0x4
+    };
+
+       return ccode_opcodes[(int)c];
+}
+
 /*
  * REX flags
  */