]> granicus.if.org Git - yasm/commitdiff
Support use of EQU values within NASM preprocessor.
authorPeter Johnson <peter@tortall.net>
Sat, 3 Nov 2007 04:37:44 +0000 (04:37 -0000)
committerPeter Johnson <peter@tortall.net>
Sat, 3 Nov 2007 04:37:44 +0000 (04:37 -0000)
Note: label values are still not supported, and probably never will be,
as yasm is single-pass parsing, and only reads the source file once.
Someday we may add specific support for relatively common %if-%error
idioms.

svn path=/trunk/yasm/; revision=2008

frontends/yasm/yasm.c
libyasm/preproc.h
modules/preprocs/cpp/cpp-preproc.c
modules/preprocs/nasm/nasm-eval.c
modules/preprocs/nasm/nasm-preproc.c
modules/preprocs/nasm/tests/ifcritical-err.errwarn
modules/preprocs/raw/raw-preproc.c

index b7bfd80c00d0d049fa16228360f350f199620d79..cde5fef80a303bf6b10db7680e3e074ebef3d3f9 100644 (file)
@@ -262,7 +262,7 @@ do_preproc_only(void)
     }
 
     /* Pre-process until done */
-    cur_preproc = yasm_preproc_create(cur_preproc_module, in_filename,
+    cur_preproc = yasm_preproc_create(cur_preproc_module, in_filename, NULL,
                                       linemap, errwarns);
 
     apply_preproc_builtins();
@@ -423,7 +423,7 @@ do_assemble(void)
     }
 
     cur_preproc = yasm_preproc_create(cur_preproc_module, in_filename,
-                                      linemap, errwarns);
+                                      object->symtab, linemap, errwarns);
 
     apply_preproc_builtins();
     apply_preproc_saved_options();
