Handle multiple standard macro sets sanely

The ordering of the macro sets ended up changing due to the recent
file reorganization.  Instead of forcing the order again, handle
multiple macro sets (rather than just two) in a coherent manner.

macros/macros.pl could use a cleanup of duplicated code, however.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2016-07-13 14:23:48 -07:00
parent 3d74b091e9
commit f7606613d0
5 changed files with 89 additions and 50 deletions

View file

@ -430,17 +430,13 @@ static uint64_t nested_rep_count;
#define PARAM_DELTA 16 #define PARAM_DELTA 16
/* /*
* The standard macro set: defined in macros.c in the array nasm_stdmac. * The standard macro set: defined in macros.c in a set of arrays.
* This gives our position in the macro set, when we're processing it. * This gives our position in any macro set, while we are processing it.
* The stdmacset is an array of such macro sets.
*/ */
static macros_t *stdmacpos; static macros_t *stdmacpos;
static macros_t **stdmacnext;
/* static macros_t *stdmacros[8];
* The extra standard macros that come from the object format, if
* any.
*/
static macros_t *extrastdmac = NULL;
static bool any_extrastdmac;
/* /*
* Tokens are allocated in blocks to improve speed * Tokens are allocated in blocks to improve speed
@ -457,6 +453,7 @@ static Blocks blocks = { NULL, NULL };
/* /*
* Forward declarations. * Forward declarations.
*/ */
static void pp_add_stdmac(macros_t *macros);
static Token *expand_mmac_params(Token * tline); static Token *expand_mmac_params(Token * tline);
static Token *expand_smacro(Token * tline); static Token *expand_smacro(Token * tline);
static Token *expand_id(Token * tline); static Token *expand_id(Token * tline);
@ -762,11 +759,10 @@ static char *line_from_stdmac(void)
*q = '\0'; *q = '\0';
if (!*stdmacpos) { if (!*stdmacpos) {
/* This was the last of the standard macro chain... */ /* This was the last of this particular macro set */
stdmacpos = NULL; stdmacpos = NULL;
if (any_extrastdmac) { if (*stdmacnext) {
stdmacpos = extrastdmac; stdmacpos = *stdmacnext++;
any_extrastdmac = false;
} else if (do_predef) { } else if (do_predef) {
Line *pd, *l; Line *pd, *l;
Token *head, **tail, *t; Token *head, **tail, *t;
@ -4878,12 +4874,16 @@ pp_reset(char *file, int apass, StrList **deplist)
nested_rep_count = 0; nested_rep_count = 0;
init_macros(); init_macros();
unique = 0; unique = 0;
if (tasm_compatible_mode) {
stdmacpos = nasm_stdmac; if (tasm_compatible_mode)
} else { pp_add_stdmac(nasm_stdmac_tasm);
stdmacpos = nasm_stdmac_after_tasm;
} pp_add_stdmac(nasm_stdmac_nasm);
any_extrastdmac = extrastdmac && *extrastdmac; pp_add_stdmac(nasm_stdmac_version);
stdmacpos = stdmacros[0];
stdmacnext = &stdmacros[1];
do_predef = true; do_predef = true;
/* /*
@ -5257,9 +5257,19 @@ static void pp_pre_undefine(char *definition)
predef = l; predef = l;
} }
static void pp_extra_stdmac(macros_t *macros) static void pp_add_stdmac(macros_t *macros)
{ {
extrastdmac = macros; macros_t **mp;
/* Find the end of the list and avoid duplicates */
for (mp = stdmacros; *mp; mp++) {
if (*mp == macros)
return; /* Nothing to do */
}
nasm_assert(mp < &stdmacros[ARRAY_SIZE(stdmacros)-1]);
*mp = macros;
} }
static void make_tok_num(Token * tok, int64_t val) static void make_tok_num(Token * tok, int64_t val)
@ -5302,7 +5312,7 @@ const struct preproc_ops nasmpp = {
pp_reset, pp_reset,
pp_getline, pp_getline,
pp_cleanup, pp_cleanup,
pp_extra_stdmac, pp_add_stdmac,
pp_pre_define, pp_pre_define,
pp_pre_undefine, pp_pre_undefine,
pp_pre_include, pp_pre_include,

View file

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- * /* ----------------------------------------------------------------------- *
* *
* Copyright 1996-2009 The NASM Authors - All Rights Reserved * Copyright 1996-2016 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for * See the file AUTHORS included with the NASM distribution for
* the specific copyright holders. * the specific copyright holders.
* *
@ -46,8 +46,9 @@
/* --- From standard.mac via macros.pl: --- */ /* --- From standard.mac via macros.pl: --- */
/* macros.c */ /* macros.c */
extern const unsigned char nasm_stdmac[]; extern const unsigned char nasm_stdmac_tasm[];
extern const unsigned char * const nasm_stdmac_after_tasm; extern const unsigned char nasm_stdmac_nasm[];
extern const unsigned char nasm_stdmac_version[];
const unsigned char *nasm_stdmac_find_package(const char *); const unsigned char *nasm_stdmac_find_package(const char *);
/* --- From insns.dat via insns.pl: --- */ /* --- From insns.dat via insns.pl: --- */

View file

@ -102,9 +102,8 @@ print OUT "#include \"nasmlib.h\"\n";
print OUT "#include \"hashtbl.h\"\n"; print OUT "#include \"hashtbl.h\"\n";
print OUT "#include \"outform.h\"\n"; print OUT "#include \"outform.h\"\n";
print OUT "\n"; print OUT "\n";
print OUT "#if 1\n";
print OUT "const unsigned char nasm_stdmac[] = {";
my $name = undef;
my $npkg = 0; my $npkg = 0;
my @pkg_list = (); my @pkg_list = ();
my %pkg_number = (); my %pkg_number = ();
@ -127,14 +126,14 @@ foreach $args ( @ARGV ) {
chomp; chomp;
$line++; $line++;
} }
if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) { if (m/^OUT:\s*(.*\S)\s*$/) {
$tasm_count = $index;
print OUT " /* End of TASM macros */\n";
} elsif (m/^OUT:\s*(.*\S)\s*$/) {
undef $pkg; undef $pkg;
my @out_alias = split(/\s+/, $1); my @out_alias = split(/\s+/, $1);
printf OUT " /* %4d */ 0\n", $index++; if (defined($name)) {
print OUT "};\n#endif\n"; printf OUT " /* %4d */ 0\n", $index++;
print OUT "};\n#endif\n";
undef $name;
}
$index = 0; $index = 0;
print OUT "\n"; print OUT "\n";
my $pfx = '#if'; my $pfx = '#if';
@ -142,22 +141,43 @@ foreach $args ( @ARGV ) {
print OUT $pfx, " defined(OF_\U${al}\E)"; print OUT $pfx, " defined(OF_\U${al}\E)";
$pfx = ' ||'; $pfx = ' ||';
} }
printf OUT "\nconst unsigned char %s_stdmac[] = {\n", $out_alias[0]; $name = $out_alias[0] . '_stdmac';
print OUT " /* From $fname */\n"; print OUT "\nconst unsigned char ${name}[] = {\n";
print OUT " /* From $fname */\n";
$lastname = $fname; $lastname = $fname;
push(@out_list, $out_alias[0]); push(@out_list, $out_alias[0]);
$out_index{$out_alias[0]} = $index; $out_index{$out_alias[0]} = $index;
} elsif (m/^STD:\s*(.*\S)\s*$/) {
undef $pkg;
my @out_alias = split(/\s+/, $1);
if (defined($name)) {
printf OUT " /* %4d */ 0\n", $index++;
print OUT "};\n#endif\n";
undef $name;
}
$index = 0;
print OUT "\n#if 1";
$name = 'nasm_stdmac_' . $out_alias[0];
print OUT "\nconst unsigned char ${name}[] = {\n";
print OUT " /* From $fname */\n";
$lastname = $fname;
push(@std_list, $out_alias[0]);
$std_index{$std_alias[0]} = $index;
} elsif (m/^USE:\s*(\S+)\s*$/) { } elsif (m/^USE:\s*(\S+)\s*$/) {
$pkg = $1; $pkg = $1;
if (defined($pkg_number{$pkg})) { if (defined($pkg_number{$pkg})) {
die "$0: $fname: duplicate package: $pkg\n"; die "$0: $fname: duplicate package: $pkg\n";
} }
printf OUT " /* %4d */ 0\n", $index++; if (defined($name)) {
print OUT "};\n#endif\n"; printf OUT " /* %4d */ 0\n", $index++;
print OUT "};\n#endif\n";
undef $name;
}
$index = 0; $index = 0;
print OUT "\n#if 1\n"; print OUT "\n#if 1";
printf OUT "static const unsigned char nasm_stdmac_%s[] = {\n", $pkg; $name = 'nasm_usemac_' . $pkg;
print OUT " /* From $fname */\n"; print OUT "\nstatic const unsigned char ${name}[] = {\n";
print OUT " /* From $fname */\n";
$lastname = $fname; $lastname = $fname;
push(@pkg_list, $pkg); push(@pkg_list, $pkg);
$pkg_number{$pkg} = $npkg++; $pkg_number{$pkg} = $npkg++;
@ -166,6 +186,11 @@ foreach $args ( @ARGV ) {
$index += length($z)+1; $index += length($z)+1;
} elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) { } elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
my $s1, $s2, $pd, $ws; my $s1, $s2, $pd, $ws;
if (!defined($name)) {
die "$0: $fname: macro declarations outside a known block\n";
}
$s1 = $1; $s1 = $1;
$s2 = ''; $s2 = '';
while ($s1 =~ /(\%[a-zA-Z_][a-zA-Z0-9_]*)((\s+)(.*)|)$/) { while ($s1 =~ /(\%[a-zA-Z_][a-zA-Z0-9_]*)((\s+)(.*)|)$/) {
@ -197,9 +222,12 @@ foreach $args ( @ARGV ) {
close(INPUT); close(INPUT);
} }
} }
printf OUT " /* %4d */ 0\n};\n#endif\n\n", $index++;
print OUT "const unsigned char * const nasm_stdmac_after_tasm = ", if (defined($name)) {
"&nasm_stdmac[$tasm_count];\n\n"; printf OUT " /* %4d */ 0\n", $index++;
print OUT "};\n#endif\n";
undef $name;
}
my @hashinfo = gen_perfect_hash(\%pkg_number); my @hashinfo = gen_perfect_hash(\%pkg_number);
if (!@hashinfo) { if (!@hashinfo) {
@ -217,7 +245,7 @@ print OUT " const char *package;\n";
print OUT " const unsigned char *macros;\n"; print OUT " const unsigned char *macros;\n";
print OUT " } packages[$npkg] = {\n"; print OUT " } packages[$npkg] = {\n";
foreach $pkg (@pkg_list) { foreach $pkg (@pkg_list) {
printf OUT " { \"%s\", nasm_stdmac_%s },\n", printf OUT " { \"%s\", nasm_usemac_%s },\n",
$pkg, $pkg; $pkg, $pkg;
} }
print OUT " };\n"; print OUT " };\n";

View file

@ -1,6 +1,6 @@
;; -------------------------------------------------------------------------- ;; --------------------------------------------------------------------------
;; ;;
;; Copyright 1996-2009 The NASM Authors - All Rights Reserved ;; Copyright 1996-2016 The NASM Authors - All Rights Reserved
;; See the file AUTHORS included with the NASM distribution for ;; See the file AUTHORS included with the NASM distribution for
;; the specific copyright holders. ;; the specific copyright holders.
;; ;;
@ -33,9 +33,8 @@
; Standard macro set for NASM -*- nasm -*- ; Standard macro set for NASM -*- nasm -*-
; Macros to make NASM ignore some TASM directives before the first include ; Macros to make NASM ignore some TASM directives
; directive. STD: tasm
%idefine IDEAL %idefine IDEAL
%idefine JUMPS %idefine JUMPS
%idefine P386 %idefine P386
@ -43,8 +42,8 @@
%idefine P586 %idefine P586
%idefine END %idefine END
; This is a magic token which indicates the end of the TASM macros ; The normal standard macros
*END*TASM*MACROS* STD: nasm
; Note that although some user-level forms of directives are defined ; Note that although some user-level forms of directives are defined
; here, not all of them are: the user-level form of a format-specific ; here, not all of them are: the user-level form of a format-specific

View file

@ -143,6 +143,7 @@ if ( $what eq 'h' ) {
printf "#define NASM_VER \"%s\"\n", $line; printf "#define NASM_VER \"%s\"\n", $line;
print "#endif /* NASM_VERSION_H */\n"; print "#endif /* NASM_VERSION_H */\n";
} elsif ( $what eq 'mac' ) { } elsif ( $what eq 'mac' ) {
print "STD: version\n";
printf "%%define __NASM_MAJOR__ %d\n", $nmaj; printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
printf "%%define __NASM_MINOR__ %d\n", $nmin; printf "%%define __NASM_MINOR__ %d\n", $nmin;
printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin; printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;