x86: drop stray W
[deliverable/binutils-gdb.git] / opcodes / i386-gen.c
index 6e457a8cc9770bce1e5af4293288b0a2bebc2ce0..1c5082ea0dcededd03a07f4624629090f63e0f65 100644 (file)
 #include <libintl.h>
 #define _(String) gettext (String)
 
+/* Build-time checks are preferrable over runtime ones.  Use this construct
+   in preference where possible.  */
+#define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
+
 static const char *program_name = NULL;
 static int debug = 0;
 
@@ -440,10 +444,8 @@ static initializer operand_type_init[] =
     "FloatReg" },
   { "OPERAND_TYPE_FLOATACC",
     "FloatAcc" },
-  { "OPERAND_TYPE_SREG2",
-    "SReg2" },
-  { "OPERAND_TYPE_SREG3",
-    "SReg3" },
+  { "OPERAND_TYPE_SREG",
+    "SReg" },
   { "OPERAND_TYPE_JUMPABSOLUTE",
     "JumpAbsolute" },
   { "OPERAND_TYPE_REGMMX",
@@ -639,6 +641,7 @@ static bitfield opcode_modifiers[] =
   BITFIELD (No_ldSuf),
   BITFIELD (FWait),
   BITFIELD (IsString),
+  BITFIELD (RegMem),
   BITFIELD (BNDPrefixOk),
   BITFIELD (NoTrackPrefixOk),
   BITFIELD (IsLockable),
@@ -702,12 +705,10 @@ static bitfield operand_types[] =
   BITFIELD (Control),
   BITFIELD (Debug),
   BITFIELD (Test),
-  BITFIELD (SReg2),
-  BITFIELD (SReg3),
+  BITFIELD (SReg),
   BITFIELD (Acc),
   BITFIELD (JumpAbsolute),
   BITFIELD (EsSeg),
-  BITFIELD (RegMem),
   BITFIELD (Byte),
   BITFIELD (Word),
   BITFIELD (Dword),
@@ -1106,6 +1107,8 @@ process_i386_opcode_modifier (FILE *table, char *mod, char **opnd, int lineno)
 
   if (strcmp (mod, "0"))
     {
+      unsigned int have_w = 0, bwlq_suf = 0xf;
+
       last = mod + strlen (mod);
       for (next = mod; next && next < last; )
        {
@@ -1119,8 +1122,30 @@ process_i386_opcode_modifier (FILE *table, char *mod, char **opnd, int lineno)
                          lineno);
              if (strcasecmp(str, "IsString") == 0)
                active_isstring = 1;
+
+             if (strcasecmp(str, "W") == 0)
+               have_w = 1;
+
+             if (strcasecmp(str, "No_bSuf") == 0)
+               bwlq_suf &= ~1;
+             if (strcasecmp(str, "No_wSuf") == 0)
+               bwlq_suf &= ~2;
+             if (strcasecmp(str, "No_lSuf") == 0)
+               bwlq_suf &= ~4;
+             if (strcasecmp(str, "No_qSuf") == 0)
+               bwlq_suf &= ~8;
            }
        }
+
+      if (have_w && !bwlq_suf)
+       fail ("%s: %d: stray W modifier\n", filename, lineno);
+      if (have_w && !(bwlq_suf & 1))
+       fprintf (stderr, "%s: %d: W modifier without Byte operand(s)\n",
+                filename, lineno);
+      if (have_w && !(bwlq_suf & ~1))
+       fprintf (stderr,
+                "%s: %d: W modifier without Word/Dword/Qword operand(s)\n",
+                filename, lineno);
     }
   output_opcode_modifier (table, modifiers, ARRAY_SIZE (modifiers));
 }
@@ -1668,9 +1693,13 @@ main (int argc, char **argv)
 
   /* Check the unused bitfield in i386_cpu_flags.  */
 #ifdef CpuUnused
+  static_assert (ARRAY_SIZE (cpu_flags) == CpuMax + 2);
+
   if ((cpumax - 1) != CpuMax)
     fail (_("CpuMax != %d!\n"), cpumax);
 #else
+  static_assert (ARRAY_SIZE (cpu_flags) == CpuMax + 1);
+
   if (cpumax != CpuMax)
     fail (_("CpuMax != %d!\n"), cpumax);
 
@@ -1679,8 +1708,14 @@ main (int argc, char **argv)
     fail (_("%d unused bits in i386_cpu_flags.\n"), c);
 #endif
 
+  static_assert (ARRAY_SIZE (opcode_modifiers) == Opcode_Modifier_Num);
+
   /* Check the unused bitfield in i386_operand_type.  */
-#ifndef OTUnused
+#ifdef OTUnused
+  static_assert (ARRAY_SIZE (operand_types) == OTNum + 1);
+#else
+  static_assert (ARRAY_SIZE (operand_types) == OTNum);
+
   c = OTNumOfBits - OTMax - 1;
   if (c)
     fail (_("%d unused bits in i386_operand_type.\n"), c);
This page took 0.026513 seconds and 4 git commands to generate.