index 0964c0e8a4200fbdb22b0f50cf6590972f3287e3..fff40daaf888bb92164700a8015183b500f8be82 100644 (file)
@@ -58,6 +58,7 @@ typedef struct yasm_preproc_module {
      *
      * \param in_filename       initial starting filename, or "-" to read from
      *                          stdin
+     * \param symtab            symbol table (may be NULL if none)
      * \param lm                line mapping repository
      * \param errwarns          error/warnning set.
      * \return New preprocessor.
@@ -65,6 +66,7 @@ typedef struct yasm_preproc_module {
      * \note Any preprocessor errors and warnings are stored into errwarns.
      */
     /*@only@*/ yasm_preproc * (*create) (const char *in_filename,
+                                         yasm_symtab *symtab,
                                          yasm_linemap *lm,
                                          yasm_errwarns *errwarns);
 
@@ -110,6 +112,7 @@ typedef struct yasm_preproc_module {
  * any output format specific macros.
  * \param module        preprocessor module
  * \param in_filename   initial starting filename, or "-" to read from stdin
+ * \param symtab        symbol table (may be NULL if none)
  * \param lm            line mapping repository
  * \param errwarns      error/warning set
  * \return New preprocessor.
@@ -117,7 +120,7 @@ typedef struct yasm_preproc_module {
  */
 /*@only@*/ yasm_preproc *yasm_preproc_create
     (yasm_preproc_module *module, const char *in_filename,
-     yasm_linemap *lm, yasm_errwarns *errwarns);
+     yasm_symtab *symtab, yasm_linemap *lm, yasm_errwarns *errwarns);
 
 /** Cleans up any allocated preproc memory.
  * \param preproc       preprocessor
@@ -170,8 +173,8 @@ void yasm_preproc_define_builtin(yasm_preproc *preproc,
 
 /* Inline macro implementations for preproc functions */
 
-#define yasm_preproc_create(module, in_filename, lm, ews) \
-    module->create(in_filename, lm, ews)
+#define yasm_preproc_create(module, in_filename, symtab, lm, ews) \
+    module->create(in_filename, symtab, lm, ews)
 
 #define yasm_preproc_destroy(preproc) \
     ((yasm_preproc_base *)preproc)->module->destroy(preproc)
index 77f3107ff06372805c2be8e620e722d9f54e6633..dae2e032aee35a54bea45d784c1e20b787c829aa 100644 (file)
@@ -184,7 +184,8 @@ cpp_generate_deps(yasm_preproc_cpp *pp)
     Interface functions.
 *******************************************************************************/
 static yasm_preproc *
-cpp_preproc_create(const char *in, yasm_linemap *lm, yasm_errwarns *errwarns)
+cpp_preproc_create(const char *in, yasm_symtab *symtab, yasm_linemap *lm,
+                   yasm_errwarns *errwarns)
 {
     yasm_preproc_cpp *pp = yasm_xmalloc(sizeof(yasm_preproc_cpp));
     void * iter;
index c896a1cc335e85262efdd9bfc67c86d78f0e753c..e249484cd5a9f4dbee86f962f2e6a1605cff8173 100644 (file)
 #include <libyasm/coretype.h>
 #include <libyasm/intnum.h>
 #include <libyasm/expr.h>
+#include <libyasm/symrec.h>
 #include <ctype.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
 #include "nasm-eval.h"
 
+/* The assembler symbol table. */
+extern yasm_symtab *nasm_symtab;
+
 static scanner scan;    /* Address of scanner routine */
 static efunc error;     /* Address of error reporting routine */
 
@@ -381,6 +385,21 @@ static yasm_expr *expr6(void)
             e = yasm_expr_create_ident(yasm_expr_int(tokval->t_integer), 0);
             break;
           case TOKEN_ID:
+            if (nasm_symtab) {
+                yasm_symrec *sym =
+                    yasm_symtab_get(nasm_symtab, tokval->t_charptr);
+                if (sym) {
+                    e = yasm_expr_create_ident(yasm_expr_sym(sym), 0);
+                } else {
+                    error(ERR_NONFATAL,
+                          "undefined symbol `%s' in preprocessor",
+                          tokval->t_charptr);
+                    e = yasm_expr_create_ident(yasm_expr_int(
+                        yasm_intnum_create_int(1)), 0);
+                }
+                break;
+            }
+            /*fallthrough*/
           case TOKEN_HERE:
           case TOKEN_BASE:
             error(ERR_NONFATAL,
index c1394a266b34617bcc30cf98f97989ca8ab25f25..a0d941cfdb4a99d6319a2af68823d212dd3ff23a 100644 (file)
@@ -43,6 +43,7 @@ typedef struct yasm_preproc_nasm {
     long prior_linnum;
     int lineinc;
 } yasm_preproc_nasm;
+yasm_symtab *nasm_symtab;
 static yasm_linemap *cur_lm;
 static yasm_errwarns *cur_errwarns;
 int tasm_compatible_mode = 0;
@@ -127,8 +128,8 @@ nasm_efunc(int severity, const char *fmt, ...)
 }
 
 static yasm_preproc *
-nasm_preproc_create(const char *in_filename, yasm_linemap *lm,
-                   yasm_errwarns *errwarns)
+nasm_preproc_create(const char *in_filename, yasm_symtab *symtab,
+                    yasm_linemap *lm, yasm_errwarns *errwarns)
 {
     FILE *f;
     yasm_preproc_nasm *preproc_nasm = yasm_xmalloc(sizeof(yasm_preproc_nasm));
@@ -144,6 +145,7 @@ nasm_preproc_create(const char *in_filename, yasm_linemap *lm,
         f = stdin;
 
     preproc_nasm->in = f;
+    nasm_symtab = symtab;
     cur_lm = lm;
     cur_errwarns = errwarns;
     preproc_deps = NULL;
index 9c617cf7b5084fb394dc9796ba720d5e6f3922cd..55b237a3e71936051958797d09c4f4d651b8a1d8 100644 (file)
@@ -1 +1 @@
--:5: cannot reference symbol `teststringlen' in preprocessor
+-:5: non-constant value given to `%if'
index 87ec4e078988894f4271604fc81759977d566851..03f07559332083195c641325350fd733d4c1c627 100644 (file)
@@ -43,8 +43,8 @@ typedef struct yasm_preproc_raw {
 yasm_preproc_module yasm_raw_LTX_preproc;
 
 static yasm_preproc *
-raw_preproc_create(const char *in_filename, yasm_linemap *lm,
-                   yasm_errwarns *errwarns)
+raw_preproc_create(const char *in_filename, yasm_symtab *symtab,
+                   yasm_linemap *lm, yasm_errwarns *errwarns)
 {
     FILE *f;
     yasm_preproc_raw *preproc_raw = yasm_xmalloc(sizeof(yasm_preproc_raw));