2007-09-06 H.J. Lu <hongjiu.lu@intel.com>
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Sep 2007 21:31:55 +0000 (21:31 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Sep 2007 21:31:55 +0000 (21:31 +0000)
* i386-gen.c (table): New.
(process_i386_opcodes): Report errno when faied to open
i386-opc.tbl.  Output opcodes to table.  Close i386-opc.tbl
before return.
(process_i386_registers): Report errno when faied to open
i386-reg.tbl.  Output opcodes to table.  Close i386-reg.tbl
before return.
(main): Open i386-tbl.h for output.

* Makefile.am ($(srcdir)/i386-tbl.h): Remove " > $@".
* Makefile.in: Regenerated.

opcodes/ChangeLog
opcodes/Makefile.am
opcodes/Makefile.in
opcodes/i386-gen.c

index 3c9ee7be89b2a42c7a8087e1b42a16b41c415497..c1cc6ce17b9cc1633cc95dca5e654fde837843d4 100644 (file)
@@ -1,3 +1,17 @@
+2007-09-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * i386-gen.c (table): New.
+       (process_i386_opcodes): Report errno when faied to open
+       i386-opc.tbl.  Output opcodes to table.  Close i386-opc.tbl
+       before return.
+       (process_i386_registers): Report errno when faied to open
+       i386-reg.tbl.  Output opcodes to table.  Close i386-reg.tbl
+       before return.
+       (main): Open i386-tbl.h for output.
+
+       * Makefile.am ($(srcdir)/i386-tbl.h): Remove " > $@".
+       * Makefile.in: Regenerated.
+
 2007-09-06  H.J. Lu  <hongjiu.lu@intel.com>
 
        * i386-opc.tbl: Correct SVME instructions to allow 32bit register
index ff1cb39a5ae80415e30108c881fbb73af8ee772a..b0d81140504cba838a9845820efbf14160fddc2c 100644 (file)
@@ -576,7 +576,7 @@ i386-gen: i386-gen.o
 i386-gen.o: i386-gen.c i386-opc.h
 
 $(srcdir)/i386-tbl.h: @MAINT@ i386-gen i386-opc.tbl i386-reg.tbl
-       ./i386-gen --srcdir $(srcdir) > $@
+       ./i386-gen --srcdir $(srcdir)
 
 ia64-gen: ia64-gen.o
        $(LINK) ia64-gen.o $(LIBIBERTY)
index 953f261525932f852beab11733d116929b5dfbf9..42f83ad865c01139e107178ffdaab199e2d14e44 100644 (file)
@@ -1127,7 +1127,7 @@ i386-gen: i386-gen.o
 i386-gen.o: i386-gen.c i386-opc.h
 
 $(srcdir)/i386-tbl.h: @MAINT@ i386-gen i386-opc.tbl i386-reg.tbl
-       ./i386-gen --srcdir $(srcdir) > $@
+       ./i386-gen --srcdir $(srcdir)
 
 ia64-gen: ia64-gen.o
        $(LINK) ia64-gen.o $(LIBIBERTY)
index fc27504efbdbb40baa657d68d6de6aad4507c920..2be26f1de8e9ccada9d8175bb5c4ed6d3dfa9caf 100644 (file)
@@ -33,6 +33,9 @@
 static const char *program_name = NULL;
 static int debug = 0;
 
+/* File of i386 opcode and register tables.  */
+static FILE *table;
+
 static void
 fail (const char *message, ...)
 {
@@ -106,10 +109,11 @@ process_i386_opcodes (void)
   char *cpu_flags, *opcode_modifier, *operand_types [MAX_OPERANDS];
 
   if (fp == NULL)
-    fail (_("can't find i386-opc.tbl for reading\n"));
+    fail (_("can't find i386-opc.tbl for reading, errno = %s\n"),
+         strerror (errno));
 
-  printf ("\n/* i386 opcode table.  */\n\n");
-  printf ("const template i386_optab[] =\n{\n");
+  fprintf (table, "\n/* i386 opcode table.  */\n\n");
+  fprintf (table, "const template i386_optab[] =\n{\n");
 
   while (!feof (fp))
     {
@@ -129,7 +133,7 @@ process_i386_opcodes (void)
       switch (p[0])
        {
        case '#':
-         printf ("%s\n", p);
+         fprintf (table, "%s\n", p);
        case '\0':
          continue;
          break;
@@ -218,13 +222,13 @@ process_i386_opcodes (void)
            }
        }
 
-      printf ("  { \"%s\", %s, %s, %s, %s,\n",
-             name, operands, base_opcode, extension_opcode,
-             cpu_flags);
+      fprintf (table, "  { \"%s\", %s, %s, %s, %s,\n",
+              name, operands, base_opcode, extension_opcode,
+              cpu_flags);
 
-      printf ("    %s,\n", opcode_modifier);
+      fprintf (table, "    %s,\n", opcode_modifier);
 
-      printf ("    { ");
+      fprintf (table, "    { ");
 
       for (i = 0; i < ARRAY_SIZE (operand_types); i++)
        {
@@ -232,20 +236,22 @@ process_i386_opcodes (void)
              || *operand_types[i] == '0')
            {
              if (i == 0)
-               printf ("0");
+               fprintf (table, "0");
              break;
            }
 
          if (i != 0)
-           printf (",\n      ");
+           fprintf (table, ",\n      ");
 
-         printf ("%s", operand_types[i]);
+         fprintf (table, "%s", operand_types[i]);
        }
-      printf (" } },\n");
+      fprintf (table, " } },\n");
     }
 
