]> granicus.if.org Git - yasm/commitdiff
Split NASM preprocessor standard macro set between various modules.
authorPeter Johnson <peter@tortall.net>
Fri, 9 May 2008 06:46:02 +0000 (06:46 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 9 May 2008 06:46:02 +0000 (06:46 -0000)
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

34 files changed:
frontends/yasm/yasm.c
libyasm/coretype.h
libyasm/objfmt.h
libyasm/parser.h
libyasm/preproc.h
modules/objfmts/bin/bin-objfmt.c
modules/objfmts/coff/Makefile.inc
modules/objfmts/coff/coff-objfmt.c
modules/objfmts/coff/win64-gas.mac [new file with mode: 0644]
modules/objfmts/coff/win64-nasm.mac [new file with mode: 0644]
modules/objfmts/dbg/dbg-objfmt.c
modules/objfmts/elf/elf-objfmt.c
modules/objfmts/macho/macho-objfmt.c
modules/objfmts/rdf/rdf-objfmt.c
modules/objfmts/win64/tests/Makefile.inc
modules/objfmts/win64/tests/gas/Makefile.inc [new file with mode: 0644]
modules/objfmts/win64/tests/gas/win64-gas-sce.asm [new file with mode: 0644]
modules/objfmts/win64/tests/gas/win64-gas-sce.hex [new file with mode: 0644]
modules/objfmts/win64/tests/gas/win64_gas_test.sh [new file with mode: 0755]
modules/objfmts/xdf/xdf-objfmt.c
modules/parsers/gas/gas-parser.c
modules/parsers/nasm/Makefile.inc
modules/parsers/nasm/nasm-parser.c
modules/parsers/nasm/nasm-std.mac [new file with mode: 0644]
modules/preprocs/cpp/cpp-preproc.c
modules/preprocs/nasm/Makefile.inc
modules/preprocs/nasm/genmacro.c [deleted file]
modules/preprocs/nasm/genversion.c
modules/preprocs/nasm/nasm-pp.c
modules/preprocs/nasm/nasm-preproc.c
modules/preprocs/nasm/standard.mac [deleted file]
modules/preprocs/nasm/tests/nasmpp-nested.errwarn
modules/preprocs/raw/raw-preproc.c
modules/preprocs/yapp/yapp-preproc.c

index 8c24d285aad1be29a40d08a738f14cc8895f6741..b5f470807177f51d98c6bb4a55a93d261bf0bc55 100644 (file)
@@ -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 */
@@ -1125,6 +1132,25 @@ apply_preproc_builtins()
     yasm_xfree(predef);
 }
 
+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()
 {
index 5c99816cdbb02b98f29db19a51541d54874f0ae2..b23e3eae4255c49d0ed1cc6fdcdafcba7ed6e69a 100644 (file)
@@ -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.
  */
index 0c40c4a3cfcd01738e53b695ae97f4d8cf31e0d3..c65e76c115f7e6eab812595df479a8b127c80911 100644 (file)
@@ -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.
index fcbb20c4ca2a8fd6f08b06bbd9320ea73d76a4c8..26c347beb1940fe8e45e5e79d6e740b18adf22db 100644 (file)
@@ -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
index fff40daaf888bb92164700a8015183b500f8be82..0b8c54ff5c53330e2970db789ba6cf923afbe48e 100644 (file)
@@ -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
 
index e108076081c39b0d99efb41aa8ad8f0f567fd763..478502ec1ae05bb14aa3c2a4e0c7d78f1051f7fc 100644 (file)
@@ -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,
index 526f7713ca30dfacbb604c787bfe1989948b82a4..e9e8576d828b00940df9c499d052f92be412cdc3 100644 (file)
@@ -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
index 22ecac45b67b8d43dcf1f617e3f5b7766e92ba55..16cf6ea3d43582cb000bf4f60bee1a53fc38765b 100644 (file)
@@ -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 (file)
index 0000000..cf1e7dc
--- /dev/null
@@ -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 (file)
index 0000000..13954b8
--- /dev/null
@@ -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
index 21a161abfe4bdfc245b5c56b65652a753847ab71..ad5f14a1dc25f996f2f77939b0889023c38361b2 100644 (file)
@@ -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,
index 142275eadb58a5d6f2ff5d3f1c777d344e8c28d0..d2083a842ecbe610f437a159d90af3b3ac4c08e7 100644 (file)
@@ -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,
index 4628bf74ad1912d44dac8a619276c01d7fb5755d..0a049bafd89109a41c44872c26b8219ec40b5012 100644 (file)
@@ -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,
index 22e2a1c7cd20f68bc2a34eb755567730c900f776..e4173289d29ca9edb18e7f4c4c94a176f2e1bf3c 100644 (file)
@@ -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,
index 4bc0907c06febd2caca5d5b52de6a5d64bbb285f..06e0f86d4a8f1dc14a67a39eb61e85c42bfcd2ca 100644 (file)
@@ -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 (file)
index 0000000..0d16bd1
--- /dev/null
@@ -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 (file)
index 0000000..3a75ee4
--- /dev/null
@@ -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 (file)
index 0000000..ff4288f
--- /dev/null
@@ -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 (executable)
index 0000000..5575383
--- /dev/null
@@ -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 $?
index d7cb453b1ed7553261c274402be32e08f1b4e9f5..89cb403c0a6eebf4effc5db0ba182fe967fc9c7f 100644 (file)
@@ -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,
index 1e7fb8b66cdf0720d73aac376653cb0ab3942565..de3397c276f1ef2867c50facc2dacf1d1019e523 100644 (file)
@@ -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
 };
index 9994e316f911e35fd7253afe214dc1916081a178..ac174ca06f7e4f588a8753265ded2df77c5d7022 100644 (file)
@@ -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
index dc46a7170133783d4639c04fb5d5c6faaddc6faf..ac10de377c100becc58ab3f2bd923f2677708338 100644 (file)
@@ -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 (file)
index 0000000..3c9223a
--- /dev/null
@@ -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__
index dae2e032aee35a54bea45d784c1e20b787c829aa..c58e404422e4bdd955f7594446e328446388f923 100644 (file)
@@ -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
 };
index a91eb91419048219c50de27d8280c748a1be4ff9..f9aa9d5ed3d3c75e53ff2765a8aca714d8f5b0d5 100644 (file)
@@ -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 (file)
index e6f4019..0000000
+++ /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;
-}
index 5426c3ddb471a523c6f0afebb490145175877e3b..ac9776854bceea172e692c6558efcad2915873a5 100644 (file)
@@ -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);
index 2bb94b04f4405a0fdc88fbfb750e753230a51a36..2d5e7d2187946fe07e984acb06e119ddbd9689b1 100644 (file)
@@ -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
index a0d941cfdb4a99d6319a2af68823d212dd3ff23a..bb4c7a744ba57000462c8190bfed24580eaa33d1 100644 (file)
@@ -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 (file)
index f459a7d..0000000
+++ /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
-
index 4df492858f2b755e4d5edec0f4e4f1ba95e9d753..31839e33df94059645abb0e710c174876c252c8a 100644 (file)
@@ -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
index 03f07559332083195c641325350fd733d4c1c627..463ceaa1399c260692c59667d084c493eb89bb1f 100644 (file)
@@ -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
 };
index e1215a75796e7cbf294a65c10311a3e503131da8..0c7740498582b18683465d0337d00bf801126249 100644 (file)
@@ -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
 };