From cfb7176ca211d2bdc8c790c1b49e6f29db42f777 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 20 Jun 2008 15:20:16 -0700 Subject: [PATCH] Move the output format macros into the macros.pl mechanism Move the handling of "extra" macros (i.e. output format macros) into the macros.pl mechanism. This allows us to change the format of the internal macro store in the future - e.g. to a single byte store without redundant pointers. Also, stop using indicies into a long array when there is no good reason to not just use different arrays. --- Makefile.in | 5 +++-- macros.pl | 30 +++++++++++++++++++++++++----- nasm.h | 3 ++- output/outaout.c | 7 +------ output/outaout.mac | 4 ++++ output/outas86.c | 7 +------ output/outas86.mac | 4 ++++ output/outbin.c | 10 +--------- output/outbin.mac | 7 +++++++ output/outcoff.c | 13 +------------ output/outcoff.mac | 10 ++++++++++ output/outelf.mac | 8 ++++++++ output/outelf32.c | 12 ++---------- output/outelf64.c | 12 ++---------- output/outmacho.c | 7 +------ output/outmacho.mac | 4 ++++ output/outobj.c | 19 +------------------ output/outobj.mac | 16 ++++++++++++++++ output/outrdf.c | 10 +--------- output/outrdf.mac | 7 +++++++ output/outrdf2.c | 13 +------------ output/outrdf2.mac | 10 ++++++++++ preproc.c | 4 ++-- preproc.h | 5 ++++- 24 files changed, 118 insertions(+), 109 deletions(-) create mode 100644 output/outaout.mac create mode 100644 output/outas86.mac create mode 100644 output/outbin.mac create mode 100644 output/outcoff.mac create mode 100644 output/outelf.mac create mode 100644 output/outmacho.mac create mode 100644 output/outobj.mac create mode 100644 output/outrdf.mac create mode 100644 output/outrdf2.mac diff --git a/Makefile.in b/Makefile.in index f8f33614..d6b6544e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -114,9 +114,10 @@ version.sed: version version.pl # This source file is generated from the standard macros file # `standard.mac' by another Perl script. Again, it's part of the # standard distribution. -macros.c: macros.pl pptok.ph standard.mac version.mac $(srcdir)/macros/*.mac +macros.c: macros.pl pptok.ph standard.mac version.mac \ + $(srcdir)/macros/*.mac $(srcdir)/output/*.mac $(PERL) $(srcdir)/macros.pl $(srcdir)/standard.mac version.mac \ - $(srcdir)/macros/*.mac + $(srcdir)/macros/*.mac $(srcdir)/output/*.mac # These source files are generated from regs.dat by yet another # perl script. diff --git a/macros.pl b/macros.pl index 5429a5ea..18c77596 100755 --- a/macros.pl +++ b/macros.pl @@ -34,25 +34,41 @@ print OUT "const char * const nasm_stdmac[] = {"; my $npkg = 0; my @pkg_list = (); my %pkg_number = (); -my %pkg_index = (); my $pkg; +my @out_list = (); +my $outfmt; +my $lastname; foreach $fname ( @ARGV ) { open(INPUT,$fname) or die "unable to open $fname\n"; - print OUT "\n /* From $fname */\n"; while () { $line++; chomp; if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) { $tasm_count = $index; print OUT " /* End of TASM macros */\n"; + } elsif (m/^OUT:\s*(.*\S)\s*$/) { + undef $pkg; + my @out_alias = split(/\s+/, $1); + printf OUT " /* %4d */ NULL\n", $index++; + print OUT "};\n"; + $index = 0; + printf OUT "const char * const %s_stdmac[] = {\n", $out_alias[0]; + print OUT " /* From $fname */\n"; + $lastname = $fname; + push(@out_list, $out_alias[0]); + $out_index{$out_alias[0]} = $index; } elsif (m/^USE:\s*(\S+)\s*$/) { $pkg = $1; if (defined($pkg_number{$pkg})) { die "$0: $fname: duplicate package: $pkg\n"; } printf OUT " /* %4d */ NULL,\n", $index++; - print OUT " /* %use $pkg */\n"; + print OUT "};\n"; + $index = 0; + printf OUT "static const char * const nasm_stdmac_%s[] = {\n", $pkg; + print OUT " /* From $fname */\n"; + $lastname = $fname; push(@pkg_list, $pkg); $pkg_number{$pkg} = $npkg++; $pkg_index{$pkg} = $index; @@ -79,6 +95,10 @@ foreach $fname ( @ARGV ) { } $s2 .= $s1; if (length($s2) > 0) { + if ($lastname ne $fname) { + print OUT "\n /* From $fname */\n"; + $lastname = $fname; + } printf OUT " /* %4d */ \"%s\",\n", $index++, $s2; } } else { @@ -107,8 +127,8 @@ print OUT " const char *package;\n"; print OUT " const char * const *macros;\n"; print OUT " } packages[$npkg] = {\n"; foreach $pkg (@pkg_list) { - printf OUT " { \"%s\", nasm_stdmac+%d },\n", - $pkg, $pkg_index{$pkg}; + printf OUT " { \"%s\", nasm_stdmac_%s },\n", + $pkg, $pkg; } print OUT " };\n"; diff --git a/nasm.h b/nasm.h index ec44f164..203750e5 100644 --- a/nasm.h +++ b/nasm.h @@ -17,6 +17,7 @@ #include #include "version.h" /* generated NASM version macros */ #include "nasmlib.h" +#include "preproc.h" #include "insnsi.h" /* For enum opcode */ #define NO_SEG -1L /* null segment value */ @@ -750,7 +751,7 @@ struct ofmt { * and user-level equivalents for any format-specific * directives). */ - const char **stdmac; + const macros_t *stdmac; /* * This procedure is called at the start of an output session. diff --git a/output/outaout.c b/output/outaout.c index 20658acd..f374b9e0 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -905,12 +905,7 @@ static void aout_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".o", error); } -static const char *aout_stdmac[] = { - "%define __SECT__ [section .text]", - "%macro __NASM_CDecl__ 1", - "%endmacro", - NULL -}; +extern macros_t aout_stdmac[]; static int aout_set_info(enum geninfo type, char **val) { diff --git a/output/outaout.mac b/output/outaout.mac new file mode 100644 index 00000000..ef049a28 --- /dev/null +++ b/output/outaout.mac @@ -0,0 +1,4 @@ +OUT: aout +%define __SECT__ [section .text] +%macro __NASM_CDecl__ 1 +%endmacro diff --git a/output/outas86.c b/output/outas86.c index 9eb68473..b59fe6b3 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -603,12 +603,7 @@ static void as86_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".o", error); } -static const char *as86_stdmac[] = { - "%define __SECT__ [section .text]", - "%macro __NASM_CDecl__ 1", - "%endmacro", - NULL -}; +extern macros_t as86_stdmac[]; static int as86_set_info(enum geninfo type, char **val) { diff --git a/output/outas86.mac b/output/outas86.mac new file mode 100644 index 00000000..1edf908c --- /dev/null +++ b/output/outas86.mac @@ -0,0 +1,4 @@ +OUT: as86 +%define __SECT__ [section .text] +%macro __NASM_CDecl__ 1 +%endmacro diff --git a/output/outbin.c b/output/outbin.c index d2b57426..e71a60eb 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -139,15 +139,7 @@ static int origin_defined; static int map_control = 0; static char *infile, *outfile; -static const char *bin_stdmac[] = { - "%define __SECT__ [section .text]", - "%imacro org 1+.nolist", - "[org %1]", - "%endmacro", - "%macro __NASM_CDecl__ 1", - "%endmacro", - NULL -}; +extern macros_t bin_stdmac[]; static void add_reloc(struct Section *s, int32_t bytes, int32_t secref, int32_t secrel) diff --git a/output/outbin.mac b/output/outbin.mac new file mode 100644 index 00000000..d0ae2a3d --- /dev/null +++ b/output/outbin.mac @@ -0,0 +1,7 @@ +OUT: bin +%define __SECT__ [section .text] +%imacro org 1+.nolist +[org %1] +%endmacro +%macro __NASM_CDecl__ 1 +%endmacro diff --git a/output/outcoff.c b/output/outcoff.c index bbd0b577..d8d1d3df 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -963,18 +963,7 @@ static void coff_win32_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".obj", error); } -static const char *coff_stdmac[] = { - "%define __SECT__ [section .text]", - "%macro __NASM_CDecl__ 1", - "%endmacro", - "%imacro export 1+.nolist", - "[export %1]", - "%endmacro", - "%imacro safeseh 1.nolist", - "[safeseh %1]", - "%endmacro", - NULL -}; +extern macros_t coff_stdmac[]; static int coff_set_info(enum geninfo type, char **val) { diff --git a/output/outcoff.mac b/output/outcoff.mac new file mode 100644 index 00000000..c9ecb54c --- /dev/null +++ b/output/outcoff.mac @@ -0,0 +1,10 @@ +OUT: coff +%define __SECT__ [section .text] +%macro __NASM_CDecl__ 1 +%endmacro +%imacro export 1+.nolist +[export %1] +%endmacro +%imacro safeseh 1.nolist +[safeseh %1] +%endmacro diff --git a/output/outelf.mac b/output/outelf.mac new file mode 100644 index 00000000..bd6f82e4 --- /dev/null +++ b/output/outelf.mac @@ -0,0 +1,8 @@ +OUT: elf elf32 elf64 +%define __SECT__ [section .text] +%macro __NASM_CDecl__ 1 +%define $_%1 $%1 +%endmacro +%macro osabi 1+.nolist +[osabi %1] +%endmacro diff --git a/output/outelf32.c b/output/outelf32.c index ec4e8383..f97a53c3 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -1480,16 +1480,8 @@ static void elf_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".o", error); } -static const char *elf_stdmac[] = { - "%define __SECT__ [section .text]", - "%macro __NASM_CDecl__ 1", - "%define $_%1 $%1", - "%endmacro", - "%macro osabi 1+.nolist", - "[osabi %1]", - "%endmacro", - NULL -}; +extern macros_t elf_stdmac[]; + static int elf_set_info(enum geninfo type, char **val) { (void)type; diff --git a/output/outelf64.c b/output/outelf64.c index 9393e7af..3980cda8 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -1511,16 +1511,8 @@ static void elf_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".o", error); } -static const char *elf_stdmac[] = { - "%define __SECT__ [section .text]", - "%macro __NASM_CDecl__ 1", - "%define $_%1 $%1", - "%endmacro", - "%macro osabi 1+.nolist", - "[osabi %1]", - "%endmacro", - NULL -}; +extern macros_t elf_stdmac[]; + static int elf_set_info(enum geninfo type, char **val) { (void)type; diff --git a/output/outmacho.c b/output/outmacho.c index 5ac2878e..5e9ad8e1 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -717,12 +717,7 @@ static void macho_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".o", error); } -static const char *macho_stdmac[] = { - "%define __SECT__ [section .text]", - "%macro __NASM_CDecl__ 1", - "%endmacro", - NULL -}; +extern macros_t macho_stdmac[]; /* Comparison function for qsort symbol layout. */ static int layout_compare (const struct symbol **s1, diff --git a/output/outmacho.mac b/output/outmacho.mac new file mode 100644 index 00000000..c135bf43 --- /dev/null +++ b/output/outmacho.mac @@ -0,0 +1,4 @@ +OUT: macho win32 win64 +%define __SECT__ [section .text] +%macro __NASM_CDecl__ 1 +%endmacro diff --git a/output/outobj.c b/output/outobj.c index c0736f76..74eb38e6 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -2292,24 +2292,7 @@ static void obj_fwrite(ObjRecord * orp) fputc((-cksum) & 0xFF, ofp); } -static const char *obj_stdmac[] = { - "%define __SECT__ [section .text]", - "%imacro group 1+.nolist", - "[group %1]", - "%endmacro", - "%imacro uppercase 0+.nolist", - "[uppercase %1]", - "%endmacro", - "%imacro export 1+.nolist", - "[export %1]", - "%endmacro", - "%imacro import 1+.nolist", - "[import %1]", - "%endmacro", - "%macro __NASM_CDecl__ 1", - "%endmacro", - NULL -}; +extern macros_t obj_stdmac[]; void dbgbi_init(struct ofmt *of, void *id, FILE * fp, efunc error) { diff --git a/output/outobj.mac b/output/outobj.mac new file mode 100644 index 00000000..ef60638a --- /dev/null +++ b/output/outobj.mac @@ -0,0 +1,16 @@ +OUT: obj +%define __SECT__ [section .text] +%imacro group 1+.nolist +[group %1] +%endmacro +%imacro uppercase 0+.nolist +[uppercase %1] +%endmacro +%imacro export 1+.nolist +[export %1] +%endmacro +%imacro import 1+.nolist +[import %1] +%endmacro +%macro __NASM_CDecl__ 1 +%endmacro diff --git a/output/outrdf.c b/output/outrdf.c index a6de475c..8c5b2396 100644 --- a/output/outrdf.c +++ b/output/outrdf.c @@ -509,15 +509,7 @@ static void rdf_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".rdf", error); } -static char *rdf_stdmac[] = { - "%define __SECT__ [section .text]", - "%imacro library 1+.nolist", - "[library %1]", - "%endmacro", - "%macro __NASM_CDecl__ 1", - "%endmacro", - NULL -}; +extern macros_t rdf_stdmac[]; static int rdf_set_info(enum geninfo type, char **val) { diff --git a/output/outrdf.mac b/output/outrdf.mac new file mode 100644 index 00000000..f0c41557 --- /dev/null +++ b/output/outrdf.mac @@ -0,0 +1,7 @@ +OUT: rdf +%define __SECT__ [section .text] +%imacro library 1+.nolist +[library %1] +%endmacro +%macro __NASM_CDecl__ 1 +%endmacro diff --git a/output/outrdf2.c b/output/outrdf2.c index 05c7ce1b..b00ad43e 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -746,18 +746,7 @@ static void rdf2_filename(char *inname, char *outname, efunc error) standard_extension(inname, outname, ".rdf", error); } -static const char *rdf2_stdmac[] = { - "%define __SECT__ [section .text]", - "%imacro library 1+.nolist", - "[library %1]", - "%endmacro", - "%imacro module 1+.nolist", - "[module %1]", - "%endmacro", - "%macro __NASM_CDecl__ 1", - "%endmacro", - NULL -}; +extern macros_t rdf2_stdmac[]; static int rdf2_set_info(enum geninfo type, char **val) { diff --git a/output/outrdf2.mac b/output/outrdf2.mac new file mode 100644 index 00000000..a48cbfb6 --- /dev/null +++ b/output/outrdf2.mac @@ -0,0 +1,10 @@ +OUT: rdf2 +%define __SECT__ [section .text] +%imacro library 1+.nolist +[library %1] +%endmacro +%imacro module 1+.nolist +[module %1] +%endmacro +%macro __NASM_CDecl__ 1 +%endmacro diff --git a/preproc.c b/preproc.c index db808e91..f42c0d0b 100644 --- a/preproc.c +++ b/preproc.c @@ -369,7 +369,7 @@ static const char * const *stdmacpos; * any. */ static const char * const *extrastdmac = NULL; -bool any_extrastdmac; +static bool any_extrastdmac; /* * Tokens are allocated in blocks to improve speed @@ -4345,7 +4345,7 @@ void pp_runtime(char *definition) } -void pp_extra_stdmac(const char **macros) +void pp_extra_stdmac(const macros_t *macros) { extrastdmac = macros; } diff --git a/preproc.h b/preproc.h index bd1210b2..a79ae277 100644 --- a/preproc.h +++ b/preproc.h @@ -14,12 +14,15 @@ extern const char * const pp_directives[]; extern const int pp_directives_len[]; +/* Pointer to a macro chain */ +typedef const char * const macros_t; + enum preproc_token pp_token_hash(const char *token); void pp_include_path(char *); void pp_pre_include(char *); void pp_pre_define(char *); void pp_pre_undefine(char *); void pp_runtime(char *); -void pp_extra_stdmac(const char **); +void pp_extra_stdmac(const macros_t *); #endif -- 2.11.4.GIT