diff options
author | Peter Johnson <peter@tortall.net> | 2007-09-10 07:15:50 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2007-09-10 07:15:50 +0000 |
commit | d0033b06c510a3b4d67092e384fb40f052323b7e (patch) | |
tree | 78956bcc67481b0bb0d72546abc10e25ac61bae1 | |
parent | 0e349f552d3f7008ea28bb0fc67767b594537777 (diff) | |
download | yasm-d0033b06c510a3b4d67092e384fb40f052323b7e.tar.gz |
Change genperf to take input and output filenames rather than outputting to
standard output. This makes for better error handling behavior with make
(redirecting the standard output could leave empty files behind on error).
svn path=/trunk/yasm/; revision=1939
-rw-r--r-- | Mkfiles/vc/genperf/run.bat | 8 | ||||
-rw-r--r-- | Mkfiles/vc8/genperf/run.bat | 8 | ||||
-rw-r--r-- | modules/arch/x86/Makefile.inc | 4 | ||||
-rw-r--r-- | tools/genperf/Makefile.inc | 2 | ||||
-rw-r--r-- | tools/genperf/genperf.c | 28 |
5 files changed, 30 insertions, 20 deletions
diff --git a/Mkfiles/vc/genperf/run.bat b/Mkfiles/vc/genperf/run.bat index 1cf44bfc..4364ead0 100644 --- a/Mkfiles/vc/genperf/run.bat +++ b/Mkfiles/vc/genperf/run.bat @@ -1,5 +1,5 @@ cd ..\..\..\
-%1 x86insn_nasm.gperf > x86insn_nasm.c
-%1 x86insn_gas.gperf > x86insn_gas.c
-%1 modules\arch\x86\x86cpu.gperf > x86cpu.c
-%1 modules\arch\x86\x86regtmod.gperf > x86regtmod.c
+%1 x86insn_nasm.gperf x86insn_nasm.c
+%1 x86insn_gas.gperf x86insn_gas.c
+%1 modules\arch\x86\x86cpu.gperf x86cpu.c
+%1 modules\arch\x86\x86regtmod.gperf x86regtmod.c
diff --git a/Mkfiles/vc8/genperf/run.bat b/Mkfiles/vc8/genperf/run.bat index 1cf44bfc..4364ead0 100644 --- a/Mkfiles/vc8/genperf/run.bat +++ b/Mkfiles/vc8/genperf/run.bat @@ -1,5 +1,5 @@ cd ..\..\..\
-%1 x86insn_nasm.gperf > x86insn_nasm.c
-%1 x86insn_gas.gperf > x86insn_gas.c
-%1 modules\arch\x86\x86cpu.gperf > x86cpu.c
-%1 modules\arch\x86\x86regtmod.gperf > x86regtmod.c
+%1 x86insn_nasm.gperf x86insn_nasm.c
+%1 x86insn_gas.gperf x86insn_gas.c
+%1 modules\arch\x86\x86cpu.gperf x86cpu.c
+%1 modules\arch\x86\x86regtmod.gperf x86regtmod.c
diff --git a/modules/arch/x86/Makefile.inc b/modules/arch/x86/Makefile.inc index 3ac4f623..0f682381 100644 --- a/modules/arch/x86/Makefile.inc +++ b/modules/arch/x86/Makefile.inc @@ -43,9 +43,9 @@ EXTRA_DIST += modules/arch/x86/x86regtmod.gperf x86insn_nasm.c: x86insn_nasm.gperf genperf$(EXEEXT) x86insn_gas.c: x86insn_gas.gperf genperf$(EXEEXT) x86cpu.c: $(srcdir)/modules/arch/x86/x86cpu.gperf genperf$(EXEEXT) - $(top_builddir)/genperf$(EXEEXT) $(srcdir)/modules/arch/x86/x86cpu.gperf > $@ + $(top_builddir)/genperf$(EXEEXT) $(srcdir)/modules/arch/x86/x86cpu.gperf $@ x86regtmod.c: $(srcdir)/modules/arch/x86/x86regtmod.gperf genperf$(EXEEXT) - $(top_builddir)/genperf$(EXEEXT) $(srcdir)/modules/arch/x86/x86regtmod.gperf > $@ + $(top_builddir)/genperf$(EXEEXT) $(srcdir)/modules/arch/x86/x86regtmod.gperf $@ BUILT_SOURCES += x86insn_nasm.c BUILT_SOURCES += x86insn_gas.c diff --git a/tools/genperf/Makefile.inc b/tools/genperf/Makefile.inc index 600c93cb..b7e80ed8 100644 --- a/tools/genperf/Makefile.inc +++ b/tools/genperf/Makefile.inc @@ -8,7 +8,7 @@ noinst_PROGRAMS += genperf # Suffix rule for genperf SUFFIXES += .gperf .gperf.c: genperf$(EXEEXT) - $(top_builddir)/genperf$(EXEEXT) $< > $@ + $(top_builddir)/genperf$(EXEEXT) $< $@ genperf_SOURCES = EXTRA_DIST += tools/genperf/genperf.c diff --git a/tools/genperf/genperf.c b/tools/genperf/genperf.c index 1020ee14..ef01b818 100644 --- a/tools/genperf/genperf.c +++ b/tools/genperf/genperf.c @@ -250,7 +250,7 @@ perfect_gen(FILE *out, const char *lookup_function_name, int main(int argc, char *argv[]) { - FILE *in; + FILE *in, *out; size_t i; char *ch; static char line[1024], tmp[1024]; @@ -271,8 +271,8 @@ main(int argc, char *argv[]) sval *sv; keyword *kw; - if (argc != 2) { - fprintf(stderr, "Usage: genperf <in>\n"); + if (argc != 3) { + fprintf(stderr, "Usage: genperf <in> <out>\n"); return EXIT_FAILURE; } @@ -511,20 +511,30 @@ main(int argc, char *argv[]) } /* output code */ - printf("/* %s code produced by genperf */\n", language); - printf("/* Command-line: genperf %s */\n", argv[1]); + out = fopen(argv[2], "wt"); + if (!out) { + fprintf(stderr, "Could not open `%s' for writing\n", argv[2]); + return EXIT_FAILURE; + } + + fprintf(out, "/* %s code produced by genperf */\n", language); + fprintf(out, "/* Command-line: genperf %s %s */\n", argv[1], argv[2]); STAILQ_FOREACH(sv, &usercode, link) - printf("%s", sv->str); + fprintf(out, "%s", sv->str); /* Get perfect hash */ - perfect_gen(stdout, lookup_function_name, struct_name, &keywords, filename); + perfect_gen(out, lookup_function_name, struct_name, &keywords, filename); STAILQ_FOREACH(sv, &usercode2, link) - printf("%s", sv->str); + fprintf(out, "%s", sv->str); - if (errors > 0) + fclose(out); + + if (errors > 0) { + remove(argv[2]); return EXIT_FAILURE; + } return EXIT_SUCCESS; } |