* PATCH: Remove " > $@" from i386-tbl.h
@ 2007-09-06 21:30 H.J. Lu
2007-09-06 22:07 ` H.J. Lu
0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2007-09-06 21:30 UTC (permalink / raw)
To: binutils
I am checking this patch to prepare for bitfield in x86 assembler.
H.J.
----
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.
Index: i386-gen.c
===================================================================
--- i386-gen.c (revision 319)
+++ i386-gen.c (working copy)
@@ -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);
}
Index: Makefile.am
===================================================================
--- Makefile.am (revision 319)
+++ Makefile.am (working copy)
@@ -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: Makefile.in
===================================================================
--- Makefile.in (revision 319)
+++ Makefile.in (working copy)
@@ -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)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: Remove " > $@" from i386-tbl.h
2007-09-06 21:30 PATCH: Remove " > $@" from i386-tbl.h H.J. Lu
@ 2007-09-06 22:07 ` H.J. Lu
0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2007-09-06 22:07 UTC (permalink / raw)
To: binutils
On Thu, Sep 06, 2007 at 02:30:20PM -0700, H.J. Lu wrote:
> I am checking this patch to prepare for bitfield in x86 assembler.
>
I am checking this patch to help bitfield in x86 assembler.
H.J.
---
2007-09-06 H.J. Lu <hongjiu.lu@intel.com>
* i386-gen.c (table): Moved ...
(main): Here. Call process_copyright to output copyright.
(process_copyright): New.
(process_i386_opcodes): Take FILE *table.
(process_i386_registers): Likewise.
Index: i386-gen.c
===================================================================
--- i386-gen.c (revision 324)
+++ i386-gen.c (working copy)
@@ -33,9 +33,6 @@
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, ...)
{
@@ -48,6 +45,30 @@ fail (const char *message, ...)
xexit (1);
}
+static void
+process_copyright (FILE *fp)
+{
+ fprintf (fp, "/* 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\
+ This library is free software; you can redistribute it and/or modify\n\
+ it under the terms of the GNU General Public License as published by\n\
+ the Free Software Foundation; either version 3, or (at your option)\n\
+ any later version.\n\
+\n\
+ It is distributed in the hope that it will be useful, but WITHOUT\n\
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n\
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\n\
+ License for more details.\n\
+\n\
+ You should have received a copy of the GNU General Public License\n\
+ along with this program; if not, write to the Free Software\n\
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\n\
+ MA 02110-1301, USA. */\n");
+}
+
/* Remove leading white spaces. */
static char *
@@ -99,7 +120,7 @@ next_field (char *str, char **next)
}
static void
-process_i386_opcodes (void)
+process_i386_opcodes (FILE *table)
{
FILE *fp = fopen ("i386-opc.tbl", "r");
char buf[2048];
@@ -255,7 +276,7 @@ process_i386_opcodes (void)
}
static void
-process_i386_registers (void)
+process_i386_registers (FILE *table)
{
FILE *fp = fopen ("i386-reg.tbl", "r");
char buf[2048];
@@ -362,6 +383,7 @@ main (int argc, char **argv)
extern int chdir (char *);
char *srcdir = NULL;
int c;
+ FILE *table;
program_name = *argv;
xmalloc_set_program_name (program_name);
@@ -399,28 +421,10 @@ main (int argc, char **argv)
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\
- This library is free software; you can redistribute it and/or modify\n\
- it under the terms of the GNU General Public License as published by\n\
- the Free Software Foundation; either version 3, or (at your option)\n\
- any later version.\n\
-\n\
- It is distributed in the hope that it will be useful, but WITHOUT\n\
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n\
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\n\
- License for more details.\n\
-\n\
- You should have received a copy of the GNU General Public License\n\
- along with this program; if not, write to the Free Software\n\
- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\n\
- MA 02110-1301, USA. */\n");
+ process_copyright (table);
- process_i386_opcodes ();
- process_i386_registers ();
+ process_i386_opcodes (table);
+ process_i386_registers (table);
fclose (table);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-09-06 22:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-06 21:30 PATCH: Remove " > $@" from i386-tbl.h H.J. Lu
2007-09-06 22:07 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).