summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/preproc.c54
-rw-r--r--include/tables.h7
-rwxr-xr-xmacros/macros.pl66
-rw-r--r--macros/standard.mac11
-rwxr-xr-xversion.pl1
5 files changed, 89 insertions, 50 deletions
diff --git a/asm/preproc.c b/asm/preproc.c
index 388f4058..48840a32 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -430,17 +430,13 @@ static uint64_t nested_rep_count;
#define PARAM_DELTA 16
/*
- * The standard macro set: defined in macros.c in the array nasm_stdmac.
- * This gives our position in the macro set, when we're processing it.
+ * The standard macro set: defined in macros.c in a set of arrays.
+ * 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;
-
-/*
- * The extra standard macros that come from the object format, if
- * any.
- */
-static macros_t *extrastdmac = NULL;
-static bool any_extrastdmac;
+static macros_t **stdmacnext;
+static macros_t *stdmacros[8];
/*
* Tokens are allocated in blocks to improve speed
@@ -457,6 +453,7 @@ static Blocks blocks = { NULL, NULL };
/*
* Forward declarations.
*/
+static void pp_add_stdmac(macros_t *macros);
static Token *expand_mmac_params(Token * tline);
static Token *expand_smacro(Token * tline);
static Token *expand_id(Token * tline);
@@ -762,11 +759,10 @@ static char *line_from_stdmac(void)
*q = '\0';
if (!*stdmacpos) {
- /* This was the last of the standard macro chain... */
+ /* This was the last of this particular macro set */
stdmacpos = NULL;
- if (any_extrastdmac) {
- stdmacpos = extrastdmac;
- any_extrastdmac = false;
+ if (*stdmacnext) {
+ stdmacpos = *stdmacnext++;
} else if (do_predef) {
Line *pd, *l;
Token *head, **tail, *t;
@@ -4878,12 +4874,16 @@ pp_reset(char *file, int apass, StrList **deplist)
nested_rep_count = 0;
init_macros();
unique = 0;
- if (tasm_compatible_mode) {
- stdmacpos = nasm_stdmac;
- } else {
- stdmacpos = nasm_stdmac_after_tasm;
- }
- any_extrastdmac = extrastdmac && *extrastdmac;
+
+ if (tasm_compatible_mode)
+ pp_add_stdmac(nasm_stdmac_tasm);
+
+ pp_add_stdmac(nasm_stdmac_nasm);
+ pp_add_stdmac(nasm_stdmac_version);
+
+ stdmacpos = stdmacros[0];
+ stdmacnext = &stdmacros[1];
+
do_predef = true;
/*
@@ -5257,9 +5257,19 @@ static void pp_pre_undefine(char *definition)
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)
@@ -5302,7 +5312,7 @@ const struct preproc_ops nasmpp = {
pp_reset,
pp_getline,
pp_cleanup,
- pp_extra_stdmac,
+ pp_add_stdmac,
pp_pre_define,
pp_pre_undefine,
pp_pre_include,
diff --git a/include/tables.h b/include/tables.h
index 693e4cff..24a665e2 100644
--- a/include/tables.h
+++ b/include/tables.h
@@ -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
* the specific copyright holders.
*
@@ -46,8 +46,9 @@
/* --- From standard.mac via macros.pl: --- */
/* macros.c */
-extern const unsigned char nasm_stdmac[];
-extern const unsigned char * const nasm_stdmac_after_tasm;
+extern const unsigned char nasm_stdmac_tasm[];
+extern const unsigned char nasm_stdmac_nasm[];
+extern const unsigned char nasm_stdmac_version[];
const unsigned char *nasm_stdmac_find_package(const char *);
/* --- From insns.dat via insns.pl: --- */
diff --git a/macros/macros.pl b/macros/macros.pl
index 3c461194..d96324a2 100755
--- a/macros/macros.pl
+++ b/macros/macros.pl
@@ -102,9 +102,8 @@ print OUT "#include \"nasmlib.h\"\n";
print OUT "#include \"hashtbl.h\"\n";
print OUT "#include \"outform.h\"\n";
print OUT "\n";
-print OUT "#if 1\n";
-print OUT "const unsigned char nasm_stdmac[] = {";
+my $name = undef;
my $npkg = 0;
my @pkg_list = ();
my %pkg_number = ();
@@ -127,14 +126,14 @@ foreach $args ( @ARGV ) {
chomp;
$line++;
}
- if (m/^\s*\*END\*TASM\*MACROS\*\s*$/) {
- $tasm_count = $index;
- print OUT " /* End of TASM macros */\n";
- } elsif (m/^OUT:\s*(.*\S)\s*$/) {
+ if (m/^OUT:\s*(.*\S)\s*$/) {
undef $pkg;
my @out_alias = split(/\s+/, $1);
- printf OUT " /* %4d */ 0\n", $index++;
- print OUT "};\n#endif\n";
+ if (defined($name)) {
+ printf OUT " /* %4d */ 0\n", $index++;
+ print OUT "};\n#endif\n";
+ undef $name;
+ }
$index = 0;
print OUT "\n";
my $pfx = '#if';
@@ -142,22 +141,43 @@ foreach $args ( @ARGV ) {
print OUT $pfx, " defined(OF_\U${al}\E)";
$pfx = ' ||';
}
- printf OUT "\nconst unsigned char %s_stdmac[] = {\n", $out_alias[0];
- print OUT " /* From $fname */\n";
+ $name = $out_alias[0] . '_stdmac';
+ print OUT "\nconst unsigned char ${name}[] = {\n";
+ print OUT " /* From $fname */\n";
$lastname = $fname;
push(@out_list, $out_alias[0]);
$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*$/) {
$pkg = $1;
if (defined($pkg_number{$pkg})) {
die "$0: $fname: duplicate package: $pkg\n";
}
- printf OUT " /* %4d */ 0\n", $index++;
- print OUT "};\n#endif\n";
+ if (defined($name)) {
+ printf OUT " /* %4d */ 0\n", $index++;
+ print OUT "};\n#endif\n";
+ undef $name;
+ }
$index = 0;
- print OUT "\n#if 1\n";
- printf OUT "static const unsigned char nasm_stdmac_%s[] = {\n", $pkg;
- print OUT " /* From $fname */\n";
+ print OUT "\n#if 1";
+ $name = 'nasm_usemac_' . $pkg;
+ print OUT "\nstatic const unsigned char ${name}[] = {\n";
+ print OUT " /* From $fname */\n";
$lastname = $fname;
push(@pkg_list, $pkg);
$pkg_number{$pkg} = $npkg++;
@@ -166,6 +186,11 @@ foreach $args ( @ARGV ) {
$index += length($z)+1;
} elsif (m/^\s*((\s*([^\"\';\s]+|\"[^\"]*\"|\'[^\']*\'))*)\s*(;.*)?$/) {
my $s1, $s2, $pd, $ws;
+
+ if (!defined($name)) {
+ die "$0: $fname: macro declarations outside a known block\n";
+ }
+
$s1 = $1;
$s2 = '';
while ($s1 =~ /(\%[a-zA-Z_][a-zA-Z0-9_]*)((\s+)(.*)|)$/) {
@@ -197,9 +222,12 @@ foreach $args ( @ARGV ) {
close(INPUT);
}
}
-printf OUT " /* %4d */ 0\n};\n#endif\n\n", $index++;
-print OUT "const unsigned char * const nasm_stdmac_after_tasm = ",
- "&nasm_stdmac[$tasm_count];\n\n";
+
+if (defined($name)) {
+ printf OUT " /* %4d */ 0\n", $index++;
+ print OUT "};\n#endif\n";
+ undef $name;
+}
my @hashinfo = gen_perfect_hash(\%pkg_number);
if (!@hashinfo) {
@@ -217,7 +245,7 @@ print OUT " const char *package;\n";
print OUT " const unsigned char *macros;\n";
print OUT " } packages[$npkg] = {\n";
foreach $pkg (@pkg_list) {
- printf OUT " { \"%s\", nasm_stdmac_%s },\n",
+ printf OUT " { \"%s\", nasm_usemac_%s },\n",
$pkg, $pkg;
}
print OUT " };\n";
diff --git a/macros/standard.mac b/macros/standard.mac
index 60c0387c..d89278a2 100644
--- a/macros/standard.mac
+++ b/macros/standard.mac
@@ -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
;; the specific copyright holders.
;;
@@ -33,9 +33,8 @@
; Standard macro set for NASM -*- nasm -*-
-; Macros to make NASM ignore some TASM directives before the first include
-; directive.
-
+; Macros to make NASM ignore some TASM directives
+STD: tasm
%idefine IDEAL
%idefine JUMPS
%idefine P386
@@ -43,8 +42,8 @@
%idefine P586
%idefine END
-; This is a magic token which indicates the end of the TASM macros
-*END*TASM*MACROS*
+; The normal standard macros
+STD: nasm
; 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
diff --git a/version.pl b/version.pl
index a5577a02..579ba7b5 100755
--- a/version.pl
+++ b/version.pl
@@ -143,6 +143,7 @@ if ( $what eq 'h' ) {
printf "#define NASM_VER \"%s\"\n", $line;
print "#endif /* NASM_VERSION_H */\n";
} elsif ( $what eq 'mac' ) {
+ print "STD: version\n";
printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
printf "%%define __NASM_MINOR__ %d\n", $nmin;
printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;