daily update
[deliverable/binutils-gdb.git] / opcodes / z8kgen.c
index cbd316d3d562a7dd1036ed19e2fbcbfdded6f8cf..8f22efda342bcfdb097f41ffc6efbf3ff2466527 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright 2001, 2002, 2003, 2005, 2007, 2009 Free Software Foundation, Inc.
+/* Copyright 2001, 2002, 2003, 2005, 2007, 2009, 2012
+   Free Software Foundation, Inc.
 
    This file is part of the GNU opcodes library.
 
    Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
-/* This program generates z8k-opc.h.  Compile with -fwritable-strings.  */
+/* This program generates z8k-opc.h.  */
 
-#include <stdio.h>
 #include "sysdep.h"
+#include <stdio.h>
 #include "libiberty.h"
 
 #define BYTE_INFO_LEN 10
@@ -32,7 +33,8 @@ struct op
   char type;
   char *bits;
   char *name;
-  char *flavor;
+  /* Unique number for stable sorting.  */
+  int id;
 };
 
 #define iswhite(x) ((x) == ' ' || (x) == '\t')
@@ -547,7 +549,6 @@ static struct op opt[] =
   {"------", 7, 32, "1000 1100 dddd 0001", "ldctlb rbd,ctrl", 0},
   {"CZSVDH", 7, 32, "1000 1100 ssss 1001", "ldctlb ctrl,rbs", 0},
 
-  {"*", 4, 8, "1000 1000 ssss dddd", "xorb rbd,rbs", 0},
   {"*", 0, 0, 0, 0, 0}
 };
 
@@ -574,7 +575,7 @@ func (const void *p1, const void *p2)
   int ret = strcmp (a->name, b->name);
   if (ret != 0)
     return ret;
-  return p1 > p2;
+  return a->id > b->id ? 1 : -1;
 }
 
 
@@ -826,9 +827,12 @@ chewname (char **name)
   return nargs;
 }
 
-static void
+static char *
 sub (char *x, char c)
 {
+  /* Create copy.  */
+  char *ret = xstrdup (x);
+  x = ret;
   while (*x)
     {
       if (x[0] == c && x[1] == c &&
@@ -839,6 +843,7 @@ sub (char *x, char c)
        }
       x++;
     }
+  return ret;
 }
 
 
@@ -909,9 +914,14 @@ static void
 internal (void)
 {
   int c = count ();
-  struct op *new_op = xmalloc (sizeof (struct op) * c);
+  int id;
+  struct op *new_op = xmalloc (sizeof (struct op) * (c + 1));
   struct op *p = opt;
-  memcpy (new_op, p, c * sizeof (struct op));
+  memcpy (new_op, p, (c + 1) * sizeof (struct op));
+
+  /* Assign unique id.  */
+  for (id = 0; id < c; id++)
+    new_op[id].id = id;
 
   /* Sort all names in table alphabetically.  */
   qsort (new_op, c, sizeof (struct op), func);
@@ -937,15 +947,15 @@ internal (void)
          /* Skip the r and sub the string.  */
          s++;
          c = s[1];
-         sub (p->bits, c);
+         p->bits = sub (p->bits, c);
        }
        if (s[0] == '(' && s[3] == ')')
        {
-         sub (p->bits, s[2]);
+         p->bits = sub (p->bits, s[2]);
        }
        if (s[0] == '(')
        {
-         sub (p->bits, s[-1]);
+         p->bits = sub (p->bits, s[-1]);
        }
 
        s++;
@@ -962,12 +972,17 @@ static void
 gas (void)
 {
   int c = count ();
+  int id;
   struct op *p = opt;
   int idx = -1;
   char *oldname = "";
-  struct op *new_op = xmalloc (sizeof (struct op) * c);
+  struct op *new_op = xmalloc (sizeof (struct op) * (c + 1));
+
+  memcpy (new_op, p, (c + 1) * sizeof (struct op));
 
-  memcpy (new_op, p, c * sizeof (struct op));
+  /* Assign unique id.  */
+  for (id = 0; id < c; id++)
+    new_op[id].id = id;
 
   /* Sort all names in table alphabetically.  */
   qsort (new_op, c, sizeof (struct op), func);
@@ -1284,7 +1299,7 @@ gas (void)
   printf ("#ifdef DEFINE_TABLE\n");
   printf ("const opcode_entry_type z8k_table[] = {\n");
 
-  while (new_op->flags && new_op->flags[0])
+  while (new_op->flags && new_op->flags[0] != '*')
     {
       int nargs;
       int length;
This page took 0.026883 seconds and 4 git commands to generate.