-  printf ("  { NULL, 0, 0, 0, 0, 0, { 0 } }\n");
-  printf ("};\n");
+  fclose (fp);
+
+  fprintf (table, "  { NULL, 0, 0, 0, 0, 0, { 0 } }\n");
+  fprintf (table, "};\n");
 }
 
 static void
@@ -257,10 +263,11 @@ process_i386_registers (void)
   char *reg_name, *reg_type, *reg_flags, *reg_num;
 
   if (fp == NULL)
-    fail (_("can't find i386-reg.tbl for reading\n"));
+    fail (_("can't find i386-reg.tbl for reading, errno = %s\n"),
+         strerror (errno));
 
-  printf ("\n/* i386 register table.  */\n\n");
-  printf ("const reg_entry i386_regtab[] =\n{\n");
+  fprintf (table, "\n/* i386 register table.  */\n\n");
+  fprintf (table, "const reg_entry i386_regtab[] =\n{\n");
 
   while (!feof (fp))
     {
@@ -280,7 +287,7 @@ process_i386_registers (void)
       switch (p[0])
        {
        case '#':
-         printf ("%s\n", p);
+         fprintf (table, "%s\n", p);
        case '\0':
          continue;
          break;
@@ -311,13 +318,15 @@ process_i386_registers (void)
       /* Find reg_num.  */
       reg_num = next_field (str, &str);
 
-      printf ("  { \"%s\", %s, %s, %s },\n",
-             reg_name, reg_type, reg_flags, reg_num);
+      fprintf (table, "  { \"%s\", %s, %s, %s },\n",
+              reg_name, reg_type, reg_flags, reg_num);
     }
 
-  printf ("};\n");
+  fclose (fp);
+
+  fprintf (table, "};\n");
 
-  printf ("\nconst unsigned int i386_regtab_size = ARRAY_SIZE (i386_regtab);\n");
+  fprintf (table, "\nconst unsigned int i386_regtab_size = ARRAY_SIZE (i386_regtab);\n");
 }
 
 /* Program options.  */
@@ -386,8 +395,12 @@ main (int argc, char **argv)
       fail (_("unable to change directory to \"%s\", errno = %s\n"),
            srcdir, strerror (errno));
 
-  printf ("/* This file is automatically generated by i386-gen.  Do not edit!  */\n");
-  printf ("/* Copyright 2007  Free Software Foundation, Inc.\n\
+  table = fopen ("i386-tbl.h", "w");
+  if (table == NULL)
+    fail (_("can't create i386-tbl.h, errno = %s\n"), strerror (errno));
+
+  fprintf (table, "/* This file is automatically generated by i386-gen.  Do not edit!  */\n\
+/* Copyright 2007  Free Software Foundation, Inc.\n\
 \n\
    This file is part of the GNU opcodes library.\n\
 \n\
@@ -409,5 +422,7 @@ main (int argc, char **argv)
   process_i386_opcodes ();
   process_i386_registers ();
 
+  fclose (table);
+
   exit (0);
 }
This page took 0.042737 seconds and 4 git commands to generate.