summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2008-05-09 06:46:02 +0000
committerPeter Johnson <peter@tortall.net>2008-05-09 06:46:02 +0000
commitcbf0c7befdecd2da9bf4f866c3b25bb0f6b173f0 (patch)
tree9c826aade374450549a3aca820112a5c71fc7c05
parentd8a6f8c3765cbbd8f2908965cb4b2adee1499c56 (diff)
downloadyasm-cbf0c7befdecd2da9bf4f866c3b25bb0f6b173f0.tar.gz
Split NASM preprocessor standard macro set between various modules.
Standard macro sets are looked up based on parser and preprocessor keyword from individual modules. The "standard" NASM parser macros now reside in the NASM parser, so when the GAS parser is used with the NASM preprocessor, the NASM-specific macros are no longer defined. Object-format specific macros are now individually defined by each object formatm module. This allows for the object formats to be independent of the NASM preprocessor module and yields a small optimization benefit as unused object format macros don't need to be skipped over. Also add GAS macro equivalents for the Win64 SEH more complex directives [1]. [1] Requested by Brian Gladman <brg@gladman.plus.com> svn path=/trunk/yasm/; revision=2082
-rw-r--r--frontends/yasm/yasm.c28
-rw-r--r--libyasm/coretype.h15
-rw-r--r--libyasm/objfmt.h3
-rw-r--r--libyasm/parser.h3
-rw-r--r--libyasm/preproc.h16
-rw-r--r--modules/objfmts/bin/bin-objfmt.c13
-rw-r--r--modules/objfmts/coff/Makefile.inc16
-rw-r--r--modules/objfmts/coff/coff-objfmt.c28
-rw-r--r--modules/objfmts/coff/win64-gas.mac73
-rw-r--r--modules/objfmts/coff/win64-nasm.mac106
-rw-r--r--modules/objfmts/dbg/dbg-objfmt.c1
-rw-r--r--modules/objfmts/elf/elf-objfmt.c21
-rw-r--r--modules/objfmts/macho/macho-objfmt.c3
-rw-r--r--modules/objfmts/rdf/rdf-objfmt.c16
-rw-r--r--modules/objfmts/win64/tests/Makefile.inc4
-rw-r--r--modules/objfmts/win64/tests/gas/Makefile.inc7
-rw-r--r--modules/objfmts/win64/tests/gas/win64-gas-sce.asm11
-rw-r--r--modules/objfmts/win64/tests/gas/win64-gas-sce.hex403
-rwxr-xr-xmodules/objfmts/win64/tests/gas/win64_gas_test.sh4
-rw-r--r--modules/objfmts/xdf/xdf-objfmt.c1
-rw-r--r--modules/parsers/gas/gas-parser.c2
-rw-r--r--modules/parsers/nasm/Makefile.inc12
-rw-r--r--modules/parsers/nasm/nasm-parser.c8
-rw-r--r--modules/parsers/nasm/nasm-std.mac109
-rw-r--r--modules/preprocs/cpp/cpp-preproc.c9
-rw-r--r--modules/preprocs/nasm/Makefile.inc21
-rw-r--r--modules/preprocs/nasm/genmacro.c145
-rw-r--r--modules/preprocs/nasm/genversion.c12
-rw-r--r--modules/preprocs/nasm/nasm-pp.c157
-rw-r--r--modules/preprocs/nasm/nasm-preproc.c13
-rw-r--r--modules/preprocs/nasm/standard.mac293
-rw-r--r--modules/preprocs/nasm/tests/nasmpp-nested.errwarn6
-rw-r--r--modules/preprocs/raw/raw-preproc.c9
-rw-r--r--modules/preprocs/yapp/yapp-preproc.c9
34 files changed, 1026 insertions, 551 deletions
diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c
index 8c24d285..b5f47080 100644
--- a/frontends/yasm/yasm.c
+++ b/frontends/yasm/yasm.c
@@ -120,6 +120,7 @@ static void print_yasm_warning(const char *filename, unsigned long line,
const char *msg);
static void apply_preproc_builtins(void);
+static void apply_preproc_standard_macros(const yasm_stdmac *stdmacs);
static void apply_preproc_saved_options(void);
static void print_list_keyword_desc(const char *name, const char *keyword);
@@ -264,13 +265,17 @@ do_preproc_only(void)
return EXIT_FAILURE;
}
- /* Pre-process until done */
+ /* Create preprocessor */
cur_preproc = yasm_preproc_create(cur_preproc_module, in_filename, NULL,
linemap, errwarns);
+ /* Apply macros */
apply_preproc_builtins();
+ apply_preproc_standard_macros(cur_parser_module->stdmacs);
+ apply_preproc_standard_macros(cur_objfmt_module->stdmacs);
apply_preproc_saved_options();
+ /* Pre-process until done */
if (generate_make_dependencies) {
size_t totlen;
@@ -429,6 +434,8 @@ do_assemble(void)
object->symtab, linemap, errwarns);
apply_preproc_builtins();
+ apply_preproc_standard_macros(cur_parser_module->stdmacs);
+ apply_preproc_standard_macros(cur_objfmt_module->stdmacs);
apply_preproc_saved_options();
/* Get initial x86 BITS setting from object format */
@@ -1126,6 +1133,25 @@ apply_preproc_builtins()
}
static void
+apply_preproc_standard_macros(const yasm_stdmac *stdmacs)
+{
+ int i, matched;
+
+ if (!stdmacs)
+ return;
+
+ matched = -1;
+ for (i=0; stdmacs[i].parser; i++)
+ if (yasm__strcasecmp(stdmacs[i].parser,
+ cur_parser_module->keyword) == 0 &&
+ yasm__strcasecmp(stdmacs[i].preproc,
+ cur_preproc_module->keyword) == 0)
+ matched = i;
+ if (matched >= 0 && stdmacs[matched].macros)
+ yasm_preproc_add_standard(cur_preproc, stdmacs[matched].macros);
+}
+
+static void
apply_preproc_saved_options()
{
constcharparam *cp, *cpnext;
diff --git a/libyasm/coretype.h b/libyasm/coretype.h
index 5c99816c..b23e3eae 100644
--- a/libyasm/coretype.h
+++ b/libyasm/coretype.h
@@ -52,6 +52,21 @@ typedef struct yasm_objfmt_module yasm_objfmt_module;
/** Debug format module interface. \see dbgfmt.h for details. */
typedef struct yasm_dbgfmt_module yasm_dbgfmt_module;
+/** Standard macro structure for modules that allows association of a set of
+ * standard macros with a parser/preprocessor combination.
+ * A NULL-terminated array of these structures is used in a number of module
+ * interfaces.
+ */
+typedef struct yasm_stdmac {
+ const char *parser; /**< Parser keyword */
+ const char *preproc; /**< Preprocessor keyword */
+
+ /** NULL-terminated array of standard macros. May be NULL if no standard
+ * macros should be added for this preprocessor.
+ */
+ const char **macros;
+} yasm_stdmac;
+
/** YASM associated data callback structure. Many data structures can have
* arbitrary data associated with them.
*/
diff --git a/libyasm/objfmt.h b/libyasm/objfmt.h
index 0c40c4a3..c65e76c1 100644
--- a/libyasm/objfmt.h
+++ b/libyasm/objfmt.h
@@ -77,6 +77,9 @@ struct yasm_objfmt_module {
/** NULL-terminated list of directives. NULL if none. */
/*@null@*/ const yasm_directive *directives;
+ /** NULL-terminated list of standard macro lookups. NULL if none. */
+ const yasm_stdmac *stdmacs;
+
/** Create object format.
* Module-level implementation of yasm_objfmt_create().
* Call yasm_objfmt_create() instead of calling this function.
diff --git a/libyasm/parser.h b/libyasm/parser.h
index fcbb20c4..26c347be 100644
--- a/libyasm/parser.h
+++ b/libyasm/parser.h
@@ -51,6 +51,9 @@ typedef struct yasm_parser_module {
/** Default preprocessor. */
const char *default_preproc_keyword;
+ /** NULL-terminated list of standard macro lookups. NULL if none. */
+ const yasm_stdmac *stdmacs;
+
/** Parse a source file into an object.
* \param object object to parse into (already created)
* \param pp preprocessor
diff --git a/libyasm/preproc.h b/libyasm/preproc.h
index fff40daa..0b8c54ff 100644
--- a/libyasm/preproc.h
+++ b/libyasm/preproc.h
@@ -105,6 +105,11 @@ typedef struct yasm_preproc_module {
* Call yasm_preproc_builtin_define() instead of calling this function.
*/
void (*define_builtin) (yasm_preproc *preproc, const char *macronameval);
+
+ /** Module-level implementation of yasm_preproc_add_standard().
+ * Call yasm_preproc_add_standard() instead of calling this function.
+ */
+ void (*add_standard) (yasm_preproc *preproc, const char **macros);
} yasm_preproc_module;
/** Initialize preprocessor.
@@ -169,6 +174,14 @@ void yasm_preproc_undefine_macro(yasm_preproc *preproc, const char *macroname);
void yasm_preproc_define_builtin(yasm_preproc *preproc,
const char *macronameval);
+/** Define additional standard macros, preprocessed after the builtins but
+ * prior to any user-defined macros.
+ * \param preproc preprocessor
+ * \param macros NULL-terminated array of macro strings
+ */
+void yasm_preproc_add_standard(yasm_preproc *preproc,
+ const char **macros);
+
#ifndef YASM_DOXYGEN
/* Inline macro implementations for preproc functions */
@@ -192,6 +205,9 @@ void yasm_preproc_define_builtin(yasm_preproc *preproc,
#define yasm_preproc_define_builtin(preproc, macronameval) \
((yasm_preproc_base *)preproc)->module->define_builtin(preproc, \
macronameval)
+#define yasm_preproc_add_standard(preproc, macros) \
+ ((yasm_preproc_base *)preproc)->module->add_standard(preproc, \
+ macros)
#endif
diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c
index e1080760..478502ec 100644
--- a/modules/objfmts/bin/bin-objfmt.c
+++ b/modules/objfmts/bin/bin-objfmt.c
@@ -1771,6 +1771,18 @@ static const yasm_directive bin_objfmt_directives[] = {
{ NULL, NULL, NULL, 0 }
};
+static const char *bin_nasm_stdmac[] = {
+ "%imacro org 1+.nolist",
+ "[org %1]",
+ "%endmacro",
+ NULL
+};
+
+static const yasm_stdmac bin_objfmt_stdmacs[] = {
+ { "nasm", "nasm", bin_nasm_stdmac },
+ { NULL, NULL, NULL }
+};
+
/* Define objfmt structure -- see objfmt.h for details */
yasm_objfmt_module yasm_bin_LTX_objfmt = {
"Flat format binary",
@@ -1780,6 +1792,7 @@ yasm_objfmt_module yasm_bin_LTX_objfmt = {
bin_objfmt_dbgfmt_keywords,
"null",
bin_objfmt_directives,
+ bin_objfmt_stdmacs,
bin_objfmt_create,
bin_objfmt_output,
bin_objfmt_destroy,
diff --git a/modules/objfmts/coff/Makefile.inc b/modules/objfmts/coff/Makefile.inc
index 526f7713..e9e8576d 100644
--- a/modules/objfmts/coff/Makefile.inc
+++ b/modules/objfmts/coff/Makefile.inc
@@ -6,6 +6,22 @@ libyasm_a_SOURCES += modules/objfmts/coff/win64-except.c
YASM_MODULES += objfmt_coff
+$(top_srcdir)/modules/objfmts/coff/coff-objfmt.c: win64-nasm.c win64-gas.c
+
+win64-nasm.c: $(srcdir)/modules/objfmts/coff/win64-nasm.mac genmacro$(EXEEXT)
+ $(top_builddir)/genmacro$(EXEEXT) $@ win64_nasm_stdmac $(srcdir)/modules/objfmts/coff/win64-nasm.mac
+
+BUILT_SOURCES += win64-nasm.c
+CLEANFILES += win64-nasm.c
+EXTRA_DIST += modules/objfmts/coff/win64-nasm.mac
+
+win64-gas.c: $(srcdir)/modules/objfmts/coff/win64-gas.mac genmacro$(EXEEXT)
+ $(top_builddir)/genmacro$(EXEEXT) $@ win64_gas_stdmac $(srcdir)/modules/objfmts/coff/win64-gas.mac
+
+BUILT_SOURCES += win64-gas.c
+CLEANFILES += win64-gas.c
+EXTRA_DIST += modules/objfmts/coff/win64-gas.mac
+
EXTRA_DIST += modules/objfmts/coff/tests/Makefile.inc
include modules/objfmts/coff/tests/Makefile.inc
diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c
index 22ecac45..16cf6ea3 100644
--- a/modules/objfmts/coff/coff-objfmt.c
+++ b/modules/objfmts/coff/coff-objfmt.c
@@ -2192,6 +2192,7 @@ yasm_objfmt_module yasm_coff_LTX_objfmt = {
coff_objfmt_dbgfmt_keywords,
"null",
coff_objfmt_directives,
+ NULL, /* no standard macros */
coff_objfmt_create,
coff_objfmt_output,
coff_objfmt_destroy,
@@ -2218,6 +2219,21 @@ static const yasm_directive win32_objfmt_directives[] = {
{ NULL, NULL, NULL, 0 }
};
+static const char *win32_nasm_stdmac[] = {
+ "%imacro export 1+.nolist",
+ "[export %1]",
+ "%endmacro",
+ "%imacro safeseh 1+.nolist",
+ "[safeseh %1]",
+ "%endmacro",
+ NULL
+};
+
+static const yasm_stdmac win32_objfmt_stdmacs[] = {
+ { "nasm", "nasm", win32_nasm_stdmac },
+ { NULL, NULL, NULL }
+};
+
/* Define objfmt structure -- see objfmt.h for details */
yasm_objfmt_module yasm_win32_LTX_objfmt = {
"Win32",
@@ -2227,6 +2243,7 @@ yasm_objfmt_module yasm_win32_LTX_objfmt = {
winXX_objfmt_dbgfmt_keywords,
"null",
win32_objfmt_directives,
+ win32_objfmt_stdmacs,
win32_objfmt_create,
coff_objfmt_output,
coff_objfmt_destroy,
@@ -2261,6 +2278,15 @@ static const yasm_directive win64_objfmt_directives[] = {
{ NULL, NULL, NULL, 0 }
};
+#include "win64-nasm.c"
+#include "win64-gas.c"
+
+static const yasm_stdmac win64_objfmt_stdmacs[] = {
+ { "nasm", "nasm", win64_nasm_stdmac },
+ { "gas", "nasm", win64_gas_stdmac },
+ { NULL, NULL, NULL }
+};
+
/* Define objfmt structure -- see objfmt.h for details */
yasm_objfmt_module yasm_win64_LTX_objfmt = {
"Win64",
@@ -2270,6 +2296,7 @@ yasm_objfmt_module yasm_win64_LTX_objfmt = {
winXX_objfmt_dbgfmt_keywords,
"null",
win64_objfmt_directives,
+ win64_objfmt_stdmacs,
win64_objfmt_create,
coff_objfmt_output,
coff_objfmt_destroy,
@@ -2285,6 +2312,7 @@ yasm_objfmt_module yasm_x64_LTX_objfmt = {
winXX_objfmt_dbgfmt_keywords,
"null",
win64_objfmt_directives,
+ win64_objfmt_stdmacs,
win64_objfmt_create,
coff_objfmt_output,
coff_objfmt_destroy,
diff --git a/modules/objfmts/coff/win64-gas.mac b/modules/objfmts/coff/win64-gas.mac
new file mode 100644
index 00000000..cf1e7dc6
--- /dev/null
+++ b/modules/objfmts/coff/win64-gas.mac
@@ -0,0 +1,73 @@
+%imacro export 1+.nolist
+.export %1
+%endmacro
+
+; Raw exception handling operations
+%imacro proc_frame 1+.nolist
+%1:
+.proc_frame %1
+%endmacro
+
+%imacro endproc_frame 0.nolist
+.endproc_frame
+%endmacro
+
+; Complex (macro) exception handling operations
+; Mimics many macros provided by MASM's macamd64.inc
+%imacro push_reg 1
+pushq %1
+.pushreg %1
+%endmacro
+
+%imacro rex_push_reg 1
+.byte 0x48
+pushq %1
+.pushreg %1
+%endmacro
+
+%imacro push_eflags 0
+pushfq
+.allocstack 8
+%endmacro
+
+%imacro rex_push_eflags 0
+.byte 0x48
+pushfq
+.allocstack 8
+%endmacro
+
+%imacro alloc_stack 1
+subq %1, %rsp
+.allocstack %1
+%endmacro
+
+%imacro save_reg 2
+movq %1, %2(%rsp)
+.savereg %1 %2
+%endmacro
+
+%imacro save_xmm128 2
+movdqa %1, %2(%rsp)
+.savexmm128 %1, %2
+%endmacro
+
+%imacro push_frame 0-1.nolist
+.pushframe %1
+%endmacro
+
+%imacro set_frame 1-2
+%if %0==1
+movq %rsp, %1
+%else
+leaq %2(%rsp), %1
+%endif
+.setframe %1, %2
+%endmacro
+
+%imacro end_prolog 0.nolist
+.endprolog
+%endmacro
+
+%imacro end_prologue 0.nolist
+.endprolog
+%endmacro
diff --git a/modules/objfmts/coff/win64-nasm.mac b/modules/objfmts/coff/win64-nasm.mac
new file mode 100644
index 00000000..13954b89
--- /dev/null
+++ b/modules/objfmts/coff/win64-nasm.mac
@@ -0,0 +1,106 @@
+%imacro export 1+.nolist
+[export %1]
+%endmacro
+
+; Raw exception handling operations
+%imacro proc_frame 1+.nolist
+%1:
+[proc_frame %1]
+%endmacro
+
+; Disable these as they're too closely named to the macroized ones.
+; MASM needs a preceding . to use these, so it seems reasonable for
+; us to similarly require the [].
+;
+;%imacro pushreg 1.nolist
+;[pushreg %1]
+;%endmacro
+;
+;%imacro setframe 1-2.nolist
+;[setframe %1 %2]
+;%endmacro
+;
+;%imacro allocstack 1.nolist
+;[allocstack %1]
+;%endmacro
+;
+;%imacro savereg 2.nolist
+;[savereg %1 %2]
+;%endmacro
+;
+;%imacro savexmm128 2.nolist
+;[savexmm128 %1 %2]
+;%endmacro
+;
+;%imacro pushframe 0-1.nolist
+;[pushframe %1]
+;%endmacro
+;
+;%imacro endprolog 0.nolist
+;[endprolog]
+;%endmacro
+;
+
+%imacro endproc_frame 0.nolist
+[endproc_frame]
+%endmacro
+
+; Complex (macro) exception handling operations
+; Mimics many macros provided by MASM's macamd64.inc
+%imacro push_reg 1
+push %1
+[pushreg %1]
+%endmacro
+
+%imacro rex_push_reg 1
+db 0x48
+push %1
+[pushreg %1]
+%endmacro
+
+%imacro push_eflags 0
+pushfq
+[allocstack 8]
+%endmacro
+
+%imacro rex_push_eflags 0
+db 0x48
+pushfq
+[allocstack 8]
+%endmacro
+
+%imacro alloc_stack 1
+sub rsp, %1
+[allocstack %1]
+%endmacro
+
+%imacro save_reg 2
+mov [rsp+%2], %1
+[savereg %1 %2]
+%endmacro
+
+%imacro save_xmm128 2
+movdqa [rsp+%2], %1
+[savexmm128 %1 %2]
+%endmacro
+
+%imacro push_frame 0-1.nolist
+[pushframe %1]
+%endmacro
+
+%imacro set_frame 1-2
+%if %0==1
+mov %1, rsp
+%else
+lea %1, [rsp+%2]
+%endif
+[setframe %1 %2]
+%endmacro
+
+%imacro end_prolog 0.nolist
+[endprolog]
+%endmacro
+
+%imacro end_prologue 0.nolist
+[endprolog]
+%endmacro
diff --git a/modules/objfmts/dbg/dbg-objfmt.c b/modules/objfmts/dbg/dbg-objfmt.c
index 21a161ab..ad5f14a1 100644
--- a/modules/objfmts/dbg/dbg-objfmt.c
+++ b/modules/objfmts/dbg/dbg-objfmt.c
@@ -165,6 +165,7 @@ yasm_objfmt_module yasm_dbg_LTX_objfmt = {
dbg_objfmt_dbgfmt_keywords,
"null",
NULL, /* no directives */
+ NULL, /* no standard macros */
dbg_objfmt_create,
dbg_objfmt_output,
dbg_objfmt_destroy,
diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c
index 142275ea..d2083a84 100644
--- a/modules/objfmts/elf/elf-objfmt.c
+++ b/modules/objfmts/elf/elf-objfmt.c
@@ -1310,6 +1310,24 @@ static const yasm_directive elf_objfmt_directives[] = {
{ NULL, NULL, NULL, 0 }
};
+static const char *elf_nasm_stdmac[] = {
+ "%imacro type 1+.nolist",
+ "[type %1]",
+ "%endmacro",
+ "%imacro size 1+.nolist",
+ "[size %1]",
+ "%endmacro",
+ "%imacro weak 1+.nolist",
+ "[weak %1]",
+ "%endmacro",
+ NULL
+};
+
+static const yasm_stdmac elf_objfmt_stdmacs[] = {
+ { "nasm", "nasm", elf_nasm_stdmac },
+ { NULL, NULL, NULL }
+};
+
/* Define objfmt structure -- see objfmt.h for details */
yasm_objfmt_module yasm_elf_LTX_objfmt = {
"ELF",
@@ -1319,6 +1337,7 @@ yasm_objfmt_module yasm_elf_LTX_objfmt = {
elf_objfmt_dbgfmt_keywords,
"null",
elf_objfmt_directives,
+ elf_objfmt_stdmacs,
elf_objfmt_create,
elf_objfmt_output,
elf_objfmt_destroy,
@@ -1335,6 +1354,7 @@ yasm_objfmt_module yasm_elf32_LTX_objfmt = {
elf_objfmt_dbgfmt_keywords,
"null",
elf_objfmt_directives,
+ elf_objfmt_stdmacs,
elf32_objfmt_create,
elf_objfmt_output,
elf_objfmt_destroy,
@@ -1351,6 +1371,7 @@ yasm_objfmt_module yasm_elf64_LTX_objfmt = {
elf_objfmt_dbgfmt_keywords,
"null",
elf_objfmt_directives,
+ elf_objfmt_stdmacs,
elf64_objfmt_create,
elf_objfmt_output,
elf_objfmt_destroy,
diff --git a/modules/objfmts/macho/macho-objfmt.c b/modules/objfmts/macho/macho-objfmt.c
index 4628bf74..0a049baf 100644
--- a/modules/objfmts/macho/macho-objfmt.c
+++ b/modules/objfmts/macho/macho-objfmt.c
@@ -1551,6 +1551,7 @@ yasm_objfmt_module yasm_macho_LTX_objfmt = {
macho_objfmt_dbgfmt_keywords,
"null",
NULL, /* no directives */
+ NULL, /* no standard macros */
macho_objfmt_create,
macho_objfmt_output,
macho_objfmt_destroy,
@@ -1567,6 +1568,7 @@ yasm_objfmt_module yasm_macho32_LTX_objfmt = {
macho_objfmt_dbgfmt_keywords,
"null",
NULL, /* no directives */
+ NULL, /* no standard macros */
macho32_objfmt_create,
macho_objfmt_output,
macho_objfmt_destroy,
@@ -1583,6 +1585,7 @@ yasm_objfmt_module yasm_macho64_LTX_objfmt = {
macho_objfmt_dbgfmt_keywords,
"null",
NULL, /* no directives */
+ NULL, /* no standard macros */
macho64_objfmt_create,
macho_objfmt_output,
macho_objfmt_destroy,
diff --git a/modules/objfmts/rdf/rdf-objfmt.c b/modules/objfmts/rdf/rdf-objfmt.c
index 22e2a1c7..e4173289 100644
--- a/modules/objfmts/rdf/rdf-objfmt.c
+++ b/modules/objfmts/rdf/rdf-objfmt.c
@@ -1057,6 +1057,21 @@ static const yasm_directive rdf_objfmt_directives[] = {
{ NULL, NULL, NULL, 0 }
};
+static const char *rdf_nasm_stdmac[] = {
+ "%imacro library 1+.nolist",
+ "[library %1]",
+ "%endmacro",
+ "%imacro module 1+.nolist",
+ "[module %1]",
+ "%endmacro",
+ NULL
+};
+
+static const yasm_stdmac rdf_objfmt_stdmacs[] = {
+ { "nasm", "nasm", rdf_nasm_stdmac },
+ { NULL, NULL, NULL }
+};
+
/* Define objfmt structure -- see objfmt.h for details */
yasm_objfmt_module yasm_rdf_LTX_objfmt = {
"Relocatable Dynamic Object File Format (RDOFF) v2.0",
@@ -1066,6 +1081,7 @@ yasm_objfmt_module yasm_rdf_LTX_objfmt = {
rdf_objfmt_dbgfmt_keywords,
"null",
rdf_objfmt_directives,
+ rdf_objfmt_stdmacs,
rdf_objfmt_create,
rdf_objfmt_output,
rdf_objfmt_destroy,
diff --git a/modules/objfmts/win64/tests/Makefile.inc b/modules/objfmts/win64/tests/Makefile.inc
index 4bc0907c..06e0f86d 100644
--- a/modules/objfmts/win64/tests/Makefile.inc
+++ b/modules/objfmts/win64/tests/Makefile.inc
@@ -27,3 +27,7 @@ EXTRA_DIST += modules/objfmts/win64/tests/win64-dataref.masm
EXTRA_DIST += modules/objfmts/win64/tests/win64-dataref2.asm
EXTRA_DIST += modules/objfmts/win64/tests/win64-dataref2.hex
EXTRA_DIST += modules/objfmts/win64/tests/win64-dataref2.masm
+
+EXTRA_DIST += modules/objfmts/win64/tests/gas/Makefile.inc
+
+include modules/objfmts/win64/tests/gas/Makefile.inc
diff --git a/modules/objfmts/win64/tests/gas/Makefile.inc b/modules/objfmts/win64/tests/gas/Makefile.inc
new file mode 100644
index 00000000..0d16bd12
--- /dev/null
+++ b/modules/objfmts/win64/tests/gas/Makefile.inc
@@ -0,0 +1,7 @@
+# $Id$
+
+TESTS += modules/objfmts/win64/tests/gas/win64_gas_test.sh
+
+EXTRA_DIST += modules/objfmts/win64/tests/gas/win64_gas_test.sh
+EXTRA_DIST += modules/objfmts/win64/tests/gas/win64-gas-sce.asm
+EXTRA_DIST += modules/objfmts/win64/tests/gas/win64-gas-sce.hex
diff --git a/modules/objfmts/win64/tests/gas/win64-gas-sce.asm b/modules/objfmts/win64/tests/gas/win64-gas-sce.asm
new file mode 100644
index 00000000..3a75ee4c
--- /dev/null
+++ b/modules/objfmts/win64/tests/gas/win64-gas-sce.asm
@@ -0,0 +1,11 @@
+PROC_FRAME sample
+rex_push_reg %rbp
+rex_push_eflags
+alloc_stack 16
+save_reg %rsi, 0x18
+save_xmm128 %xmm7, 0x20
+push_frame 16
+set_frame %rdi
+set_frame %rdi, 16
+END_PROLOGUE
+ENDPROC_FRAME
diff --git a/modules/objfmts/win64/tests/gas/win64-gas-sce.hex b/modules/objfmts/win64/tests/gas/win64-gas-sce.hex
new file mode 100644
index 00000000..ff4288f9
--- /dev/null
+++ b/modules/objfmts/win64/tests/gas/win64-gas-sce.hex
@@ -0,0 +1,403 @@
+64
+86
+03
+00
+00
+00
+00
+00
+ed
+00
+00
+00
+09
+00
+00
+00
+00
+00
+04
+00
+2e
+74
+65
+78
+74
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+1f
+00
+00
+00
+8c
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+20
+00
+50
+60
+2e
+78
+64
+61
+74
+61
+00
+00
+1f
+00
+00
+00
+00
+00
+00
+00
+18
+00
+00
+00
+ab
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+40
+00
+40
+40
+2e
+70
+64
+61
+74
+61
+00
+00
+37
+00
+00
+00
+00
+00
+00
+00
+0c
+00
+00
+00
+c3
+00
+00
+00
+cf
+00
+00
+00
+00
+00
+00
+00
+03
+00
+00
+00
+40
+00
+30
+40
+48
+55
+48
+9c
+48
+2b
+24
+25
+10
+00
+00
+00
+48
+89
+74
+24
+18
+66
+0f
+7f
+7c
+24
+20
+48
+89
+e7
+48
+8d
+7c
+24
+10
+01
+1f
+0a
+17
+1f
+73
+1a
+73
+17
+1a
+17
+78
+02
+00
+11
+64
+03
+00
+0c
+12
+04
+02
+02
+50
+00
+00
+00
+00
+1f
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
+03
+00
+04
+00
+00
+00
+04
+00
+00
+00
+03
+00
+08
+00
+00
+00
+05
+00
+00
+00
+03
+00
+2e
+66
+69
+6c
+65
+00
+00
+00
+00
+00
+00
+00
+fe
+ff
+00
+00
+67
+01
+2d
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+2e
+74
+65
+78
+74
+00
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+03
+01
+1f
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+73
+61
+6d
+70
+6c
+65
+00
+00
+00
+00
+00
+00
+01
+00
+00
+00
+03
+00
+2e
+78
+64
+61
+74
+61
+00
+00
+00
+00
+00
+00
+02
+00
+00
+00
+03
+01
+18
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+2e
+70
+64
+61
+74
+61
+00
+00
+00
+00
+00
+00
+03
+00
+00
+00
+03
+01
+0c
+00
+00
+00
+03
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+00
+04
+00
+00
+00
diff --git a/modules/objfmts/win64/tests/gas/win64_gas_test.sh b/modules/objfmts/win64/tests/gas/win64_gas_test.sh
new file mode 100755
index 00000000..55753839
--- /dev/null
+++ b/modules/objfmts/win64/tests/gas/win64_gas_test.sh
@@ -0,0 +1,4 @@
+#! /bin/sh
+# $Id$
+${srcdir}/out_test.sh win64_gas_test modules/objfmts/win64/tests/gas "win64 objfmt" "-f win64 -p gas -r nasm" ".obj"
+exit $?
diff --git a/modules/objfmts/xdf/xdf-objfmt.c b/modules/objfmts/xdf/xdf-objfmt.c
index d7cb453b..89cb403c 100644
--- a/modules/objfmts/xdf/xdf-objfmt.c
+++ b/modules/objfmts/xdf/xdf-objfmt.c
@@ -839,6 +839,7 @@ yasm_objfmt_module yasm_xdf_LTX_objfmt = {
xdf_objfmt_dbgfmt_keywords,
"null",
NULL, /* no directives */
+ NULL, /* no standard macros */
xdf_objfmt_create,
xdf_objfmt_output,
xdf_objfmt_destroy,
diff --git a/modules/parsers/gas/gas-parser.c b/modules/parsers/gas/gas-parser.c
index 1e7fb8b6..de3397c2 100644
--- a/modules/parsers/gas/gas-parser.c
+++ b/modules/parsers/gas/gas-parser.c
@@ -129,6 +129,7 @@ yasm_parser_module yasm_gas_LTX_parser = {
"gas",
gas_parser_preproc_keywords,
"raw",
+ NULL, /* No standard macros */
gas_parser_do_parse
};
yasm_parser_module yasm_gnu_LTX_parser = {
@@ -136,5 +137,6 @@ yasm_parser_module yasm_gnu_LTX_parser = {
"gnu",
gas_parser_preproc_keywords,
"raw",
+ NULL, /* No standard macros */
gas_parser_do_parse
};
diff --git a/modules/parsers/nasm/Makefile.inc b/modules/parsers/nasm/Makefile.inc
index 9994e316..ac174ca0 100644
--- a/modules/parsers/nasm/Makefile.inc
+++ b/modules/parsers/nasm/Makefile.inc
@@ -14,7 +14,17 @@ BUILT_SOURCES += nasm-token.c
CLEANFILES += nasm-token.c
-EXTRA_DIST += modules/parsers/nasm/tests/Makefile.inc
EXTRA_DIST += modules/parsers/nasm/nasm-token.re
+$(top_srcdir)/modules/parsers/nasm/nasm-parser.c: nasm-macros.c
+
+nasm-macros.c: $(srcdir)/modules/parsers/nasm/nasm-std.mac genmacro$(EXEEXT)
+ $(top_builddir)/genmacro$(EXEEXT) $@ nasm_standard_mac $(srcdir)/modules/parsers/nasm/nasm-std.mac
+
+BUILT_SOURCES += nasm-macros.c
+CLEANFILES += nasm-macros.c
+EXTRA_DIST += modules/parsers/nasm/nasm-std.mac
+
+EXTRA_DIST += modules/parsers/nasm/tests/Makefile.inc
+
include modules/parsers/nasm/tests/Makefile.inc
diff --git a/modules/parsers/nasm/nasm-parser.c b/modules/parsers/nasm/nasm-parser.c
index dc46a717..ac10de37 100644
--- a/modules/parsers/nasm/nasm-parser.c
+++ b/modules/parsers/nasm/nasm-parser.c
@@ -77,6 +77,8 @@ nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
yasm_symtab_parser_finalize(object->symtab, 0, errwarns);
}
+#include "nasm-macros.c"
+
/* Define valid preprocessors to use with this parser */
static const char *nasm_parser_preproc_keywords[] = {
"raw",
@@ -84,11 +86,17 @@ static const char *nasm_parser_preproc_keywords[] = {
NULL
};
+static const yasm_stdmac nasm_parser_stdmacs[] = {
+ { "nasm", "nasm", nasm_standard_mac },
+ { NULL, NULL, NULL }
+};
+
/* Define parser structure -- see parser.h for details */
yasm_parser_module yasm_nasm_LTX_parser = {
"NASM-compatible parser",
"nasm",
nasm_parser_preproc_keywords,
"nasm",
+ nasm_parser_stdmacs,
nasm_parser_do_parse
};
diff --git a/modules/parsers/nasm/nasm-std.mac b/modules/parsers/nasm/nasm-std.mac
new file mode 100644
index 00000000..3c9223ab
--- /dev/null
+++ b/modules/parsers/nasm/nasm-std.mac
@@ -0,0 +1,109 @@
+; Standard macro set for NASM -*- 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
+; directive should be defined in the module for that directive.
+
+; These two need to be defined, though the actual definitions will
+; be constantly updated during preprocessing.
+%define __FILE__
+%define __LINE__
+
+%define __SECT__ [section .text] ; it ought to be defined, even if as nothing
+
+%imacro section 1+.nolist
+%define __SECT__ [section %1]
+ __SECT__
+%endmacro
+%imacro segment 1+.nolist
+%define __SECT__ [segment %1]
+ __SECT__
+%endmacro
+
+%imacro absolute 1+.nolist
+%define __SECT__ [absolute %1]
+ __SECT__
+%endmacro
+
+%imacro struc 1.nolist
+%push struc
+%define %$strucname %1
+[absolute 0]
+%$strucname: ; allow definition of `.member' to work sanely
+%endmacro
+%imacro endstruc 0.nolist
+%{$strucname}_size:
+%pop
+__SECT__
+%endmacro
+
+%imacro istruc 1.nolist
+%push istruc
+%define %$strucname %1
+%$strucstart:
+%endmacro
+%imacro at 1-2+.nolist
+ times %1-($-%$strucstart) db 0
+ %2
+%endmacro
+%imacro iend 0.nolist
+ times %{$strucname}_size-($-%$strucstart) db 0
+%pop
+%endmacro
+
+%imacro align 1-2+.nolist nop
+%ifidni %2,nop
+ [align %1]
+%else
+ times ($$-$) & ((%1)-1) %2
+%endif
+%endmacro
+%imacro alignb 1-2+.nolist resb 1
+ times ($$-$) & ((%1)-1) %2
+%endmacro
+
+%imacro extern 1-*.nolist
+%rep %0
+[extern %1]
+%rotate 1
+%endrep
+%endmacro
+
+%imacro bits 1+.nolist
+[bits %1]
+%endmacro
+
+%imacro use16 0.nolist
+[bits 16]
+%endmacro
+%imacro use32 0.nolist
+[bits 32]
+%endmacro
+%imacro use64 0.nolist
+[bits 64]
+%endmacro
+
+%imacro global 1-*.nolist
+%rep %0
+[global %1]
+%rotate 1
+%endrep
+%endmacro
+
+%imacro common 1-*.nolist
+%rep %0
+[common %1]
+%rotate 1
+%endrep
+%endmacro
+
+%imacro cpu 1+.nolist
+[cpu %1]
+%endmacro
+
+%imacro default 1+.nolist
+[default %1]
+%endmacro
+
+; NASM compatibility shim
+%define __OUTPUT_FORMAT__ __YASM_OBJFMT__
diff --git a/modules/preprocs/cpp/cpp-preproc.c b/modules/preprocs/cpp/cpp-preproc.c
index dae2e032..c58e4044 100644
--- a/modules/preprocs/cpp/cpp-preproc.c
+++ b/modules/preprocs/cpp/cpp-preproc.c
@@ -377,6 +377,12 @@ cpp_preproc_define_builtin(yasm_preproc *preproc, const char *macronameval)
cpp_preproc_predefine_macro(preproc, macronameval);
}
+static void
+cpp_preproc_add_standard(yasm_preproc *preproc, const char **macros)
+{
+ /* TODO */
+}
+
/*******************************************************************************
Preprocessor module object.
*******************************************************************************/
@@ -391,5 +397,6 @@ yasm_preproc_module yasm_cpp_LTX_preproc = {
cpp_preproc_add_include_file,
cpp_preproc_predefine_macro,
cpp_preproc_undefine_macro,
- cpp_preproc_define_builtin
+ cpp_preproc_define_builtin,
+ cpp_preproc_add_standard
};
diff --git a/modules/preprocs/nasm/Makefile.inc b/modules/preprocs/nasm/Makefile.inc
index a91eb914..f9aa9d5e 100644
--- a/modules/preprocs/nasm/Makefile.inc
+++ b/modules/preprocs/nasm/Makefile.inc
@@ -11,23 +11,13 @@ libyasm_a_SOURCES += modules/preprocs/nasm/nasm-eval.c
YASM_MODULES += preproc_nasm
-$(top_srcdir)/src/preprocs/nasm/nasm-pp.c: nasm-macros.c
+$(top_srcdir)/modules/preprocs/nasm/nasm-preproc.c: nasm-version.c
-nasm-macros.c: $(top_srcdir)/modules/preprocs/nasm/standard.mac version.mac genmacro$(EXEEXT)
- $(top_builddir)/genmacro$(EXEEXT) $(top_srcdir)/modules/preprocs/nasm/standard.mac version.mac
+nasm-version.c: version.mac genmacro$(EXEEXT)
+ $(top_builddir)/genmacro$(EXEEXT) $@ nasm_version_mac version.mac
-BUILT_SOURCES += nasm-macros.c
-CLEANFILES += nasm-macros.c
-
-noinst_PROGRAMS += genmacro
-
-genmacro_SOURCES =
-EXTRA_DIST += modules/preprocs/nasm/genmacro.c
-genmacro_LDADD = genmacro.$(OBJEXT)
-genmacro_LINK = $(CCLD_FOR_BUILD) -o $@
-
-genmacro.$(OBJEXT): modules/preprocs/nasm/genmacro.c
- $(CC_FOR_BUILD) $(DEFAULT_INCLUDES) $(INCLUDES) -c -o $@ `test -f modules/preprocs/nasm/genmacro.c || echo '$(srcdir)/'`modules/preprocs/nasm/genmacro.c
+BUILT_SOURCES += nasm-version.c
+CLEANFILES += nasm-version.c
version.mac: genversion$(EXEEXT)
$(top_builddir)/genversion$(EXEEXT) $@
@@ -45,7 +35,6 @@ genversion_LINK = $(CCLD_FOR_BUILD) -o $@
genversion.$(OBJEXT): modules/preprocs/nasm/genversion.c
$(CC_FOR_BUILD) $(DEFAULT_INCLUDES) $(INCLUDES) -c -o $@ `test -f modules/preprocs/nasm/genversion.c || echo '$(srcdir)/'`modules/preprocs/nasm/genversion.c
-EXTRA_DIST += modules/preprocs/nasm/standard.mac
EXTRA_DIST += modules/preprocs/nasm/tests/Makefile.inc
include modules/preprocs/nasm/tests/Makefile.inc
diff --git a/modules/preprocs/nasm/genmacro.c b/modules/preprocs/nasm/genmacro.c
deleted file mode 100644
index e6f40193..00000000
--- a/modules/preprocs/nasm/genmacro.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/* $Id$
- *
- * C version of NASM's macros.pl
- *
- * Copyright (C) 2004-2007 Peter Johnson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define OUTPUT "nasm-macros.c"
-#define MAXLINE 1024
-
-int
-main(int argc, char *argv[])
-{
- FILE *in, *out;
- int i;
- char *str;
- char *strp;
- char *charp;
- int fline;
- int line = 0;
- int lindex = 0;
- int tasm_count = -1;
- size_t len;
-
- if (argc < 2) {
- fprintf(stderr, "Usage: %s <file> [<file> ...]\n", argv[0]);
- return EXIT_FAILURE;
- }
-
- out = fopen(OUTPUT, "wt");
-
- if (!out) {
- fprintf(stderr, "Could not open `%s'.\n", OUTPUT);
- return EXIT_FAILURE;
- }
-
- str = malloc(MAXLINE);
-
- fprintf(out, "/* This file auto-generated from standard.mac by genmacro.c"
- " - don't edit it */\n\n#include <stddef.h>\n\n"
- "static const char *stdmac[] = {\n");
-
- for (i=1; i<argc; i++) {
- in = fopen(argv[i], "rt");
- if (!in) {
- fprintf(stderr, "Could not open `%s'.\n", argv[i]);
- fclose(out);
- remove(OUTPUT);
- return EXIT_FAILURE;
- }
-
- fline = 0;
-
- while (fgets(str, MAXLINE, in)) {
- line++;
- fline++;
-
- strp = str;
-
- /* check for unterminated quotes and delete comments */
- charp = strp;
- while ((charp = strpbrk(charp, "'\";"))) {
- if (charp[0] == ';') {
- *charp = '\0';
- break;
- }
- if ((charp = strchr(charp+1, charp[0])) == NULL) {
- fprintf(stderr, "%s:%d: error: unterminated quote\n",
- argv[i], fline);
- fclose(out);
- remove(OUTPUT);
- return EXIT_FAILURE;
- }
- charp++;
- }
-
- /* strip off leading and trailing whitespace */
- while (*strp == ' ' || *strp == '\t')
- strp++;
- len = strlen(strp);
- while (len > 0 && (strp[len-1] == ' ' || strp[len-1] == '\t' ||
- strp[len-1] == '\n')) {
- strp[len-1] = '\0';
- len--;
- }
-
- /* skip blank lines */
- if (len == 0)
- continue;
-
- /* check for special TASM ending token */
- if (strcmp(strp, "*END*TASM*MACROS*") == 0) {
- tasm_count = lindex;
- continue;
- }
-
- /* output as string to output file */
- fprintf(out, " \"");
- while (*strp != '\0') {
- if (*strp == '\\' || *strp == '"')
- fputc('\\', out);
- fputc(*strp, out);
- strp++;
- }
- fprintf(out, "\",\n");
- lindex++;
- }
-
- fclose(in);
- }
-
- fprintf(out, " NULL\n};\n");
- if (tasm_count == -1)
- tasm_count = lindex;
- fprintf(out, "#define TASM_MACRO_COUNT %d\n", tasm_count);
- fclose(out);
-
- free(str);
-
- return EXIT_SUCCESS;
-}
diff --git a/modules/preprocs/nasm/genversion.c b/modules/preprocs/nasm/genversion.c
index 5426c3dd..ac977685 100644
--- a/modules/preprocs/nasm/genversion.c
+++ b/modules/preprocs/nasm/genversion.c
@@ -43,6 +43,11 @@ main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ if (sscanf(PACKAGE_INTVER, "%d.%d.%d", &major, &minor, &subminor) != 3) {
+ fprintf(stderr, "Version tokenizing error\n");
+ return EXIT_FAILURE;
+ }
+
out = fopen(argv[1], "wt");
if (!out) {
@@ -53,13 +58,6 @@ main(int argc, char *argv[])
fprintf(out, "; This file auto-generated by genversion.c"
" - don't edit it\n");
- if (sscanf(PACKAGE_INTVER, "%d.%d.%d", &major, &minor, &subminor) != 3) {
- fprintf(stderr, "Version tokenizing error\n");
- fclose(out);
- remove(argv[1]);
- return EXIT_FAILURE;
- }
-
fprintf(out, "%%define __YASM_MAJOR__ %d\n", major);
fprintf(out, "%%define __YASM_MINOR__ %d\n", minor);
fprintf(out, "%%define __YASM_SUBMINOR__ %d\n", subminor);
diff --git a/modules/preprocs/nasm/nasm-pp.c b/modules/preprocs/nasm/nasm-pp.c
index 2bb94b04..2d5e7d21 100644
--- a/modules/preprocs/nasm/nasm-pp.c
+++ b/modules/preprocs/nasm/nasm-pp.c
@@ -351,7 +351,9 @@ static int pass; /* HACK: pass 0 = generate dependencies only */
static unsigned long unique; /* unique identifier numbers */
static Line *builtindef = NULL;
+static Line *stddef = NULL;
static Line *predef = NULL;
+static int first_line = 1;
static ListGen *list;
@@ -384,18 +386,19 @@ static MMacro *defining;
#define PARAM_DELTA 16
/*
- * The standard macro set: defined as `static char *stdmac[]'. Also
- * gives our position in the macro set, when we're processing it.
+ * Macros to make NASM ignore some TASM directives before the first include
+ * directive.
*/
-#include "nasm-macros.c"
-static const char **stdmacpos;
-
-/*
- * The extra standard macros that come from the object format, if
- * any.
- */
-static const char **extrastdmac = NULL;
-int any_extrastdmac;
+static const char *tasm_compat_macros[] =
+{
+ "%idefine IDEAL",
+ "%idefine JUMPS",
+ "%idefine P386",
+ "%idefine P486",
+ "%idefine P586",
+ "%idefine END",
+ NULL
+};
static int nested_mac_count, nested_rep_count;
@@ -641,69 +644,6 @@ read_line(void)
char *buffer, *p, *q;
int bufsize, continued_count;
- Line *pd, *l;
- Token *head, **tail, *t;
-
- /* Nasty hack for builtin defines */
- for (pd = builtindef; pd; pd = pd->next)
- {
- head = NULL;
- tail = &head;
- for (t = pd->first; t; t = t->next)
- {
- *tail = new_Token(NULL, t->type, t->text, 0);
- tail = &(*tail)->next;
- }
- l = nasm_malloc(sizeof(Line));
- l->next = istk->expansion;
- l->first = head;
- l->finishes = FALSE;
- istk->expansion = l;
- }
-
- if (stdmacpos)
- {
- if (*stdmacpos)
- {
- char *ret = nasm_strdup(*stdmacpos++);
- if (!*stdmacpos && any_extrastdmac)
- {
- stdmacpos = extrastdmac;
- any_extrastdmac = FALSE;
- return ret;
- }
- /*
- * Nasty hack: here we push the contents of `predef' on
- * to the top-level expansion stack, since this is the
- * most convenient way to implement the pre-include and
- * pre-define features.
- */
- if (!*stdmacpos)
- {
- for (pd = predef; pd; pd = pd->next)
- {
- head = NULL;
- tail = &head;
- for (t = pd->first; t; t = t->next)
- {
- *tail = new_Token(NULL, t->type, t->text, 0);
- tail = &(*tail)->next;
- }
- l = nasm_malloc(sizeof(Line));
- l->next = istk->expansion;
- l->first = head;
- l->finishes = FALSE;
- istk->expansion = l;
- }
- }
- return ret;
- }
- else
- {
- stdmacpos = NULL;
- }
- }
-
bufsize = BUF_DELTA;
buffer = nasm_malloc(BUF_DELTA);
p = buffer;
@@ -4213,15 +4153,42 @@ pp_reset(FILE *f, const char *file, int apass, efunc errfunc, evalfunc eval,
smacros[h] = NULL;
}
unique = 0;
- if (tasm_compatible_mode) {
- stdmacpos = stdmac;
- } else {
- stdmacpos = &stdmac[TASM_MACRO_COUNT];
- }
- any_extrastdmac = (extrastdmac != NULL);
+ if (tasm_compatible_mode) {
+ pp_extra_stdmac(tasm_compat_macros);
+ }
list = listgen;
evaluate = eval;
pass = apass;
+ first_line = 1;
+}
+
+/*
+ * Nasty hack: here we push the contents of `predef' on
+ * to the top-level expansion stack, since this is the
+ * most convenient way to implement the pre-include and
+ * pre-define features.
+ */
+static void
+poke_predef(Line *predef_lines)
+{
+ Line *pd, *l;
+ Token *head, **tail, *t;
+
+ for (pd = predef_lines; pd; pd = pd->next)
+ {
+ head = NULL;
+ tail = &head;
+ for (t = pd->first; t; t = t->next)
+ {
+ *tail = new_Token(NULL, t->type, t->text, 0);
+ tail = &(*tail)->next;
+ }
+ l = nasm_malloc(sizeof(Line));
+ l->next = istk->expansion;
+ l->first = head;
+ l->finishes = FALSE;
+ istk->expansion = l;
+ }
}
static char *
@@ -4237,6 +4204,16 @@ pp_getline(void)
* buffer or from the input file.
*/
tline = NULL;
+
+ if (first_line)
+ {
+ /* Reverse order */
+ poke_predef(predef);
+ poke_predef(stddef);
+ poke_predef(builtindef);
+ first_line = 0;
+ }
+
if (!istk)
return NULL;
while (istk->expansion && istk->expansion->finishes)
@@ -4501,6 +4478,7 @@ pp_cleanup(int pass_)
if (pass_ == 0)
{
free_llist(builtindef);
+ free_llist(stddef);
free_llist(predef);
delete_Blocks();
}
@@ -4589,7 +4567,24 @@ pp_builtin_define(char *definition)
void
pp_extra_stdmac(const char **macros)
{
- extrastdmac = macros;
+ const char **lp;
+
+ for (lp=macros; *lp; lp++)
+ {
+ char *macro;
+ Token *t;
+ Line *l;
+
+ macro = nasm_strdup(*lp);
+ t = tokenise(macro);
+ nasm_free(macro);
+
+ l = nasm_malloc(sizeof(Line));
+ l->next = stddef;
+ l->first = t;
+ l->finishes = FALSE;
+ stddef = l;
+ }
}
static void
diff --git a/modules/preprocs/nasm/nasm-preproc.c b/modules/preprocs/nasm/nasm-preproc.c
index a0d941cf..bb4c7a74 100644
--- a/modules/preprocs/nasm/nasm-preproc.c
+++ b/modules/preprocs/nasm/nasm-preproc.c
@@ -48,6 +48,8 @@ static yasm_linemap *cur_lm;
static yasm_errwarns *cur_errwarns;
int tasm_compatible_mode = 0;
+#include "nasm-version.c"
+
typedef struct preproc_dep {
STAILQ_ENTRY(preproc_dep) link;
char *name;
@@ -156,6 +158,8 @@ nasm_preproc_create(const char *in_filename, yasm_symtab *symtab,
preproc_nasm->lineinc = 0;
nasmpp.reset(f, in_filename, 2, nasm_efunc, nasm_evaluate, &nil_list);
+ pp_extra_stdmac(nasm_version_mac);
+
return (yasm_preproc *)preproc_nasm;
}
@@ -290,6 +294,12 @@ nasm_preproc_define_builtin(yasm_preproc *preproc, const char *macronameval)
yasm_xfree(mnv);
}
+static void
+nasm_preproc_add_standard(yasm_preproc *preproc, const char **macros)
+{
+ pp_extra_stdmac(macros);
+}
+
/* Define preproc structure -- see preproc.h for details */
yasm_preproc_module yasm_nasm_LTX_preproc = {
"Real NASM Preprocessor",
@@ -301,5 +311,6 @@ yasm_preproc_module yasm_nasm_LTX_preproc = {
nasm_preproc_add_include_file,
nasm_preproc_predefine_macro,
nasm_preproc_undefine_macro,
- nasm_preproc_define_builtin
+ nasm_preproc_define_builtin,
+ nasm_preproc_add_standard
};
diff --git a/modules/preprocs/nasm/standard.mac b/modules/preprocs/nasm/standard.mac
deleted file mode 100644
index f459a7db..00000000
--- a/modules/preprocs/nasm/standard.mac
+++ /dev/null
@@ -1,293 +0,0 @@
-; Standard macro set for NASM -*- nasm -*-
-
-; Macros to make NASM ignore some TASM directives before the first include
-; directive.
-
- %idefine IDEAL
- %idefine JUMPS
- %idefine P386
- %idefine P486
- %idefine P586
- %idefine END
-
-; This is a magic token which indicates the end of the TASM macros
-*END*TASM*MACROS*
-
-; 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
-; directive should be defined in the module for that directive.
-
-; These two need to be defined, though the actual definitions will
-; be constantly updated during preprocessing.
-%define __FILE__
-%define __LINE__
-
-%define __SECT__ [section .text] ; it ought to be defined, even if as nothing
-
-%imacro section 1+.nolist
-%define __SECT__ [section %1]
- __SECT__
-%endmacro
-%imacro segment 1+.nolist
-%define __SECT__ [segment %1]
- __SECT__
-%endmacro
-
-%imacro absolute 1+.nolist
-%define __SECT__ [absolute %1]
- __SECT__
-%endmacro
-
-%imacro struc 1.nolist
-%push struc
-%define %$strucname %1
-[absolute 0]
-%$strucname: ; allow definition of `.member' to work sanely
-%endmacro
-%imacro endstruc 0.nolist
-%{$strucname}_size:
-%pop
-__SECT__
-%endmacro
-
-%imacro istruc 1.nolist
-%push istruc
-%define %$strucname %1
-%$strucstart:
-%endmacro
-%imacro at 1-2+.nolist
- times %1-($-%$strucstart) db 0
- %2
-%endmacro
-%imacro iend 0.nolist
- times %{$strucname}_size-($-%$strucstart) db 0
-%pop
-%endmacro
-
-%imacro align 1-2+.nolist nop
-%ifidni %2,nop
- [align %1]
-%else
- times ($$-$) & ((%1)-1) %2
-%endif
-%endmacro
-%imacro alignb 1-2+.nolist resb 1
- times ($$-$) & ((%1)-1) %2
-%endmacro
-
-%imacro extern 1-*.nolist
-%rep %0
-[extern %1]
-%rotate 1
-%endrep
-%endmacro
-
-%imacro bits 1+.nolist
-[bits %1]
-%endmacro
-
-%imacro use16 0.nolist
-[bits 16]
-%endmacro
-%imacro use32 0.nolist
-[bits 32]
-%endmacro
-%imacro use64 0.nolist
-[bits 64]
-%endmacro
-
-%imacro global 1-*.nolist
-%rep %0
-[global %1]
-%rotate 1
-%endrep
-%endmacro
-
-%imacro common 1-*.nolist
-%rep %0
-[common %1]
-%rotate 1
-%endrep
-%endmacro
-
-%imacro cpu 1+.nolist
-[cpu %1]
-%endmacro
-
-%imacro default 1+.nolist
-[default %1]
-%endmacro
-
-; NASM compatibility shim
-%define __OUTPUT_FORMAT__ __YASM_OBJFMT__
-
-%ifidn __YASM_OBJFMT__,bin
-%imacro org 1+.nolist
-[org %1]
-%endmacro
-%endif
-
-%ifidn __YASM_OBJFMT__,win32
-%imacro export 1+.nolist
-[export %1]
-%endmacro
-
-%imacro safeseh 1+.nolist
-[safeseh %1]
-%endmacro
-%endif
-
-%ifidn __YASM_OBJFMT__,win64
-%define __YASM_WIN64__
-%endif
-
-%ifidn __YASM_OBJFMT__,x64
-%define __YASM_WIN64__
-%endif
-
-%ifdef __YASM_WIN64__
-%undef __YASM_WIN64__
-
-%imacro export 1+.nolist
-[export %1]
-%endmacro
-
-; Raw exception handling operations
-%imacro proc_frame 1+.nolist
-%1:
-[proc_frame %1]
-%endmacro
-
-%if 0
-; Disable these as they're too closely named to the macroized ones.
-; MASM needs a preceding . to use these, so it seems reasonable for
-; us to similarly require the [].
-%imacro pushreg 1.nolist
-[pushreg %1]
-%endmacro
-
-%imacro setframe 1-2.nolist
-[setframe %1 %2]
-%endmacro
-
-%imacro allocstack 1.nolist
-[allocstack %1]
-%endmacro
-
-%imacro savereg 2.nolist
-[savereg %1 %2]
-%endmacro
-
-%imacro savexmm128 2.nolist
-[savexmm128 %1 %2]
-%endmacro
-
-%imacro pushframe 0-1.nolist
-[pushframe %1]
-%endmacro
-
-%imacro endprolog 0.nolist
-[endprolog]
-%endmacro
-%endif
-
-%imacro endproc_frame 0.nolist
-[endproc_frame]
-%endmacro
-
-; Complex (macro) exception handling operations
-; Mimics many macros provided by MASM's macamd64.inc
-%imacro push_reg 1
-push %1
-[pushreg %1]
-%endmacro
-
-%imacro rex_push_reg 1
-db 0x48
-push %1
-[pushreg %1]
-%endmacro
-
-%imacro push_eflags 0
-pushfq
-[allocstack 8]
-%endmacro
-
-%imacro rex_push_eflags 0
-db 0x48
-pushfq
-[allocstack 8]
-%endmacro
-
-%imacro alloc_stack 1
-sub rsp, %1
-[allocstack %1]
-%endmacro
-
-%imacro save_reg 2
-mov [rsp+%2], %1
-[savereg %1 %2]
-%endmacro
-
-%imacro save_xmm128 2
-movdqa [rsp+%2], %1
-[savexmm128 %1 %2]
-%endmacro
-
-%imacro push_frame 0-1.nolist
-[pushframe %1]
-%endmacro
-
-%imacro set_frame 1-2
-%if %0==1
-mov %1, rsp
-%else
-lea %1, [rsp+%2]
-%endif
-[setframe %1 %2]
-%endmacro
-
-%imacro end_prolog 0.nolist
-[endprolog]
-%endmacro
-
-%imacro end_prologue 0.nolist
-[endprolog]
-%endmacro
-
-%endif
-
-%ifidn __YASM_OBJFMT__,elf
-%define __YASM_ELF__
-%endif
-
-%ifidn __YASM_OBJFMT__,elf32
-%define __YASM_ELF__
-%endif
-
-%ifidn __YASM_OBJFMT__,elf64
-%define __YASM_ELF__
-%endif
-
-%ifdef __YASM_ELF__
-%undef __YASM_ELF__
-%imacro type 1+.nolist
-[type %1]
-%endmacro
-%imacro size 1+.nolist
-[size %1]
-%endmacro
-%imacro weak 1+.nolist
-[weak %1]
-%endmacro
-%endif
-
-%ifidn __YASM_OBJFMT__,rdf
-%imacro library 1+.nolist
-[library %1]
-%endmacro
-%imacro module 1+.nolist
-[module %1]
-%endmacro
-%endif
-
diff --git a/modules/preprocs/nasm/tests/nasmpp-nested.errwarn b/modules/preprocs/nasm/tests/nasmpp-nested.errwarn
index 4df49285..31839e33 100644
--- a/modules/preprocs/nasm/tests/nasmpp-nested.errwarn
+++ b/modules/preprocs/nasm/tests/nasmpp-nested.errwarn
@@ -1,3 +1,3 @@
--:27: warning: (WORK_1:4) 4
--:28: warning: (WORK_2:4) 4
--:29: warning: (DONT_WORK_1:6) 4 4
+-:27: warning: (WORK_1:2) 4
+-:28: warning: (WORK_2:2) 4
+-:29: warning: (DONT_WORK_1:3) 4 4
diff --git a/modules/preprocs/raw/raw-preproc.c b/modules/preprocs/raw/raw-preproc.c
index 03f07559..463ceaa1 100644
--- a/modules/preprocs/raw/raw-preproc.c
+++ b/modules/preprocs/raw/raw-preproc.c
@@ -147,6 +147,12 @@ raw_preproc_define_builtin(yasm_preproc *preproc, const char *macronameval)
/* no builtin defines */
}
+static void
+raw_preproc_add_standard(yasm_preproc *preproc, const char **macros)
+{
+ /* no standard macros */
+}
+
/* Define preproc structure -- see preproc.h for details */
yasm_preproc_module yasm_raw_LTX_preproc = {
@@ -159,5 +165,6 @@ yasm_preproc_module yasm_raw_LTX_preproc = {
raw_preproc_add_include_file,
raw_preproc_predefine_macro,
raw_preproc_undefine_macro,
- raw_preproc_define_builtin
+ raw_preproc_define_builtin,
+ raw_preproc_add_standard
};
diff --git a/modules/preprocs/yapp/yapp-preproc.c b/modules/preprocs/yapp/yapp-preproc.c
index e1215a75..0c774049 100644
--- a/modules/preprocs/yapp/yapp-preproc.c
+++ b/modules/preprocs/yapp/yapp-preproc.c
@@ -999,6 +999,12 @@ yapp_preproc_define_builtin(yasm_preproc *preproc, const char *macronameval)
/* TODO */
}
+static void
+yapp_preproc_add_standard(yasm_preproc *preproc, const char **macros)
+{
+ /* TODO */
+}
+
/* Define preproc structure -- see preproc.h for details */
yasm_preproc_module yasm_yapp_LTX_preproc = {
"YAPP preprocessing (NASM style)",
@@ -1010,5 +1016,6 @@ yasm_preproc_module yasm_yapp_LTX_preproc = {
yapp_preproc_add_include_file,
yapp_preproc_predefine_macro,
yapp_preproc_undefine_macro,
- yapp_preproc_define_builtin
+ yapp_preproc_define_builtin,
+ yapp_preproc_add_standard
};