]> granicus.if.org Git - yasm/commitdiff
Add the "real" NASM preprocessor, and default to it. As NASM is LGPL, no
authorPeter Johnson <peter@tortall.net>
Mon, 4 Nov 2002 08:35:35 +0000 (08:35 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 4 Nov 2002 08:35:35 +0000 (08:35 -0000)
licensing issues with this.  All the compiler warnings have been fixed, and
most namespace issues resolved.  However, the integration isn't perfect, and
there are probably memory leaks.  Note that right now the real NASM preproc
and "compatible" NASM parser share a module.  The parser should probably be
renamed to avoid extra loading and code source confusion.

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

30 files changed:
frontends/yasm/Makefile.inc
frontends/yasm/yasm.c
libyasm/Makefile.inc
modules/Makefile.inc
modules/parsers/nasm/Makefile.inc
modules/preprocs/Makefile.inc
modules/preprocs/nasm/Makefile.inc [new file with mode: 0644]
modules/preprocs/nasm/macros.pl
modules/preprocs/nasm/nasm-eval.c
modules/preprocs/nasm/nasm-eval.h
modules/preprocs/nasm/nasm-pp.c
modules/preprocs/nasm/nasm-pp.h
modules/preprocs/nasm/nasm-preproc.c [new file with mode: 0644]
modules/preprocs/nasm/nasm.h
modules/preprocs/nasm/nasmlib.c
modules/preprocs/nasm/nasmlib.h
src/Makefile.inc
src/main.c
src/parsers/nasm/Makefile.inc
src/preprocs/Makefile.inc
src/preprocs/nasm/Makefile.inc [new file with mode: 0644]
src/preprocs/nasm/macros.pl
src/preprocs/nasm/nasm-eval.c
src/preprocs/nasm/nasm-eval.h
src/preprocs/nasm/nasm-pp.c
src/preprocs/nasm/nasm-pp.h
src/preprocs/nasm/nasm-preproc.c [new file with mode: 0644]
src/preprocs/nasm/nasm.h
src/preprocs/nasm/nasmlib.c
src/preprocs/nasm/nasmlib.h

index 27ce27918f4bd50348e2f22c2c18f4dde33eb1c5..1e3134eac4177a81ad06f776f4233a961e53f111 100644 (file)
@@ -58,6 +58,14 @@ EXTRA_DIST += \
        src/objfmts/Makefile.inc        \
        src/tests/Makefile.inc
 
+# Modules with more than one type of interface
+
+lib_LTLIBRARIES += yasm-nasm.la
+yasm_nasm_la_SOURCES =
+yasm_nasm_la_LDFLAGS = -module -avoid-version
+yasm_nasm_la_LIBADD = libyasm.la
+yasm_LDADD += -dlopen yasm-nasm.la
+
 include src/arch/Makefile.inc
 include src/parsers/Makefile.inc
 include src/preprocs/Makefile.inc
index b8689b13ed90b743cd057b25665bad8397e941de..18b01f670bc188ec659961f589c9f170ed149513 100644 (file)
@@ -249,9 +249,9 @@ main(int argc, char *argv[])
            }
        }
 
-       /* If not already specified, default to yapp preproc. */
+       /* If not already specified, default to nasm preproc. */
        if (!cur_preproc)
-           cur_preproc = load_preproc("yapp");
+           cur_preproc = load_preproc("nasm");
 
        if (!cur_preproc) {
            fprintf(stderr, _("Could not load default preprocessor"));
index 27ce27918f4bd50348e2f22c2c18f4dde33eb1c5..1e3134eac4177a81ad06f776f4233a961e53f111 100644 (file)
@@ -58,6 +58,14 @@ EXTRA_DIST += \
        src/objfmts/Makefile.inc        \
        src/tests/Makefile.inc
 
+# Modules with more than one type of interface
+
+lib_LTLIBRARIES += yasm-nasm.la
+yasm_nasm_la_SOURCES =
+yasm_nasm_la_LDFLAGS = -module -avoid-version
+yasm_nasm_la_LIBADD = libyasm.la
+yasm_LDADD += -dlopen yasm-nasm.la
+
 include src/arch/Makefile.inc
 include src/parsers/Makefile.inc
 include src/preprocs/Makefile.inc
index 27ce27918f4bd50348e2f22c2c18f4dde33eb1c5..1e3134eac4177a81ad06f776f4233a961e53f111 100644 (file)
@@ -58,6 +58,14 @@ EXTRA_DIST += \
        src/objfmts/Makefile.inc        \
        src/tests/Makefile.inc
 
+# Modules with more than one type of interface
+
+lib_LTLIBRARIES += yasm-nasm.la
+yasm_nasm_la_SOURCES =
+yasm_nasm_la_LDFLAGS = -module -avoid-version
+yasm_nasm_la_LIBADD = libyasm.la
+yasm_LDADD += -dlopen yasm-nasm.la
+
 include src/arch/Makefile.inc
 include src/parsers/Makefile.inc
 include src/preprocs/Makefile.inc
index 80df154dbeceee650b79afdc07d36fa0fc98fa6f..43ac6c8943f2beceeb13366c4b6f4a61256305d6 100644 (file)
@@ -1,17 +1,17 @@
 # $IdPath$
 
-lib_LTLIBRARIES += yasm-nasm.la
+#lib_LTLIBRARIES += yasm-nasm.la
 
-yasm_nasm_la_SOURCES = \
+yasm_nasm_la_SOURCES += \
        src/parsers/nasm/nasm-parser.h          \
        src/parsers/nasm/nasm-parser.c          \
        src/parsers/nasm/nasm-defs.h            \
        src/parsers/nasm/nasm-bison.y           \
        nasm-bison.h                            \
        nasm-token.c
-yasm_nasm_la_LDFLAGS = -module -avoid-version
-yasm_nasm_la_LIBADD = libyasm.la
-yasm_LDADD += -dlpreopen yasm-nasm.la
+#yasm_nasm_la_LDFLAGS = -module -avoid-version
+#yasm_nasm_la_LIBADD = libyasm.la
+#yasm_LDADD += -dlpreopen yasm-nasm.la
 
 nasm-token.c: $(srcdir)/src/parsers/nasm/nasm-token.re re2c$(EXEEXT) $(srcdir)/tools/re2c/cleanup.pl
        $(top_builddir)/re2c$(EXEEXT) -b $(srcdir)/src/parsers/nasm/nasm-token.re | $(PERL) $(srcdir)/tools/re2c/cleanup.pl | sed "/^#l/ s,re2c-out\.c,$@," > $@
index 0849f3ffce6f10f1802b1f7528d9a85c31305ba5..0fae8c097adbaf62d6cf0c440b209928b06d7b6d 100644 (file)
@@ -1,8 +1,10 @@
 # $IdPath$
 
 EXTRA_DIST += \
+       src/preprocs/nasm/Makefile.inc \
        src/preprocs/raw/Makefile.inc \
        src/preprocs/yapp/Makefile.inc
 
+include src/preprocs/nasm/Makefile.inc
 include src/preprocs/raw/Makefile.inc
 include src/preprocs/yapp/Makefile.inc
diff --git a/modules/preprocs/nasm/Makefile.inc b/modules/preprocs/nasm/Makefile.inc
new file mode 100644 (file)
index 0000000..7df8e5f
--- /dev/null
@@ -0,0 +1,26 @@
+# $IdPath$
+
+#lib_LTLIBRARIES += yasm-nasm.la
+
+yasm_nasm_la_SOURCES += \
+       src/preprocs/nasm/nasm-preproc.c \
+       src/preprocs/nasm/nasm-pp.h \
+       src/preprocs/nasm/nasm-pp.c \
+       src/preprocs/nasm/nasmlib.h \
+       src/preprocs/nasm/nasmlib.c \
+       src/preprocs/nasm/nasm-eval.h \
+       src/preprocs/nasm/nasm-eval.c
+
+src/preprocs/nasm/nasm-pp.c: nasm-macros.c
+
+nasm-macros.c: src/preprocs/nasm/macros.pl src/preprocs/nasm/standard.mac
+       $(PERL) src/preprocs/nasm/macros.pl src/preprocs/nasm/standard.mac
+
+BUILT_SOURCES += nasm-macros.c
+
+EXTRA_DIST += src/preprocs/nasm/macros.pl \
+       src/preprocs/nasm/standard.mac
+
+#yasm_nasm_la_LDFLAGS = -module -avoid-version
+#yasm_nasm_la_LIBADD = libyasm.la
+#yasm_LDADD += -dlopen yasm-nasm.la
index 0934d1741c85bb2b9ddf60c46b4c5cdebb99d188..bb217e15697543996c0b66051720a7af38016e92 100644 (file)
@@ -16,7 +16,7 @@ my $tasm_count;
 
 undef $tasm_count;
 
-open(OUTPUT,">macros.c") or die "unable to open macros.c\n";
+open(OUTPUT,">nasm-macros.c") or die "unable to open nasm-macros.c\n";
     
 print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" .
 " - don't edit it */\n\n#include <stddef.h>\n\nstatic const char *stdmac[] = {\n";
index 28aca642b12ea87d027f7135e8153ee58660c3c5..545f42564a3176dcaefe397adcd322e16e8ba991 100644 (file)
@@ -7,17 +7,13 @@
  *
  * initial version 27/iii/95 by Simon Tatham
  */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
+#include "util.h"
 #include <ctype.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
-#include "eval.h"
-#include "labels.h"
+#include "nasm-eval.h"
+/*#include "labels.h"*/
 
 #define TEMPEXPRS_DELTA 128
 #define TEMPEXPR_DELTA 8
@@ -28,11 +24,11 @@ static lfunc labelfunc;     /* Address of label routine */
 
 static struct ofmt *outfmt;  /* Structure of addresses of output routines */
 
-static expr **tempexprs = NULL;
+static nasm_expr **tempexprs = NULL;
 static int    ntempexprs;
 static int    tempexprs_size = 0;
 
-static expr  *tempexpr;
+static nasm_expr  *tempexpr;
 static int   ntempexpr;
 static int   tempexpr_size;
 
@@ -45,15 +41,15 @@ static int *opflags;
 
 static struct eval_hints *hint;
 
-extern int  in_abs_seg;                /* ABSOLUTE segment flag */
-extern long abs_seg;           /* ABSOLUTE segment */
-extern long abs_offset;                /* ABSOLUTE segment offset */
+static int  in_abs_seg = 0;            /* ABSOLUTE segment flag */
+static long abs_seg = 0;               /* ABSOLUTE segment */
+static long abs_offset = 0;            /* ABSOLUTE segment offset */
 
 /*
  * Unimportant cleanup is done to avoid confusing people who are trying
  * to debug real memory leaks
  */
-void eval_cleanup(void) 
+void nasm_eval_cleanup(void) 
 {
     while (ntempexprs)
        nasm_free (tempexprs[--ntempexprs]);
@@ -80,7 +76,7 @@ static void addtotemp(long type, long value)
     tempexpr[ntempexpr++].value = value;
 }
 
-static expr *finishtemp(void) 
+static nasm_expr *finishtemp(void) 
 {
     addtotemp (0L, 0L);                       /* terminate */
     while (ntempexprs >= tempexprs_size) {
@@ -96,11 +92,11 @@ static expr *finishtemp(void)
  * absolute segment types: we preserve them during addition _only_
  * if one of the segments is a truly pure scalar.
  */
-static expr *add_vectors(expr *p, expr *q) 
+static nasm_expr *add_vectors(nasm_expr *p, nasm_expr *q) 
 {
     int preserve;
 
-    preserve = is_really_simple(p) || is_really_simple(q);
+    preserve = nasm_is_really_simple(p) || nasm_is_really_simple(q);
 
     begintemp();
 
@@ -155,9 +151,9 @@ static expr *add_vectors(expr *p, expr *q)
  * multiplied. This allows [eax*1+ebx] to hint EBX rather than EAX
  * as the base register.
  */
-static expr *scalar_mult(expr *vect, long scalar, int affect_hints) 
+static nasm_expr *scalar_mult(nasm_expr *vect, long scalar, int affect_hints) 
 {
-    expr *p = vect;
+    nasm_expr *p = vect;
 
     while (p->type && p->type < EXPR_SEGBASE+SEG_ABS) {
        p->value = scalar * (p->value);
@@ -171,14 +167,14 @@ static expr *scalar_mult(expr *vect, long scalar, int affect_hints)
     return vect;
 }
 
-static expr *scalarvect (long scalar) 
+static nasm_expr *scalarvect (long scalar) 
 {
     begintemp();
     addtotemp(EXPR_SIMPLE, scalar);
     return finishtemp();
 }
 
-static expr *unknown_expr (void) 
+static nasm_expr *unknown_expr (void) 
 {
     begintemp();
     addtotemp(EXPR_UNKNOWN, 1L);
@@ -190,19 +186,19 @@ static expr *unknown_expr (void)
  * value. Return NULL, as usual, if an error occurs. Report the
  * error too.
  */
-static expr *segment_part (expr *e) 
+static nasm_expr *segment_part (nasm_expr *e) 
 {
     long seg;
 
-    if (is_unknown(e))
+    if (nasm_is_unknown(e))
        return unknown_expr();
 
-    if (!is_reloc(e)) {
+    if (!nasm_is_reloc(e)) {
        error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
        return NULL;
     }
 
-    seg = reloc_seg(e);
+    seg = nasm_reloc_seg(e);
     if (seg == NO_SEG) {
        error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
        return NULL;
@@ -255,16 +251,16 @@ static expr *segment_part (expr *e)
  *       | number
  */
 
-static expr *rexp0(int), *rexp1(int), *rexp2(int), *rexp3(int);
+static nasm_expr *rexp0(int), *rexp1(int), *rexp2(int), *rexp3(int);
 
-static expr *expr0(int), *expr1(int), *expr2(int), *expr3(int);
-static expr *expr4(int), *expr5(int), *expr6(int);
+static nasm_expr *expr0(int), *expr1(int), *expr2(int), *expr3(int);
+static nasm_expr *expr4(int), *expr5(int), *expr6(int);
 
-static expr *(*bexpr)(int);
+static nasm_expr *(*bexpr)(int);
 
-static expr *rexp0(int critical) 
+static nasm_expr *rexp0(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = rexp1(critical);
     if (!e)
@@ -276,24 +272,24 @@ static expr *rexp0(int critical)
        f = rexp1(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`|' operator may only be applied to"
                  " scalar values");
        }
 
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect ((long) (reloc_value(e) || reloc_value(f)));
+           e = scalarvect ((long) (nasm_reloc_value(e) || nasm_reloc_value(f)));
     }
     return e;
 }
 
-static expr *rexp1(int critical) 
+static nasm_expr *rexp1(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = rexp2(critical);
     if (!e)
@@ -305,24 +301,24 @@ static expr *rexp1(int critical)
        f = rexp2(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`^' operator may only be applied to"
                  " scalar values");
        }
 
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect ((long) (!reloc_value(e) ^ !reloc_value(f)));
+           e = scalarvect ((long) (!nasm_reloc_value(e) ^ !nasm_reloc_value(f)));
     }
     return e;
 }
 
-static expr *rexp2(int critical) 
+static nasm_expr *rexp2(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = rexp3(critical);
     if (!e)
@@ -333,23 +329,23 @@ static expr *rexp2(int critical)
        f = rexp3(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`&' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect ((long) (reloc_value(e) && reloc_value(f)));
+           e = scalarvect ((long) (nasm_reloc_value(e) && nasm_reloc_value(f)));
     }
     return e;
 }
 
-static expr *rexp3(int critical) 
+static nasm_expr *rexp3(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
     long v;
 
     e = expr0(critical);
@@ -370,23 +366,23 @@ static expr *rexp3(int critical)
        switch (j) 
        {
          case TOKEN_EQ: case TOKEN_NE:
-           if (is_unknown(e))
+           if (nasm_is_unknown(e))
                v = -1;                /* means unknown */
-           else if (!is_really_simple(e) || reloc_value(e) != 0)
+           else if (!nasm_is_really_simple(e) || nasm_reloc_value(e) != 0)
                v = (j == TOKEN_NE);   /* unequal, so return TRUE if NE */
            else
                v = (j == TOKEN_EQ);   /* equal, so return TRUE if EQ */
            break;
          default:
-           if (is_unknown(e))
+           if (nasm_is_unknown(e))
                v = -1;                /* means unknown */
-           else if (!is_really_simple(e)) {
+           else if (!nasm_is_really_simple(e)) {
                error(ERR_NONFATAL, "`%s': operands differ by a non-scalar",
                      (j == TOKEN_LE ? "<=" : j == TOKEN_LT ? "<" :
                       j == TOKEN_GE ? ">=" : ">"));
                v = 0;                 /* must set it to _something_ */
            } else {
-               int vv = reloc_value(e);
+               int vv = nasm_reloc_value(e);
                if (vv == 0)
                    v = (j == TOKEN_LE || j == TOKEN_GE);
                else if (vv > 0)
@@ -405,9 +401,9 @@ static expr *rexp3(int critical)
     return e;
 }
 
-static expr *expr0(int critical) 
+static nasm_expr *expr0(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr1(critical);
     if (!e)
@@ -419,23 +415,23 @@ static expr *expr0(int critical)
        f = expr1(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`|' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect (reloc_value(e) | reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) | nasm_reloc_value(f));
     }
     return e;
 }
 
-static expr *expr1(int critical) 
+static nasm_expr *expr1(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr2(critical);
     if (!e)
@@ -446,23 +442,23 @@ static expr *expr1(int critical)
        f = expr2(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`^' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect (reloc_value(e) ^ reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) ^ nasm_reloc_value(f));
     }
     return e;
 }
 
-static expr *expr2(int critical) 
+static nasm_expr *expr2(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr3(critical);
     if (!e)
@@ -473,23 +469,23 @@ static expr *expr2(int critical)
        f = expr3(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`&' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect (reloc_value(e) & reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) & nasm_reloc_value(f));
     }
     return e;
 }
 
-static expr *expr3(int critical) 
+static nasm_expr *expr3(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr4(critical);
     if (!e)
@@ -502,29 +498,29 @@ static expr *expr3(int critical)
        f = expr4(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "shift operator may only be applied to"
                  " scalar values");
-       } else if (is_just_unknown(e) || is_just_unknown(f)) {
+       } else if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f)) {
            e = unknown_expr();
        } else switch (j) {
          case TOKEN_SHL:
-           e = scalarvect (reloc_value(e) << reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) << nasm_reloc_value(f));
            break;
          case TOKEN_SHR:
-           e = scalarvect (((unsigned long)reloc_value(e)) >>
-                           reloc_value(f));
+           e = scalarvect (((unsigned long)nasm_reloc_value(e)) >>
+                           nasm_reloc_value(f));
            break;
        }
     }
     return e;
 }
 
-static expr *expr4(int critical) 
+static nasm_expr *expr4(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr5(critical);
     if (!e)
@@ -548,9 +544,9 @@ static expr *expr4(int critical)
     return e;
 }
 
-static expr *expr5(int critical) 
+static nasm_expr *expr5(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr6(critical);
     if (!e)
@@ -563,24 +559,24 @@ static expr *expr5(int critical)
        f = expr6(critical);
        if (!f)
            return NULL;
-       if (j != '*' && (!(is_simple(e) || is_just_unknown(e)) ||
-                        !(is_simple(f) || is_just_unknown(f)))) 
+       if (j != '*' && (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+                        !(nasm_is_simple(f) || nasm_is_just_unknown(f)))) 
        {
            error(ERR_NONFATAL, "division operator may only be applied to"
                  " scalar values");
            return NULL;
        }
-       if (j != '*' && !is_unknown(f) && reloc_value(f) == 0) {
+       if (j != '*' && !nasm_is_unknown(f) && nasm_reloc_value(f) == 0) {
            error(ERR_NONFATAL, "division by zero");
            return NULL;
        }
        switch (j) {
          case '*':
-           if (is_simple(e))
-               e = scalar_mult (f, reloc_value(e), TRUE);
-           else if (is_simple(f))
-               e = scalar_mult (e, reloc_value(f), TRUE);
-           else if (is_just_unknown(e) && is_just_unknown(f))
+           if (nasm_is_simple(e))
+               e = scalar_mult (f, nasm_reloc_value(e), TRUE);
+           else if (nasm_is_simple(f))
+               e = scalar_mult (e, nasm_reloc_value(f), TRUE);
+           else if (nasm_is_just_unknown(e) && nasm_is_just_unknown(f))
                e = unknown_expr();
            else {
                error(ERR_NONFATAL, "unable to multiply two "
@@ -589,42 +585,42 @@ static expr *expr5(int critical)
            }
            break;
          case '/':
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((unsigned long)reloc_value(e)) /
-                               ((unsigned long)reloc_value(f)));
+               e = scalarvect (((unsigned long)nasm_reloc_value(e)) /
+                               ((unsigned long)nasm_reloc_value(f)));
            break;
          case '%':
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((unsigned long)reloc_value(e)) %
-                               ((unsigned long)reloc_value(f)));
+               e = scalarvect (((unsigned long)nasm_reloc_value(e)) %
+                               ((unsigned long)nasm_reloc_value(f)));
            break;
          case TOKEN_SDIV:
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((signed long)reloc_value(e)) /
-                               ((signed long)reloc_value(f)));
+               e = scalarvect (((signed long)nasm_reloc_value(e)) /
+                               ((signed long)nasm_reloc_value(f)));
            break;
          case TOKEN_SMOD:
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((signed long)reloc_value(e)) %
-                               ((signed long)reloc_value(f)));
+               e = scalarvect (((signed long)nasm_reloc_value(e)) %
+                               ((signed long)nasm_reloc_value(f)));
            break;
        }
     }
     return e;
 }
 
-static expr *expr6(int critical) 
+static nasm_expr *expr6(int critical) 
 {
     long type;
-    expr *e;
+    nasm_expr *e;
     long label_seg, label_ofs;
 
     if (i == '-') {
@@ -641,14 +637,14 @@ static expr *expr6(int critical)
        e = expr6(critical);
        if (!e)
            return NULL;
-       if (is_just_unknown(e))
+       if (nasm_is_just_unknown(e))
            return unknown_expr();
-       else if (!is_simple(e)) {
+       else if (!nasm_is_simple(e)) {
            error(ERR_NONFATAL, "`~' operator may only be applied to"
                  " scalar values");
            return NULL;
        }
-       return scalarvect(~reloc_value(e));
+       return scalarvect(~nasm_reloc_value(e));
     } else if (i == TOKEN_SEG) {
        i = scan(scpriv, tokval);
        e = expr6(critical);
@@ -657,7 +653,7 @@ static expr *expr6(int critical)
        e = segment_part(e);
        if (!e)
            return NULL;
-       if (is_unknown(e) && critical) {
+       if (nasm_is_unknown(e) && critical) {
            error(ERR_NONFATAL, "unable to determine segment base");
            return NULL;
        }
@@ -732,8 +728,10 @@ static expr *expr6(int critical)
                    label_ofs = 1;
                }
            }
-               if (opflags && is_extern (tokval->t_charptr))
+#if 0
+               if (opflags && nasm_is_extern (tokval->t_charptr))
                    *opflags |= OPFLAG_EXTERN;
+#endif
            }
            addtotemp(type, label_ofs);
            if (label_seg!=NO_SEG)
@@ -748,19 +746,19 @@ static expr *expr6(int critical)
     }
 }
 
-void eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp) 
+void nasm_eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp) 
 {
     outfmt = output;
     labelfunc = lookup_label;
     location = locp;
 }
 
-expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
+nasm_expr *nasm_evaluate (scanner sc, void *scprivate, struct tokenval *tv,
                int *fwref, int critical, efunc report_error,
                struct eval_hints *hints) 
 {
-    expr *e;
-    expr *f = NULL;
+    nasm_expr *e;
+    nasm_expr *f = NULL;
 
     hint = hints;
     if (hint)
@@ -798,19 +796,19 @@ expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
     }
     e = scalar_mult (e, 1L, FALSE);    /* strip far-absolute segment part */
     if (f) {
-       expr *g;
-       if (is_just_unknown(f))
+       nasm_expr *g;
+       if (nasm_is_just_unknown(f))
            g = unknown_expr();
        else {
            long value;
            begintemp();
-           if (!is_reloc(f)) {
+           if (!nasm_is_reloc(f)) {
                error(ERR_NONFATAL, "invalid right-hand operand to WRT");
                return NULL;
            }
-           value = reloc_seg(f);
+           value = nasm_reloc_seg(f);
            if (value == NO_SEG)
-               value = reloc_value(f) | SEG_ABS;
+               value = nasm_reloc_value(f) | SEG_ABS;
            else if (!(value & SEG_ABS) && !(value % 2) && critical) 
            {
                error(ERR_NONFATAL, "invalid right-hand operand to WRT");
index a933cbfd0a69dd3022fc16d8165a91e03ec2e9fe..92495937bf93882928232d2016d40d0d0e0cd7a1 100644 (file)
  * providing segment-base details, and what function can be used to
  * look labels up.
  */
-void eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp);
+void nasm_eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp);
 
 /*
  * The evaluator itself.
  */
-expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
+nasm_expr *nasm_evaluate (scanner sc, void *scprivate, struct tokenval *tv,
                int *fwref, int critical, efunc report_error,
                struct eval_hints *hints);
 
-void eval_cleanup(void);
+void nasm_eval_cleanup(void);
 
 #endif
index 0770812ed5285e21256c1c8f85f024e77f0e7b47..8b7278b10d2be59c13cd1d0102c2c53f4bf3dd01 100644 (file)
  *
  * detoken is used to convert the line back to text
  */
-
-#include <stdio.h>
+#include "util.h"
 #include <stdarg.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
 #include <ctype.h>
 #include <limits.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
+#include "nasm-pp.h"
 
 typedef struct SMacro SMacro;
 typedef struct MMacro MMacro;
@@ -343,7 +340,7 @@ static const char *tasm_directives[] = {
 };
 
 static int StackSize = 4;
-static char *StackPointer = "ebp";
+static const char *StackPointer = "ebp";
 static int ArgOffset = 8;
 static int LocalOffset = 4;
 
@@ -395,7 +392,7 @@ static MMacro *defining;
  * The standard macro set: defined as `static char *stdmac[]'. Also
  * gives our position in the macro set, when we're processing it.
  */
-#include "macros.c"
+#include "nasm-macros.c"
 static const char **stdmacpos;
 
 /*
@@ -428,7 +425,7 @@ static void make_tok_num(Token * tok, long val);
 static void error(int severity, const char *fmt, ...);
 static void *new_Block(size_t size);
 static void delete_Blocks(void);
-static Token *new_Token(Token * next, int type, char *text, int txtlen);
+static Token *new_Token(Token * next, int type, const char *text, int txtlen);
 static Token *delete_Token(Token * t);
 
 /*
@@ -571,11 +568,11 @@ hash(char *s)
  * Free a linked list of tokens.
  */
 static void
-free_tlist(Token * list)
+free_tlist(Token * list_)
 {
-    while (list)
+    while (list_)
     {
-       list = delete_Token(list);
+       list_ = delete_Token(list_);
     }
 }
 
@@ -583,13 +580,13 @@ free_tlist(Token * list)
  * Free a linked list of lines.
  */
 static void
-free_llist(Line * list)
+free_llist(Line * list_)
 {
     Line *l;
-    while (list)
+    while (list_)
     {
-       l = list;
-       list = list->next;
+       l = list_;
+       list_ = list_->next;
        free_tlist(l->first);
        nasm_free(l);
     }
@@ -735,7 +732,7 @@ read_line(void)
        return NULL;
     }
 
-    src_set_linnum(src_get_linnum() + istk->lineinc + (continued_count * istk->lineinc));
+    nasm_src_set_linnum(nasm_src_get_linnum() + istk->lineinc + (continued_count * istk->lineinc));
 
     /*
      * Play safe: remove CRs as well as LFs, if any of either are
@@ -765,8 +762,8 @@ tokenise(char *line)
 {
     char *p = line;
     int type;
-    Token *list = NULL;
-    Token *t, **tail = &list;
+    Token *list_ = NULL;
+    Token *t, **tail = &list_;
 
     while (*line)
     {
@@ -908,7 +905,7 @@ tokenise(char *line)
        }
        line = p;
     }
-    return list;
+    return list_;
 }
 
 /*
@@ -965,7 +962,7 @@ delete_Blocks(void)
  *  also the mac and next elements to NULL.
  */
 static Token *
-new_Token(Token * next, int type, char *text, int txtlen)
+new_Token(Token * next, int type, const char *text, int txtlen)
 {
     Token *t;
     int i;
@@ -1024,10 +1021,10 @@ detoken(Token * tlist, int expand_locals)
     {
        if (t->type == TOK_PREPROC_ID && t->text[1] == '!')
        {
-           char *p = getenv(t->text + 2);
+           char *p2 = getenv(t->text + 2);
            nasm_free(t->text);
-           if (p)
-               t->text = nasm_strdup(p);
+           if (p2)
+               t->text = nasm_strdup(p2);
            else
                t->text = NULL;
        }
@@ -1040,13 +1037,13 @@ detoken(Token * tlist, int expand_locals)
            if (ctx)
            {
                char buffer[40];
-               char *p, *q = t->text + 2;
+               char *p2, *q = t->text + 2;
 
                q += strspn(q, "$");
                sprintf(buffer, "..@%lu.", ctx->number);
-               p = nasm_strcat(buffer, q);
+               p2 = nasm_strcat(buffer, q);
                nasm_free(t->text);
-               t->text = p;
+               t->text = p2;
            }
        }
        if (t->type == TOK_WHITESPACE)
@@ -1128,7 +1125,7 @@ ppscan(void *private_data, struct tokenval *tokval)
     {
        int rn_error;
 
-       tokval->t_integer = readnum(tline->text, &rn_error);
+       tokval->t_integer = nasm_readnum(tline->text, &rn_error);
        if (rn_error)
            return tokval->t_type = TOKEN_ERRNUM;
        tokval->t_charptr = NULL;
@@ -1147,7 +1144,7 @@ ppscan(void *private_data, struct tokenval *tokval)
 
        if (l == 0 || r[l - 1] != q)
            return tokval->t_type = TOKEN_ERRNUM;
-       tokval->t_integer = readstrnum(r, l - 1, &rn_warn);
+       tokval->t_integer = nasm_readstrnum(r, l - 1, &rn_warn);
        if (rn_warn)
            error(ERR_WARNING | ERR_PASS1, "character constant too long");
        tokval->t_charptr = NULL;
@@ -1281,7 +1278,8 @@ static FILE *
 inc_fopen(char *file)
 {
     FILE *fp;
-    char *prefix = "", *combine;
+    const char *prefix = "";
+    char *combine;
     IncPath *ip = ipath;
     static int namelen = 0;
     int len = strlen(file);
@@ -1440,7 +1438,7 @@ if_condition(Token * tline, int i)
     int j, casesense;
     Token *t, *tt, **tptr, *origline;
     struct tokenval tokval;
-    expr *evalresult;
+    nasm_expr *evalresult;
 
     origline = tline;
 
@@ -1601,7 +1599,7 @@ if_condition(Token * tline, int i)
            else
            {
                searching.nparam_min = searching.nparam_max =
-                       readnum(tline->text, &j);
+                       nasm_readnum(tline->text, &j);
                if (j)
                    error(ERR_NONFATAL,
                          "unable to parse parameter count `%s'",
@@ -1618,7 +1616,7 @@ if_condition(Token * tline, int i)
                          directives[i]);
                else
                {
-                   searching.nparam_max = readnum(tline->text, &j);
+                   searching.nparam_max = nasm_readnum(tline->text, &j);
                    if (j)
                        error(ERR_NONFATAL,
                                "unable to parse parameter count `%s'",
@@ -1713,13 +1711,13 @@ if_condition(Token * tline, int i)
            if (tokval.t_type)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL,
                        "non-constant value given to `%s'", directives[i]);
                return -1;
            }
-           return reloc_value(evalresult) != 0;
+           return nasm_reloc_value(evalresult) != 0;
 
        default:
            error(ERR_FATAL,
@@ -1735,7 +1733,7 @@ if_condition(Token * tline, int i)
  * First tokenise the string, apply "expand_smacro" and then de-tokenise back.
  * The returned variable should ALWAYS be freed after usage.
  */
-void
+static void
 expand_macros_in_string(char **p)
 {
     Token *line = tokenise(*p);
@@ -1769,7 +1767,7 @@ do_directive(Token * tline)
     Token *t, *tt, *param_start, *macro_start, *last, **tptr, *origline;
     Line *l;
     struct tokenval tokval;
-    expr *evalresult;
+    nasm_expr *evalresult;
     MMacro *tmp_defining;      /* Used when manipulating rep_nest */
 
     origline = tline;
@@ -2095,9 +2093,9 @@ do_directive(Token * tline)
            {
                while (mmacros[j])
                {
-                   MMacro *m = mmacros[j];
-                   mmacros[j] = m->next;
-                   free_mmacro(m);
+                   MMacro *m2 = mmacros[j];
+                   mmacros[j] = m2->next;
+                   free_mmacro(m2);
                }
                while (smacros[j])
                {
@@ -2136,8 +2134,8 @@ do_directive(Token * tline)
            inc->next = istk;
            inc->conds = NULL;
            inc->fp = inc_fopen(p);
-           inc->fname = src_set_fname(p);
-           inc->lineno = src_set_linnum(0);
+           inc->fname = nasm_src_set_fname(p);
+           inc->lineno = nasm_src_set_linnum(0);
            inc->lineinc = 1;
            inc->expansion = NULL;
            inc->mstk = NULL;
@@ -2353,7 +2351,7 @@ do_directive(Token * tline)
            else
            {
                defining->nparam_min = defining->nparam_max =
-                       readnum(tline->text, &j);
+                       nasm_readnum(tline->text, &j);
                if (j)
                    error(ERR_NONFATAL,
                            "unable to parse parameter count `%s'",
@@ -2370,7 +2368,7 @@ do_directive(Token * tline)
                            (i == PP_IMACRO ? "i" : ""));
                else
                {
-                   defining->nparam_max = readnum(tline->text, &j);
+                   defining->nparam_max = nasm_readnum(tline->text, &j);
                    if (j)
                        error(ERR_NONFATAL,
                                "unable to parse parameter count `%s'",
@@ -2464,7 +2462,7 @@ do_directive(Token * tline)
            if (tokval.t_type)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL, "non-constant value given to `%%rotate'");
                return DIRECTIVE_FOUND;
@@ -2484,7 +2482,7 @@ do_directive(Token * tline)
            }
            else
            {
-               mmac->rotate = mmac->rotate + reloc_value(evalresult);
+               mmac->rotate = mmac->rotate + nasm_reloc_value(evalresult);
                
                if (mmac->rotate < 0)
                    mmac->rotate = 
@@ -2518,7 +2516,7 @@ do_directive(Token * tline)
            if (tokval.t_type)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL, "non-constant value given to `%%rep'");
                return DIRECTIVE_FOUND;
@@ -2529,7 +2527,7 @@ do_directive(Token * tline)
            defining->casesense = 0;
            defining->plus = FALSE;
            defining->nolist = nolist;
-           defining->in_progress = reloc_value(evalresult) + 1;
+           defining->in_progress = nasm_reloc_value(evalresult) + 1;
            defining->nparam_min = defining->nparam_max = 0;
            defining->defaults = NULL;
            defining->dlist = NULL;
@@ -2901,7 +2899,7 @@ do_directive(Token * tline)
                free_tlist(origline);
                return DIRECTIVE_FOUND;
            }
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL, "non-constant value given to `%%substr`");
                free_tlist(tline);
@@ -3003,7 +3001,7 @@ do_directive(Token * tline)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
 
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL,
                        "non-constant value given to `%%%sassign'",
@@ -3014,7 +3012,7 @@ do_directive(Token * tline)
 
            macro_start = nasm_malloc(sizeof(*macro_start));
            macro_start->next = NULL;
-           make_tok_num(macro_start, reloc_value(evalresult));
+           make_tok_num(macro_start, nasm_reloc_value(evalresult));
            macro_start->mac = NULL;
 
            /*
@@ -3065,7 +3063,7 @@ do_directive(Token * tline)
                free_tlist(origline);
                return DIRECTIVE_FOUND;
            }
-           k = readnum(tline->text, &j);
+           k = nasm_readnum(tline->text, &j);
            m = 1;
            tline = tline->next;
            if (tok_is_(tline, "+"))
@@ -3077,15 +3075,15 @@ do_directive(Token * tline)
                    free_tlist(origline);
                    return DIRECTIVE_FOUND;
                }
-               m = readnum(tline->text, &j);
+               m = nasm_readnum(tline->text, &j);
                tline = tline->next;
            }
            skip_white_(tline);
-           src_set_linnum(k);
+           nasm_src_set_linnum(k);
            istk->lineinc = m;
            if (tline)
            {
-               nasm_free(src_set_fname(detoken(tline, FALSE)));
+               nasm_free(nasm_src_set_fname(detoken(tline, FALSE)));
            }
            free_tlist(origline);
            return DIRECTIVE_FOUND;
@@ -3409,7 +3407,7 @@ expand_smacro(Token * tline)
                        if (!strcmp("__FILE__", m->name))
                        {
                            long num = 0;
-                           src_get(&num, &(tline->text));
+                           nasm_src_get(&num, &(tline->text));
                            nasm_quote(&(tline->text));
                            tline->type = TOK_STRING;
                            continue;
@@ -3417,7 +3415,7 @@ expand_smacro(Token * tline)
                        if (!strcmp("__LINE__", m->name))
                        {
                            nasm_free(tline->text);
-                           make_tok_num(tline, src_get_linnum());
+                           make_tok_num(tline, nasm_src_get_linnum());
                            continue;
                        }
                        tline = delete_Token(tline);
@@ -4058,7 +4056,7 @@ error(int severity, const char *fmt, ...)
 }
 
 static void
-pp_reset(char *file, int apass, efunc errfunc, evalfunc eval,
+pp_reset(FILE *f, const char *file, int apass, efunc errfunc, evalfunc eval,
        ListGen * listgen)
 {
     int h;
@@ -4070,13 +4068,11 @@ pp_reset(char *file, int apass, efunc errfunc, evalfunc eval,
     istk->conds = NULL;
     istk->expansion = NULL;
     istk->mstk = NULL;
-    istk->fp = fopen(file, "r");
+    istk->fp = f;
     istk->fname = NULL;
-    src_set_fname(nasm_strdup(file));
-    src_set_linnum(0);
+    nasm_src_set_fname(nasm_strdup(file));
+    nasm_src_set_linnum(0);
     istk->lineinc = 1;
-    if (!istk->fp)
-       error(ERR_FATAL | ERR_NOFILE, "unable to open input file `%s'", file);
     defining = NULL;
     for (h = 0; h < NHASH; h++)
     {
@@ -4232,8 +4228,8 @@ pp_getline(void)
                /* only set line and file name if there's a next node */
                if (i->next) 
                {
-                   src_set_linnum(i->lineno);
-                   nasm_free(src_set_fname(i->fname));
+                   nasm_src_set_linnum(i->lineno);
+                   nasm_free(nasm_src_set_fname(i->fname));
                }
                istk = i->next;
                list->downlevel(LIST_INCLUDE);
@@ -4324,7 +4320,7 @@ pp_getline(void)
 }
 
 static void
-pp_cleanup(int pass)
+pp_cleanup(int pass_)
 {
     int h;
 
@@ -4363,7 +4359,7 @@ pp_cleanup(int pass)
     }
     while (cstk)
        ctx_pop();
-    if (pass == 0)
+    if (pass_ == 0)
        {
                free_llist(predef);
                delete_Blocks();
index 0b7df114e62db8b67438e776cd186aad415e1a4d..82a1569c049bc250b3950c817eae741916dfb9f5 100644 (file)
@@ -6,8 +6,8 @@
  * distributed in the NASM archive.
  */
 
-#ifndef NASM_PREPROC_H
-#define NASM_PREPROC_H
+#ifndef YASM_NASM_PREPROC_H
+#define YASM_NASM_PREPROC_H
 
 void pp_include_path (char *);
 void pp_pre_include (char *);
diff --git a/modules/preprocs/nasm/nasm-preproc.c b/modules/preprocs/nasm/nasm-preproc.c
new file mode 100644 (file)
index 0000000..38c2aea
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Imported NASM preprocessor - glue code
+ *
+ *  Copyright (C) 2002  Peter Johnson
+ *
+ *  This file is part of YASM.
+ *
+ *  YASM is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  YASM is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include "util.h"
+/*@unused@*/ RCSID("$IdPath$");
+
+#include "errwarn.h"
+#include "linemgr.h"
+
+#include "preproc.h"
+#include "nasm.h"
+#include "nasmlib.h"
+#include "nasm-pp.h"
+#include "nasm-eval.h"
+
+static FILE *in;
+static linemgr *cur_lm;
+static errwarn *cur_we;
+static char *line, *linepos;
+static size_t lineleft;
+static char *file_name;
+static long prior_linnum;
+static int lineinc;
+int tasm_compatible_mode = 0;
+
+
+static void
+nil_listgen_init(char *p, efunc e)
+{
+}
+
+static void
+nil_listgen_cleanup(void)
+{
+}
+
+static void
+nil_listgen_output(long v, const void *d, unsigned long v2)
+{
+}
+
+static void
+nil_listgen_line(int v, char *p)
+{
+}
+
+static void
+nil_listgen_uplevel(int v)
+{
+}
+
+static void
+nil_listgen_downlevel(int v)
+{
+}
+
+static ListGen nil_list = {
+    nil_listgen_init,
+    nil_listgen_cleanup,
+    nil_listgen_output,
+    nil_listgen_line,
+    nil_listgen_uplevel,
+    nil_listgen_downlevel
+};
+
+
+static void
+nasm_efunc(int severity, const char *fmt, ...)
+{
+    va_list va;
+
+    va_start(va, fmt);
+    switch (severity & ERR_MASK) {
+       case ERR_WARNING:
+           cur_we->warning_va(WARN_PREPROC, cur_lm->get_current(), fmt, va);
+           break;
+       case ERR_NONFATAL:
+           cur_we->error_va(cur_lm->get_current(), fmt, va);
+           break;
+       case ERR_FATAL:
+           cur_we->fatal(FATAL_UNKNOWN);   /* FIXME */
+           break;
+       case ERR_PANIC:
+           cur_we->internal_error(fmt);    /* FIXME */
+           break;
+       case ERR_DEBUG:
+           break;
+    }
+    va_end(va);
+}
+
+static void
+nasm_preproc_initialize(FILE *f, const char *in_filename, linemgr *lm,
+                       errwarn *we)
+{
+    in = f;
+    cur_lm = lm;
+    cur_we = we;
+    line = NULL;
+    file_name = NULL;
+    prior_linnum = 0;
+    lineinc = 0;
+    nasmpp.reset(f, in_filename, 2, nasm_efunc, nasm_evaluate, &nil_list);
+}
+
+static void
+nasm_preproc_cleanup(void)
+{
+    nasmpp.cleanup(0);
+}
+
+static size_t
+nasm_preproc_input(char *buf, size_t max_size)
+{
+    size_t tot = 0, n;
+    long linnum = prior_linnum += lineinc;
+    int altline;
+
+    if (!line) {
+       line = nasmpp.getline();
+       if (!line)
+           return 0;
+       linepos = line;
+       lineleft = strlen(line) + 1;
+       line[lineleft-1] = '\n';
+    }
+
+    altline = nasm_src_get(&linnum, &file_name);
+    if (altline) {
+       if (altline == 1 && lineinc == 1) {
+           *buf++ = '\n';
+           max_size--;
+           tot++;
+       } else {
+           lineinc = (altline != -1 || lineinc != 1);
+           n = sprintf(buf, "%%line %ld+%d %s\n", linnum, lineinc, file_name);
+           buf += n;
+           max_size -= n;
+           tot += n;
+       }
+       prior_linnum = linnum;
+    }
+
+    n = lineleft<max_size?lineleft:max_size;
+    strncpy(buf, linepos, n);
+    tot += n;
+
+    if (n == lineleft) {
+       xfree(line);
+       line = NULL;
+    } else {
+       lineleft -= n;
+       linepos += n;
+    }
+
+    return tot;
+}
+
+
+/* Define preproc structure -- see preproc.h for details */
+preproc yasm_nasm_LTX_preproc = {
+    "Real NASM Preprocessor",
+    "nasm",
+    nasm_preproc_initialize,
+    nasm_preproc_cleanup,
+    nasm_preproc_input
+};
index 8f4f293c562401b3724775ea1315a34b4840bfb2..890991b9785f53144cb1c6bf85da0c3196aa7785 100644 (file)
@@ -7,12 +7,8 @@
  *
  * initial version: 27/iii/95 by Simon Tatham
  */
-
-#ifndef NASM_NASM_H
-#define NASM_NASM_H
-
-#include <stdio.h>
-#include "version.h"                  /* generated NASM version macros */
+#ifndef YASM_NASM_H
+#define YASM_NASM_H
 
 #ifndef NULL
 #define NULL 0
@@ -237,7 +233,7 @@ typedef struct {
 typedef struct {
     long type;                        /* a register, or EXPR_xxx */
     long value;                               /* must be >= 32 bits */
-} expr;
+} nasm_expr;
 
 /*
  * The evaluator can also return hints about which of two registers
@@ -274,7 +270,7 @@ struct eval_hints {
  * the base register in complex effective addresses.
  */
 #define CRITICAL 0x100
-typedef expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv,
+typedef nasm_expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv,
                           int *fwref, int critical, efunc error,
                           struct eval_hints *hints);
 
@@ -300,7 +296,7 @@ typedef struct {
      * of the pass, an error reporting function, an evaluator
      * function, and a listing generator to talk to.
      */
-    void (*reset) (char *, int, efunc, evalfunc, ListGen *);
+    void (*reset) (FILE *, const char *, int, efunc, evalfunc, ListGen *);
 
     /*
      * Called to fetch a line of preprocessed source. The line
@@ -429,16 +425,17 @@ enum {
 #define UNITY     0x00802000L         /* for shift/rotate instructions */
 #define BYTENESS  0x40000000L          /* so SBYTE == IMMEDIATE | BYTENESS */
 #define SBYTE    0x40002000L          /* for op r16/32,immediate instrs. */
-               
+       
+
 /* Register names automatically generated from regs.dat */
-#include "regs.h"
+/*#include "regs.h"*/
 
 enum {                                /* condition code names */
     C_A, C_AE, C_B, C_BE, C_C, C_E, C_G, C_GE, C_L, C_LE, C_NA, C_NAE,
     C_NB, C_NBE, C_NC, C_NE, C_NG, C_NGE, C_NL, C_NLE, C_NO, C_NP,
     C_NS, C_NZ, C_O, C_P, C_PE, C_PO, C_S, C_Z
 };
-
+#if 0
 /*
  * Note that because segment registers may be used as instruction
  * prefixes, we must ensure the enumerations for prefixes and
@@ -449,7 +446,7 @@ enum {                                     /* instruction prefixes */
     P_A16 = PREFIX_ENUM_START, P_A32, P_LOCK, P_O16, P_O32, P_REP, P_REPE,
     P_REPNE, P_REPNZ, P_REPZ, P_TIMES
 };
-
+#endif
 enum {                                /* extended operand types */
     EOT_NOTHING, EOT_DB_STRING, EOT_DB_NUMBER
 };
index bb0ab29e0e14dabc93569c5f3519e6dfd6da4f47..5eb2be1a7500c62d6c4a0f1c3376372dad7f5f94 100644 (file)
  * redistributable under the licence given in the file "Licence"
  * distributed in the NASM archive.
  */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "util.h"
 #include <ctype.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
-#include "insns.h"             /* For MAX_KEYWORD */
-
-static efunc nasm_malloc_error;
-
-#ifdef LOGALLOC
-static FILE *logfp;
-#endif
-
-void nasm_set_malloc_error (efunc error) 
-{
-    nasm_malloc_error = error;
-#ifdef LOGALLOC
-    logfp = fopen ("malloc.log", "w");
-    setvbuf (logfp, NULL, _IOLBF, BUFSIZ);
-    fprintf (logfp, "null pointer is %p\n", NULL);
-#endif
-}
-
-#ifdef LOGALLOC
-void *nasm_malloc_log (char *file, int line, size_t size)
-#else
-void *nasm_malloc (size_t size)
-#endif
-{
-    void *p = malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else
-       fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    return p;
-}
-
-#ifdef LOGALLOC
-void *nasm_realloc_log (char *file, int line, void *q, size_t size)
-#else
-void *nasm_realloc (void *q, size_t size)
-#endif
-{
-    void *p = q ? realloc(q, size) : malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else if (q)
-       fprintf(logfp, "%s %d realloc(%p,%ld) returns %p\n",
-               file, line, q, (long)size, p);
-    else
-       fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    return p;
-}
-
-#ifdef LOGALLOC
-void nasm_free_log (char *file, int line, void *q)
-#else
-void nasm_free (void *q)
-#endif
-{
-    if (q) {
-       free (q);
-#ifdef LOGALLOC
-       fprintf(logfp, "%s %d free(%p)\n",
-               file, line, q);
-#endif
-    }
-}
-
-#ifdef LOGALLOC
-char *nasm_strdup_log (char *file, int line, const char *s)
-#else
-char *nasm_strdup (const char *s)
-#endif
-{
-    char *p;
-    int size = strlen(s)+1;
-
-    p = malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else
-       fprintf(logfp, "%s %d strdup(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    strcpy (p, s);
-    return p;
-}
-
-#ifdef LOGALLOC
-char *nasm_strndup_log (char *file, int line, char *s, size_t len)
-#else
-char *nasm_strndup (char *s, size_t len)
-#endif
-{
-    char *p;
-    int size = len+1;
-
-    p = malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else
-       fprintf(logfp, "%s %d strndup(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    strncpy (p, s, len);
-    p[len] = '\0';
-    return p;
-}
-
-#if !defined(stricmp) && !defined(strcasecmp)
-int nasm_stricmp (const char *s1, const char *s2) 
-{
-    while (*s1 && tolower(*s1) == tolower(*s2))
-       s1++, s2++;
-    if (!*s1 && !*s2)
-       return 0;
-    else if (tolower(*s1) < tolower(*s2))
-       return -1;
-    else
-       return 1;
-}
-#endif
-
-#if !defined(strnicmp) && !defined(strncasecmp)
-int nasm_strnicmp (const char *s1, const char *s2, int n) 
-{
-    while (n > 0 && *s1 && tolower(*s1) == tolower(*s2))
-       s1++, s2++, n--;
-    if ((!*s1 && !*s2) || n==0)
-       return 0;
-    else if (tolower(*s1) < tolower(*s2))
-       return -1;
-    else
-       return 1;
-}
-#endif
+/*#include "insns.h"*/         /* For MAX_KEYWORD */
 
 #define lib_isnumchar(c)   ( isalnum(c) || (c) == '$')
 #define numvalue(c)  ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
 
-long readnum (char *str, int *error) 
+long nasm_readnum (char *str, int *error) 
 {
     char *r = str, *q;
     long radix;
@@ -243,16 +101,16 @@ long readnum (char *str, int *error)
        result = radix * result + digit;
        r++;
     }
-
+#if 0
     if (warn)
        nasm_malloc_error (ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
                           "numeric constant %s does not fit in 32 bits",
                           str);
-
+#endif
     return result*sign;
 }
 
-long readstrnum (char *str, int length, int *warn) 
+long nasm_readstrnum (char *str, int length, int *warn) 
 {
     long charconst = 0;
     int i;
@@ -271,603 +129,21 @@ long readstrnum (char *str, int length, int *warn)
 
 static long next_seg;
 
-void seg_init(void) 
+void nasm_seg_init(void) 
 {
     next_seg = 0;
 }
 
-long seg_alloc(void) 
+long nasm_seg_alloc(void) 
 {
     return (next_seg += 2) - 2;
 }
 
-void fwriteshort (int data, FILE *fp) 
-{
-    fputc ((int) (data & 255), fp);
-    fputc ((int) ((data >> 8) & 255), fp);
-}
-
-void fwritelong (long data, FILE *fp) 
-{
-    fputc ((int) (data & 255), fp);
-    fputc ((int) ((data >> 8) & 255), fp);
-    fputc ((int) ((data >> 16) & 255), fp);
-    fputc ((int) ((data >> 24) & 255), fp);
-}
-
-void standard_extension (char *inname, char *outname, char *extension,
-                        efunc error) 
-{
-    char *p, *q;
-
-    if (*outname)                     /* file name already exists, */
-       return;                        /* so do nothing */
-    q = inname;
-    p = outname;
-    while (*q) *p++ = *q++;           /* copy, and find end of string */
-    *p = '\0';                        /* terminate it */
-    while (p > outname && *--p != '.');/* find final period (or whatever) */
-    if (*p != '.') while (*p) p++;     /* go back to end if none found */
-    if (!strcmp(p, extension)) {       /* is the extension already there? */
-       if (*extension)
-           error(ERR_WARNING | ERR_NOFILE,
-                 "file name already ends in `%s': "
-                 "output will be in `nasm.out'",
-                 extension);
-       else
-           error(ERR_WARNING | ERR_NOFILE,
-                 "file name already has no extension: "
-                 "output will be in `nasm.out'");
-       strcpy(outname, "nasm.out");
-    } else
-       strcpy(p, extension);
-}
-
-#define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
-#define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
-
-#define LAYERSIZ(r) ( (r)->layers==0 ? RAA_BLKSIZE : RAA_LAYERSIZE )
-
-static struct RAA *real_raa_init (int layers) 
-{
-    struct RAA *r;
-    int i;
-
-    if (layers == 0) {
-       r = nasm_malloc (LEAFSIZ);
-       r->layers = 0;
-       memset (r->u.l.data, 0, sizeof(r->u.l.data));
-       r->stepsize = 1L;
-    } else {
-       r = nasm_malloc (BRANCHSIZ);
-       r->layers = layers;
-       for ( i = 0 ; i < RAA_LAYERSIZE ; i++ )
-         r->u.b.data[i] = NULL;
-       r->stepsize = RAA_BLKSIZE;
-       while (--layers)
-           r->stepsize *= RAA_LAYERSIZE;
-    }
-    return r;
-}
-
-struct RAA *raa_init (void) 
-{
-    return real_raa_init (0);
-}
-
-void raa_free (struct RAA *r) 
-{
-    if (r->layers == 0)
-       nasm_free (r);
-    else {
-       struct RAA **p;
-       for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++)
-           if (*p)
-               raa_free (*p);
-    }
-}
-
-long raa_read (struct RAA *r, long posn) 
-{
-    if (posn >= r->stepsize * LAYERSIZ(r))
-       return 0;               /* Return 0 for undefined entries */
-    while (r->layers > 0) {
-       ldiv_t l;
-       l = ldiv (posn, r->stepsize);
-       r = r->u.b.data[l.quot];
-       posn = l.rem;
-       if (!r)
-           return 0;           /* Return 0 for undefined entries */
-    }
-    return r->u.l.data[posn];
-}
-
-struct RAA *raa_write (struct RAA *r, long posn, long value) 
-{
-    struct RAA *result;
-
-    if (posn < 0)
-       nasm_malloc_error (ERR_PANIC, "negative position in raa_write");
-
-    while (r->stepsize * LAYERSIZ(r) <= posn) {
-       /*
-        * Must add a layer.
-        */
-       struct RAA *s;
-       int i;
-
-       s = nasm_malloc (BRANCHSIZ);
-       for ( i = 0 ; i < RAA_LAYERSIZE ; i++ )
-           s->u.b.data[i] = NULL;
-       s->layers = r->layers + 1;
-       s->stepsize = LAYERSIZ(r) * r->stepsize;
-       s->u.b.data[0] = r;
-       r = s;
-    }
-
-    result = r;
-
-    while (r->layers > 0) {
-       ldiv_t l;
-       struct RAA **s;
-       l = ldiv (posn, r->stepsize);
-       s = &r->u.b.data[l.quot];
-       if (!*s)
-           *s = real_raa_init (r->layers - 1);
-       r = *s;
-       posn = l.rem;
-    }
-
-    r->u.l.data[posn] = value;
-
-    return result;
-}
-
-#define SAA_MAXLEN 8192
-
-struct SAA *saa_init (long elem_len) 
-{
-    struct SAA *s;
-
-    if (elem_len > SAA_MAXLEN)
-       nasm_malloc_error (ERR_PANIC | ERR_NOFILE, "SAA with huge elements");
-
-    s = nasm_malloc (sizeof(struct SAA));
-    s->posn = s->start = 0L;
-    s->elem_len = elem_len;
-    s->length = SAA_MAXLEN - (SAA_MAXLEN % elem_len);
-    s->data = nasm_malloc (s->length);
-    s->next = NULL;
-    s->end = s;
-
-    return s;
-}
-
-void saa_free (struct SAA *s) 
-{
-    struct SAA *t;
-
-    while (s) {
-       t = s->next;
-       nasm_free (s->data);
-       nasm_free (s);
-       s = t;
-    }
-}
-
-void *saa_wstruct (struct SAA *s) 
-{
-    void *p;
-
-    if (s->end->length - s->end->posn < s->elem_len) {
-       s->end->next = nasm_malloc (sizeof(struct SAA));
-       s->end->next->start = s->end->start + s->end->posn;
-       s->end = s->end->next;
-       s->end->length = s->length;
-       s->end->next = NULL;
-       s->end->posn = 0L;
-       s->end->data = nasm_malloc (s->length);
-    }
-
-    p = s->end->data + s->end->posn;
-    s->end->posn += s->elem_len;
-    return p;
-}
-
-void saa_wbytes (struct SAA *s, const void *data, long len) 
-{
-    const char *d = data;
-
-    while (len > 0) {
-       long l = s->end->length - s->end->posn;
-       if (l > len)
-           l = len;
-       if (l > 0) {
-           if (d) {
-               memcpy (s->end->data + s->end->posn, d, l);
-               d += l;
-           } else
-               memset (s->end->data + s->end->posn, 0, l);
-           s->end->posn += l;
-           len -= l;
-       }
-       if (len > 0) {
-           s->end->next = nasm_malloc (sizeof(struct SAA));
-           s->end->next->start = s->end->start + s->end->posn;
-           s->end = s->end->next;
-           s->end->length = s->length;
-           s->end->next = NULL;
-           s->end->posn = 0L;
-           s->end->data = nasm_malloc (s->length);
-       }
-    }
-}
-
-void saa_rewind (struct SAA *s) 
-{
-    s->rptr = s;
-    s->rpos = 0L;
-}
-
-void *saa_rstruct (struct SAA *s) 
-{
-    void *p;
-
-    if (!s->rptr)
-       return NULL;
-
-    if (s->rptr->posn - s->rpos < s->elem_len) {
-       s->rptr = s->rptr->next;
-       if (!s->rptr)
-           return NULL;               /* end of array */
-       s->rpos = 0L;
-    }
-
-    p = s->rptr->data + s->rpos;
-    s->rpos += s->elem_len;
-    return p;
-}
-
-void *saa_rbytes (struct SAA *s, long *len) 
-{
-    void *p;
-
-    if (!s->rptr)
-       return NULL;
-
-    p = s->rptr->data + s->rpos;
-    *len = s->rptr->posn - s->rpos;
-    s->rptr = s->rptr->next;
-    s->rpos = 0L;
-    return p;
-}
-
-void saa_rnbytes (struct SAA *s, void *data, long len) 
-{
-    char *d = data;
-
-    while (len > 0) {
-       long l;
-
-       if (!s->rptr)
-           return;
-
-       l = s->rptr->posn - s->rpos;
-       if (l > len)
-           l = len;
-       if (l > 0) {
-           memcpy (d, s->rptr->data + s->rpos, l);
-           d += l;
-           s->rpos += l;
-           len -= l;
-       }
-       if (len > 0) {
-           s->rptr = s->rptr->next;
-           s->rpos = 0L;
-       }
-    }
-}
-
-void saa_fread (struct SAA *s, long posn, void *data, long len) 
-{
-    struct SAA *p;
-    long pos;
-    char *cdata = data;
-
-    if (!s->rptr || posn < s->rptr->start)
-       saa_rewind (s);
-    p = s->rptr;
-    while (posn >= p->start + p->posn) {
-       p = p->next;
-       if (!p)
-           return;                    /* what else can we do?! */
-    }
-
-    pos = posn - p->start;
-    while (len) {
-       long l = p->posn - pos;
-       if (l > len)
-           l = len;
-       memcpy (cdata, p->data+pos, l);
-       len -= l;
-       cdata += l;
-       p = p->next;
-       if (!p)
-           return;
-       pos = 0L;
-    }
-    s->rptr = p;
-}
-
-void saa_fwrite (struct SAA *s, long posn, void *data, long len) 
-{
-    struct SAA *p;
-    long pos;
-    char *cdata = data;
-
-    if (!s->rptr || posn < s->rptr->start)
-       saa_rewind (s);
-    p = s->rptr;
-    while (posn >= p->start + p->posn) {
-       p = p->next;
-       if (!p)
-           return;                    /* what else can we do?! */
-    }
-
-    pos = posn - p->start;
-    while (len) {
-       long l = p->posn - pos;
-       if (l > len)
-           l = len;
-       memcpy (p->data+pos, cdata, l);
-       len -= l;
-       cdata += l;
-       p = p->next;
-       if (!p)
-           return;
-       pos = 0L;
-    }
-    s->rptr = p;
-}
-
-void saa_fpwrite (struct SAA *s, FILE *fp) 
-{
-    char *data;
-    long len;
-
-    saa_rewind (s);
-    while ( (data = saa_rbytes (s, &len)) )
-       fwrite (data, 1, len, fp);
-}
-
-/*
- * Register, instruction, condition-code and prefix keywords used
- * by the scanner.
- */
-#include "names.c"
-static const char *special_names[] = {
-    "byte", "dword", "far", "long", "near", "nosplit", "qword",
-    "short", "strict", "to", "tword", "word"
-};
-static const char *prefix_names[] = {
-    "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
-    "repnz", "repz", "times"
-};
-
-
-/*
- * Standard scanner routine used by parser.c and some output
- * formats. It keeps a succession of temporary-storage strings in
- * stdscan_tempstorage, which can be cleared using stdscan_reset.
- */
-static char **stdscan_tempstorage = NULL;
-static int stdscan_tempsize = 0, stdscan_templen = 0;
-#define STDSCAN_TEMP_DELTA 256
-
-static void stdscan_pop(void) 
-{
-    nasm_free (stdscan_tempstorage[--stdscan_templen]);
-}
-
-void stdscan_reset(void) 
-{
-    while (stdscan_templen > 0)
-       stdscan_pop();
-}
-
-/*
- * Unimportant cleanup is done to avoid confusing people who are trying
- * to debug real memory leaks
- */
-void nasmlib_cleanup (void) 
-{
-    stdscan_reset();
-    nasm_free (stdscan_tempstorage);
-}
-
-static char *stdscan_copy(char *p, int len) 
-{
-    char *text;
-
-    text = nasm_malloc(len+1);
-    strncpy (text, p, len);
-    text[len] = '\0';
-
-    if (stdscan_templen >= stdscan_tempsize) {
-       stdscan_tempsize += STDSCAN_TEMP_DELTA;
-       stdscan_tempstorage = nasm_realloc(stdscan_tempstorage,
-                                          stdscan_tempsize*sizeof(char *));
-    }
-    stdscan_tempstorage[stdscan_templen++] = text;
-
-    return text;
-}
-
-char *stdscan_bufptr = NULL;
-int stdscan (void *private_data, struct tokenval *tv) 
-{
-    char ourcopy[MAX_KEYWORD+1], *r, *s;
-
-    (void) private_data;  /* Don't warn that this parameter is unused */
-
-    while (isspace(*stdscan_bufptr)) stdscan_bufptr++;
-    if (!*stdscan_bufptr)
-       return tv->t_type = 0;
-
-    /* we have a token; either an id, a number or a char */
-    if (isidstart(*stdscan_bufptr) ||
-       (*stdscan_bufptr == '$' && isidstart(stdscan_bufptr[1]))) {
-       /* now we've got an identifier */
-       int i;
-       int is_sym = FALSE;
-
-       if (*stdscan_bufptr == '$') {
-           is_sym = TRUE;
-           stdscan_bufptr++;
-       }
-
-       r = stdscan_bufptr++;
-       while (isidchar(*stdscan_bufptr)) stdscan_bufptr++;
-       tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
-
-       if (is_sym || stdscan_bufptr-r > MAX_KEYWORD)
-           return tv->t_type = TOKEN_ID;/* bypass all other checks */
-    
-       for (s=tv->t_charptr, r=ourcopy; *s; s++)
-           *r++ = tolower (*s);
-       *r = '\0';
-       /* right, so we have an identifier sitting in temp storage. now,
-        * is it actually a register or instruction name, or what? */
-       if ((tv->t_integer=bsi(ourcopy, reg_names,
-                              elements(reg_names)))>=0) {
-           tv->t_integer += EXPR_REG_START;
-           return tv->t_type = TOKEN_REG;
-       } else if ((tv->t_integer=bsi(ourcopy, insn_names,
-                                     elements(insn_names)))>=0) {
-           return tv->t_type = TOKEN_INSN;
-       }
-       for (i=0; i<elements(icn); i++)
-           if (!strncmp(ourcopy, icn[i], strlen(icn[i]))) {
-               char *p = ourcopy + strlen(icn[i]);
-               tv->t_integer = ico[i];
-               if ((tv->t_inttwo=bsi(p, conditions,
-                                        elements(conditions)))>=0)
-                   return tv->t_type = TOKEN_INSN;
-           }
-       if ((tv->t_integer=bsi(ourcopy, prefix_names,
-                                 elements(prefix_names)))>=0) {
-           tv->t_integer += PREFIX_ENUM_START;
-           return tv->t_type = TOKEN_PREFIX;
-       }
-       if ((tv->t_integer=bsi(ourcopy, special_names,
-                                 elements(special_names)))>=0)
-           return tv->t_type = TOKEN_SPECIAL;
-       if (!nasm_stricmp(ourcopy, "seg"))
-           return tv->t_type = TOKEN_SEG;
-       if (!nasm_stricmp(ourcopy, "wrt"))
-           return tv->t_type = TOKEN_WRT;
-       return tv->t_type = TOKEN_ID;
-    } else if (*stdscan_bufptr == '$' && !isnumchar(stdscan_bufptr[1])) {
-       /*
-        * It's a $ sign with no following hex number; this must
-        * mean it's a Here token ($), evaluating to the current
-        * assembly location, or a Base token ($$), evaluating to
-        * the base of the current segment.
-        */
-       stdscan_bufptr++;
-       if (*stdscan_bufptr == '$') {
-           stdscan_bufptr++;
-           return tv->t_type = TOKEN_BASE;
-       }
-       return tv->t_type = TOKEN_HERE;
-    } else if (isnumstart(*stdscan_bufptr)) {  /* now we've got a number */
-       int rn_error;
-
-       r = stdscan_bufptr++;
-       while (isnumchar(*stdscan_bufptr))
-           stdscan_bufptr++;
-
-       if (*stdscan_bufptr == '.') {
-           /*
-            * a floating point constant
-            */
-           stdscan_bufptr++;
-           while (isnumchar(*stdscan_bufptr) ||
-                  ((stdscan_bufptr[-1] == 'e' || stdscan_bufptr[-1] == 'E')
-                   && (*stdscan_bufptr == '-' || *stdscan_bufptr == '+')) ) 
-           {
-               stdscan_bufptr++;
-           }
-           tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
-           return tv->t_type = TOKEN_FLOAT;
-       }
-       r = stdscan_copy(r, stdscan_bufptr - r);
-       tv->t_integer = readnum(r, &rn_error);
-       stdscan_pop();
-       if (rn_error)
-           return tv->t_type = TOKEN_ERRNUM;/* some malformation occurred */
-       tv->t_charptr = NULL;
-       return tv->t_type = TOKEN_NUM;
-    } else if (*stdscan_bufptr == '\'' ||
-              *stdscan_bufptr == '"') {/* a char constant */
-       char quote = *stdscan_bufptr++, *r;
-       int rn_warn;
-       r = tv->t_charptr = stdscan_bufptr;
-       while (*stdscan_bufptr && *stdscan_bufptr != quote) stdscan_bufptr++;
-       tv->t_inttwo = stdscan_bufptr - r;      /* store full version */
-       if (!*stdscan_bufptr)
-           return tv->t_type = TOKEN_ERRNUM;       /* unmatched quotes */
-       stdscan_bufptr++;                       /* skip over final quote */
-       tv->t_integer = readstrnum(r, tv->t_inttwo, &rn_warn);
-       /* FIXME: rn_warn is not checked! */
-       return tv->t_type = TOKEN_NUM;
-    } else if (*stdscan_bufptr == ';') {  /* a comment has happened - stay */
-       return tv->t_type = 0;
-    } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '>') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SHR;
-    } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '<') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SHL;
-    } else if (stdscan_bufptr[0] == '/' && stdscan_bufptr[1] == '/') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SDIV;
-    } else if (stdscan_bufptr[0] == '%' && stdscan_bufptr[1] == '%') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SMOD;
-    } else if (stdscan_bufptr[0] == '=' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_EQ;
-    } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '>') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_NE;
-    } else if (stdscan_bufptr[0] == '!' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_NE;
-    } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_LE;
-    } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_GE;
-    } else if (stdscan_bufptr[0] == '&' && stdscan_bufptr[1] == '&') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_DBL_AND;
-    } else if (stdscan_bufptr[0] == '^' && stdscan_bufptr[1] == '^') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_DBL_XOR;
-    } else if (stdscan_bufptr[0] == '|' && stdscan_bufptr[1] == '|') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_DBL_OR;
-    } else                            /* just an ordinary char */
-       return tv->t_type = (unsigned char) (*stdscan_bufptr++);
-}
-
 /*
  * Return TRUE if the argument is a simple scalar. (Or a far-
  * absolute, which counts.)
  */
-int is_simple (expr *vect) 
+int nasm_is_simple (nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -886,7 +162,7 @@ int is_simple (expr *vect)
  * Return TRUE if the argument is a simple scalar, _NOT_ a far-
  * absolute.
  */
-int is_really_simple (expr *vect) 
+int nasm_is_really_simple (nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -905,7 +181,7 @@ int is_really_simple (expr *vect)
  * Return TRUE if the argument is relocatable (i.e. a simple
  * scalar, plus at most one segment-base, plus possibly a WRT).
  */
-int is_reloc (expr *vect) 
+int nasm_is_reloc (nasm_expr *vect) 
 {
     while (vect->type && !vect->value) /* skip initial value-0 terms */
        vect++;
@@ -940,7 +216,7 @@ int is_reloc (expr *vect)
 /*
  * Return TRUE if the argument contains an `unknown' part.
  */
-int is_unknown(expr *vect) 
+int nasm_is_unknown(nasm_expr *vect) 
 {
     while (vect->type && vect->type < EXPR_UNKNOWN)
        vect++;
@@ -951,7 +227,7 @@ int is_unknown(expr *vect)
  * Return TRUE if the argument contains nothing but an `unknown'
  * part.
  */
-int is_just_unknown(expr *vect) 
+int nasm_is_just_unknown(nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -962,7 +238,7 @@ int is_just_unknown(expr *vect)
  * Return the scalar part of a relocatable vector. (Including
  * simple scalar vectors - those qualify as relocatable.)
  */
-long reloc_value (expr *vect) 
+long nasm_reloc_value (nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -977,7 +253,7 @@ long reloc_value (expr *vect)
  * Return the segment number of a relocatable vector, or NO_SEG for
  * simple scalars.
  */
-long reloc_seg (expr *vect) 
+long nasm_reloc_seg (nasm_expr *vect) 
 {
     while (vect->type && (vect->type == EXPR_WRT || !vect->value))
        vect++;
@@ -996,7 +272,7 @@ long reloc_seg (expr *vect)
  * Return the WRT segment number of a relocatable vector, or NO_SEG
  * if no WRT part is present.
  */
-long reloc_wrt (expr *vect) 
+long nasm_reloc_wrt (nasm_expr *vect) 
 {
     while (vect->type && vect->type < EXPR_WRT)
        vect++;
@@ -1009,7 +285,7 @@ long reloc_wrt (expr *vect)
 /*
  * Binary search.
  */
-int bsi (char *string, const char **array, int size) 
+int nasm_bsi (char *string, const char **array, int size) 
 {
     int i = -1, j = size;             /* always, i < index < j */
     while (j-i >= 2) {
@@ -1028,26 +304,26 @@ int bsi (char *string, const char **array, int size)
 static char *file_name = NULL;
 static long line_number = 0;
 
-char *src_set_fname(char *newname) 
+char *nasm_src_set_fname(char *newname) 
 {
     char *oldname = file_name;
     file_name = newname;
     return oldname;
 }
 
-long src_set_linnum(long newline) 
+long nasm_src_set_linnum(long newline) 
 {
     long oldline = line_number;
     line_number = newline;
     return oldline;
 }
 
-long src_get_linnum(void) 
+long nasm_src_get_linnum(void) 
 {
     return line_number;
 }
 
-int src_get(long *xline, char **xname) 
+int nasm_src_get(long *xline, char **xname) 
 {
     if (!file_name || !*xname || strcmp(*xname, file_name)) 
     {
@@ -1092,25 +368,3 @@ char *nasm_strcat(char *one, char *two)
     strcpy(rslt+l1, two);
     return rslt;
 }
-
-void null_debug_init(struct ofmt *of, void *id, FILE *fp, efunc error ) {}
-void null_debug_linenum(const char *filename, long linenumber, long segto) {}
-void null_debug_deflabel(char *name, long segment, long offset, int is_global, char *special) {}
-void null_debug_routine(const char *directive, const char *params) {}
-void null_debug_typevalue(long type) {}
-void null_debug_output(int type, void *param) {}
-void null_debug_cleanup(void){}
-
-struct dfmt null_debug_form = {
-    "Null debug format",
-    "null",
-    null_debug_init,
-    null_debug_linenum,
-    null_debug_deflabel,
-    null_debug_routine,
-    null_debug_typevalue,
-    null_debug_output,
-    null_debug_cleanup
-};
-
-struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };
index 54964539e9251c66dee922e28509b244bf0b3b6c..5163758d60113c268e7283927b6304009d8da8ca 100644 (file)
@@ -6,17 +6,8 @@
  * distributed in the NASM archive.
  */
 
-#ifndef NASM_NASMLIB_H
-#define NASM_NASMLIB_H
-
-/*
- * If this is defined, the wrappers around malloc et al will
- * transform into logging variants, which will cause NASM to create
- * a file called `malloc.log' when run, and spew details of all its
- * memory management into that. That can then be analysed to detect
- * memory leaks and potentially other problems too.
- */
-/* #define LOGALLOC */
+#ifndef YASM_NASMLIB_H
+#define YASM_NASMLIB_H
 
 /*
  * Wrappers around malloc, realloc and free. nasm_malloc will
  * passed a NULL pointer; nasm_free will do nothing if it is passed
  * a NULL pointer.
  */
-#ifdef NASM_NASM_H                    /* need efunc defined for this */
-void nasm_set_malloc_error (efunc);
-#ifndef LOGALLOC
-void *nasm_malloc (size_t);
-void *nasm_realloc (void *, size_t);
-void nasm_free (void *);
-char *nasm_strdup (const char *);
-char *nasm_strndup (char *, size_t);
-#else
-void *nasm_malloc_log (char *, int, size_t);
-void *nasm_realloc_log (char *, int, void *, size_t);
-void nasm_free_log (char *, int, void *);
-char *nasm_strdup_log (char *, int, const char *);
-char *nasm_strndup_log (char *, int, char *, size_t);
-#define nasm_malloc(x) nasm_malloc_log(__FILE__,__LINE__,x)
-#define nasm_realloc(x,y) nasm_realloc_log(__FILE__,__LINE__,x,y)
-#define nasm_free(x) nasm_free_log(__FILE__,__LINE__,x)
-#define nasm_strdup(x) nasm_strdup_log(__FILE__,__LINE__,x)
-#define nasm_strndup(x,y) nasm_strndup_log(__FILE__,__LINE__,x,y)
-#endif
-#endif
-
-/*
- * ANSI doesn't guarantee the presence of `stricmp' or
- * `strcasecmp'.
- */
-#if defined(stricmp) || defined(strcasecmp)
-#if defined(stricmp)
-#define nasm_stricmp stricmp
-#else
+#define nasm_malloc xmalloc
+#define nasm_realloc xrealloc
+#define nasm_free xfree
+#define nasm_strdup xstrdup
+#define nasm_strndup xstrndup
 #define nasm_stricmp strcasecmp
-#endif
-#else
-int nasm_stricmp (const char *, const char *);
-#endif
-
-#if defined(strnicmp) || defined(strncasecmp)
-#if defined(strnicmp)
-#define nasm_strnicmp strnicmp
-#else
 #define nasm_strnicmp strncasecmp
-#endif
-#else
-int nasm_strnicmp (const char *, const char *, int);
-#endif
 
 /*
  * Convert a string into a number, using NASM number rules. Sets
  * `*error' to TRUE if an error occurs, and FALSE otherwise.
  */
-long readnum(char *str, int *error);
+long nasm_readnum(char *str, int *error);
 
 /*
  * Convert a character constant into a number. Sets
@@ -83,150 +36,27 @@ long readnum(char *str, int *error);
  * str points to and length covers the middle of the string,
  * without the quotes.
  */
-long readstrnum(char *str, int length, int *warn);
+long nasm_readstrnum(char *str, int length, int *warn);
 
 /*
  * seg_init: Initialise the segment-number allocator.
  * seg_alloc: allocate a hitherto unused segment number.
  */
-void seg_init(void);
-long seg_alloc(void);
-
-/*
- * many output formats will be able to make use of this: a standard
- * function to add an extension to the name of the input file
- */
-#ifdef NASM_NASM_H
-void standard_extension (char *inname, char *outname, char *extension,
-                        efunc error);
-#endif
-
-/*
- * some handy macros that will probably be of use in more than one
- * output format: convert integers into little-endian byte packed
- * format in memory
- */
-
-#define WRITELONG(p,v) \
-  do { \
-    *(p)++ = (v) & 0xFF; \
-    *(p)++ = ((v) >> 8) & 0xFF; \
-    *(p)++ = ((v) >> 16) & 0xFF; \
-    *(p)++ = ((v) >> 24) & 0xFF; \
-  } while (0)
-
-#define WRITESHORT(p,v) \
-  do { \
-    *(p)++ = (v) & 0xFF; \
-    *(p)++ = ((v) >> 8) & 0xFF; \
-  } while (0)
-
-/*
- * and routines to do the same thing to a file
- */
-void fwriteshort (int data, FILE *fp);
-void fwritelong (long data, FILE *fp);
-
-/*
- * Routines to manage a dynamic random access array of longs which
- * may grow in size to be more than the largest single malloc'able
- * chunk.
- */
-
-#define RAA_BLKSIZE 4096              /* this many longs allocated at once */
-#define RAA_LAYERSIZE 1024            /* this many _pointers_ allocated */
-
-typedef struct RAA RAA;
-typedef union RAA_UNION RAA_UNION;
-typedef struct RAA_LEAF RAA_LEAF;
-typedef struct RAA_BRANCH RAA_BRANCH;
-
-struct RAA {
-    /*
-     * Number of layers below this one to get to the real data. 0
-     * means this structure is a leaf, holding RAA_BLKSIZE real
-     * data items; 1 and above mean it's a branch, holding
-     * RAA_LAYERSIZE pointers to the next level branch or leaf
-     * structures.
-     */
-    int layers;
-    /*
-     * Number of real data items spanned by one position in the
-     * `data' array at this level. This number is 1, trivially, for
-     * a leaf (level 0): for a level 1 branch it should be
-     * RAA_BLKSIZE, and for a level 2 branch it's
-     * RAA_LAYERSIZE*RAA_BLKSIZE.
-     */
-    long stepsize;
-    union RAA_UNION {
-       struct RAA_LEAF {
-           long data[RAA_BLKSIZE];
-       } l;
-       struct RAA_BRANCH {
-           struct RAA *data[RAA_LAYERSIZE];
-       } b;
-    } u;
-};
-
-
-struct RAA *raa_init (void);
-void raa_free (struct RAA *);
-long raa_read (struct RAA *, long);
-struct RAA *raa_write (struct RAA *r, long posn, long value);
-
-/*
- * Routines to manage a dynamic sequential-access array, under the
- * same restriction on maximum mallocable block. This array may be
- * written to in two ways: a contiguous chunk can be reserved of a
- * given size, and a pointer returned, or single-byte data may be
- * written. The array can also be read back in the same two ways:
- * as a series of big byte-data blocks or as a list of structures
- * of a given size.
- */
-
-struct SAA {
-    /*
-     * members `end' and `elem_len' are only valid in first link in
-     * list; `rptr' and `rpos' are used for reading
-     */
-    struct SAA *next, *end, *rptr;
-    long elem_len, length, posn, start, rpos;
-    char *data;
-};
-
-struct SAA *saa_init (long elem_len);  /* 1 == byte */
-void saa_free (struct SAA *);
-void *saa_wstruct (struct SAA *);      /* return a structure of elem_len */
-void saa_wbytes (struct SAA *, const void *, long);  /* write arbitrary bytes */
-void saa_rewind (struct SAA *);               /* for reading from beginning */
-void *saa_rstruct (struct SAA *);      /* return NULL on EOA */
-void *saa_rbytes (struct SAA *, long *);   /* return 0 on EOA */
-void saa_rnbytes (struct SAA *, void *, long); /* read a given no. of bytes */
-void saa_fread (struct SAA *s, long posn, void *p, long len);   /* fixup */
-void saa_fwrite (struct SAA *s, long posn, void *p, long len);   /* fixup */
-void saa_fpwrite (struct SAA *, FILE *);
-
-#ifdef NASM_NASM_H
-/*
- * Standard scanner.
- */
-extern char *stdscan_bufptr;
-void stdscan_reset(void);
-int stdscan (void *private_data, struct tokenval *tv);
-#endif
+void nasm_seg_init(void);
+long nasm_seg_alloc(void);
 
-#ifdef NASM_NASM_H
+#ifdef YASM_NASM_H
 /*
  * Library routines to manipulate expression data types.
  */
-int is_reloc(expr *);
-int is_simple(expr *);
-int is_really_simple (expr *);
-int is_unknown(expr *);
-int is_just_unknown(expr *);
-long reloc_value(expr *);
-long reloc_seg(expr *);
-long reloc_wrt(expr *);
+int nasm_is_reloc(nasm_expr *);
+int nasm_is_simple(nasm_expr *);
+int nasm_is_really_simple (nasm_expr *);
+int nasm_is_unknown(nasm_expr *);
+int nasm_is_just_unknown(nasm_expr *);
+long nasm_reloc_value(nasm_expr *);
+long nasm_reloc_seg(nasm_expr *);
+long nasm_reloc_wrt(nasm_expr *);
 #endif
 
 /*
@@ -234,25 +64,21 @@ long reloc_wrt(expr *);
  * matching `string', or <0 if no match. `array' is taken to
  * contain `size' elements.
  */
-int bsi (char *string, const char **array, int size);
+int nasm_bsi (char *string, const char **array, int size);
 
 
-char *src_set_fname(char *newname);
-long src_set_linnum(long newline);
-long src_get_linnum(void);
+char *nasm_src_set_fname(char *newname);
+long nasm_src_set_linnum(long newline);
+long nasm_src_get_linnum(void);
 /*
  * src_get may be used if you simply want to know the source file and line.
  * It is also used if you maintain private status about the source location
  * It return 0 if the information was the same as the last time you
  * checked, -1 if the name changed and (new-old) if just the line changed.
  */
-int src_get(long *xline, char **xname);
+int nasm_src_get(long *xline, char **xname);
 
 void nasm_quote(char **str);
 char *nasm_strcat(char *one, char *two);
-void nasmlib_cleanup(void);
 
-void null_debug_routine(const char *directive, const char *params);
-extern struct dfmt null_debug_form;
-extern struct dfmt *null_debug_arr[2];
 #endif
index 27ce27918f4bd50348e2f22c2c18f4dde33eb1c5..1e3134eac4177a81ad06f776f4233a961e53f111 100644 (file)
@@ -58,6 +58,14 @@ EXTRA_DIST += \
        src/objfmts/Makefile.inc        \
        src/tests/Makefile.inc
 
+# Modules with more than one type of interface
+
+lib_LTLIBRARIES += yasm-nasm.la
+yasm_nasm_la_SOURCES =
+yasm_nasm_la_LDFLAGS = -module -avoid-version
+yasm_nasm_la_LIBADD = libyasm.la
+yasm_LDADD += -dlopen yasm-nasm.la
+
 include src/arch/Makefile.inc
 include src/parsers/Makefile.inc
 include src/preprocs/Makefile.inc
index b8689b13ed90b743cd057b25665bad8397e941de..18b01f670bc188ec659961f589c9f170ed149513 100644 (file)
@@ -249,9 +249,9 @@ main(int argc, char *argv[])
            }
        }
 
-       /* If not already specified, default to yapp preproc. */
+       /* If not already specified, default to nasm preproc. */
        if (!cur_preproc)
-           cur_preproc = load_preproc("yapp");
+           cur_preproc = load_preproc("nasm");
 
        if (!cur_preproc) {
            fprintf(stderr, _("Could not load default preprocessor"));
index 80df154dbeceee650b79afdc07d36fa0fc98fa6f..43ac6c8943f2beceeb13366c4b6f4a61256305d6 100644 (file)
@@ -1,17 +1,17 @@
 # $IdPath$
 
-lib_LTLIBRARIES += yasm-nasm.la
+#lib_LTLIBRARIES += yasm-nasm.la
 
-yasm_nasm_la_SOURCES = \
+yasm_nasm_la_SOURCES += \
        src/parsers/nasm/nasm-parser.h          \
        src/parsers/nasm/nasm-parser.c          \
        src/parsers/nasm/nasm-defs.h            \
        src/parsers/nasm/nasm-bison.y           \
        nasm-bison.h                            \
        nasm-token.c
-yasm_nasm_la_LDFLAGS = -module -avoid-version
-yasm_nasm_la_LIBADD = libyasm.la
-yasm_LDADD += -dlpreopen yasm-nasm.la
+#yasm_nasm_la_LDFLAGS = -module -avoid-version
+#yasm_nasm_la_LIBADD = libyasm.la
+#yasm_LDADD += -dlpreopen yasm-nasm.la
 
 nasm-token.c: $(srcdir)/src/parsers/nasm/nasm-token.re re2c$(EXEEXT) $(srcdir)/tools/re2c/cleanup.pl
        $(top_builddir)/re2c$(EXEEXT) -b $(srcdir)/src/parsers/nasm/nasm-token.re | $(PERL) $(srcdir)/tools/re2c/cleanup.pl | sed "/^#l/ s,re2c-out\.c,$@," > $@
index 0849f3ffce6f10f1802b1f7528d9a85c31305ba5..0fae8c097adbaf62d6cf0c440b209928b06d7b6d 100644 (file)
@@ -1,8 +1,10 @@
 # $IdPath$
 
 EXTRA_DIST += \
+       src/preprocs/nasm/Makefile.inc \
        src/preprocs/raw/Makefile.inc \
        src/preprocs/yapp/Makefile.inc
 
+include src/preprocs/nasm/Makefile.inc
 include src/preprocs/raw/Makefile.inc
 include src/preprocs/yapp/Makefile.inc
diff --git a/src/preprocs/nasm/Makefile.inc b/src/preprocs/nasm/Makefile.inc
new file mode 100644 (file)
index 0000000..7df8e5f
--- /dev/null
@@ -0,0 +1,26 @@
+# $IdPath$
+
+#lib_LTLIBRARIES += yasm-nasm.la
+
+yasm_nasm_la_SOURCES += \
+       src/preprocs/nasm/nasm-preproc.c \
+       src/preprocs/nasm/nasm-pp.h \
+       src/preprocs/nasm/nasm-pp.c \
+       src/preprocs/nasm/nasmlib.h \
+       src/preprocs/nasm/nasmlib.c \
+       src/preprocs/nasm/nasm-eval.h \
+       src/preprocs/nasm/nasm-eval.c
+
+src/preprocs/nasm/nasm-pp.c: nasm-macros.c
+
+nasm-macros.c: src/preprocs/nasm/macros.pl src/preprocs/nasm/standard.mac
+       $(PERL) src/preprocs/nasm/macros.pl src/preprocs/nasm/standard.mac
+
+BUILT_SOURCES += nasm-macros.c
+
+EXTRA_DIST += src/preprocs/nasm/macros.pl \
+       src/preprocs/nasm/standard.mac
+
+#yasm_nasm_la_LDFLAGS = -module -avoid-version
+#yasm_nasm_la_LIBADD = libyasm.la
+#yasm_LDADD += -dlopen yasm-nasm.la
index 0934d1741c85bb2b9ddf60c46b4c5cdebb99d188..bb217e15697543996c0b66051720a7af38016e92 100644 (file)
@@ -16,7 +16,7 @@ my $tasm_count;
 
 undef $tasm_count;
 
-open(OUTPUT,">macros.c") or die "unable to open macros.c\n";
+open(OUTPUT,">nasm-macros.c") or die "unable to open nasm-macros.c\n";
     
 print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" .
 " - don't edit it */\n\n#include <stddef.h>\n\nstatic const char *stdmac[] = {\n";
index 28aca642b12ea87d027f7135e8153ee58660c3c5..545f42564a3176dcaefe397adcd322e16e8ba991 100644 (file)
@@ -7,17 +7,13 @@
  *
  * initial version 27/iii/95 by Simon Tatham
  */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
+#include "util.h"
 #include <ctype.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
-#include "eval.h"
-#include "labels.h"
+#include "nasm-eval.h"
+/*#include "labels.h"*/
 
 #define TEMPEXPRS_DELTA 128
 #define TEMPEXPR_DELTA 8
@@ -28,11 +24,11 @@ static lfunc labelfunc;     /* Address of label routine */
 
 static struct ofmt *outfmt;  /* Structure of addresses of output routines */
 
-static expr **tempexprs = NULL;
+static nasm_expr **tempexprs = NULL;
 static int    ntempexprs;
 static int    tempexprs_size = 0;
 
-static expr  *tempexpr;
+static nasm_expr  *tempexpr;
 static int   ntempexpr;
 static int   tempexpr_size;
 
@@ -45,15 +41,15 @@ static int *opflags;
 
 static struct eval_hints *hint;
 
-extern int  in_abs_seg;                /* ABSOLUTE segment flag */
-extern long abs_seg;           /* ABSOLUTE segment */
-extern long abs_offset;                /* ABSOLUTE segment offset */
+static int  in_abs_seg = 0;            /* ABSOLUTE segment flag */
+static long abs_seg = 0;               /* ABSOLUTE segment */
+static long abs_offset = 0;            /* ABSOLUTE segment offset */
 
 /*
  * Unimportant cleanup is done to avoid confusing people who are trying
  * to debug real memory leaks
  */
-void eval_cleanup(void) 
+void nasm_eval_cleanup(void) 
 {
     while (ntempexprs)
        nasm_free (tempexprs[--ntempexprs]);
@@ -80,7 +76,7 @@ static void addtotemp(long type, long value)
     tempexpr[ntempexpr++].value = value;
 }
 
-static expr *finishtemp(void) 
+static nasm_expr *finishtemp(void) 
 {
     addtotemp (0L, 0L);                       /* terminate */
     while (ntempexprs >= tempexprs_size) {
@@ -96,11 +92,11 @@ static expr *finishtemp(void)
  * absolute segment types: we preserve them during addition _only_
  * if one of the segments is a truly pure scalar.
  */
-static expr *add_vectors(expr *p, expr *q) 
+static nasm_expr *add_vectors(nasm_expr *p, nasm_expr *q) 
 {
     int preserve;
 
-    preserve = is_really_simple(p) || is_really_simple(q);
+    preserve = nasm_is_really_simple(p) || nasm_is_really_simple(q);
 
     begintemp();
 
@@ -155,9 +151,9 @@ static expr *add_vectors(expr *p, expr *q)
  * multiplied. This allows [eax*1+ebx] to hint EBX rather than EAX
  * as the base register.
  */
-static expr *scalar_mult(expr *vect, long scalar, int affect_hints) 
+static nasm_expr *scalar_mult(nasm_expr *vect, long scalar, int affect_hints) 
 {
-    expr *p = vect;
+    nasm_expr *p = vect;
 
     while (p->type && p->type < EXPR_SEGBASE+SEG_ABS) {
        p->value = scalar * (p->value);
@@ -171,14 +167,14 @@ static expr *scalar_mult(expr *vect, long scalar, int affect_hints)
     return vect;
 }
 
-static expr *scalarvect (long scalar) 
+static nasm_expr *scalarvect (long scalar) 
 {
     begintemp();
     addtotemp(EXPR_SIMPLE, scalar);
     return finishtemp();
 }
 
-static expr *unknown_expr (void) 
+static nasm_expr *unknown_expr (void) 
 {
     begintemp();
     addtotemp(EXPR_UNKNOWN, 1L);
@@ -190,19 +186,19 @@ static expr *unknown_expr (void)
  * value. Return NULL, as usual, if an error occurs. Report the
  * error too.
  */
-static expr *segment_part (expr *e) 
+static nasm_expr *segment_part (nasm_expr *e) 
 {
     long seg;
 
-    if (is_unknown(e))
+    if (nasm_is_unknown(e))
        return unknown_expr();
 
-    if (!is_reloc(e)) {
+    if (!nasm_is_reloc(e)) {
        error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
        return NULL;
     }
 
-    seg = reloc_seg(e);
+    seg = nasm_reloc_seg(e);
     if (seg == NO_SEG) {
        error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
        return NULL;
@@ -255,16 +251,16 @@ static expr *segment_part (expr *e)
  *       | number
  */
 
-static expr *rexp0(int), *rexp1(int), *rexp2(int), *rexp3(int);
+static nasm_expr *rexp0(int), *rexp1(int), *rexp2(int), *rexp3(int);
 
-static expr *expr0(int), *expr1(int), *expr2(int), *expr3(int);
-static expr *expr4(int), *expr5(int), *expr6(int);
+static nasm_expr *expr0(int), *expr1(int), *expr2(int), *expr3(int);
+static nasm_expr *expr4(int), *expr5(int), *expr6(int);
 
-static expr *(*bexpr)(int);
+static nasm_expr *(*bexpr)(int);
 
-static expr *rexp0(int critical) 
+static nasm_expr *rexp0(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = rexp1(critical);
     if (!e)
@@ -276,24 +272,24 @@ static expr *rexp0(int critical)
        f = rexp1(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`|' operator may only be applied to"
                  " scalar values");
        }
 
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect ((long) (reloc_value(e) || reloc_value(f)));
+           e = scalarvect ((long) (nasm_reloc_value(e) || nasm_reloc_value(f)));
     }
     return e;
 }
 
-static expr *rexp1(int critical) 
+static nasm_expr *rexp1(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = rexp2(critical);
     if (!e)
@@ -305,24 +301,24 @@ static expr *rexp1(int critical)
        f = rexp2(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`^' operator may only be applied to"
                  " scalar values");
        }
 
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect ((long) (!reloc_value(e) ^ !reloc_value(f)));
+           e = scalarvect ((long) (!nasm_reloc_value(e) ^ !nasm_reloc_value(f)));
     }
     return e;
 }
 
-static expr *rexp2(int critical) 
+static nasm_expr *rexp2(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = rexp3(critical);
     if (!e)
@@ -333,23 +329,23 @@ static expr *rexp2(int critical)
        f = rexp3(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`&' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect ((long) (reloc_value(e) && reloc_value(f)));
+           e = scalarvect ((long) (nasm_reloc_value(e) && nasm_reloc_value(f)));
     }
     return e;
 }
 
-static expr *rexp3(int critical) 
+static nasm_expr *rexp3(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
     long v;
 
     e = expr0(critical);
@@ -370,23 +366,23 @@ static expr *rexp3(int critical)
        switch (j) 
        {
          case TOKEN_EQ: case TOKEN_NE:
-           if (is_unknown(e))
+           if (nasm_is_unknown(e))
                v = -1;                /* means unknown */
-           else if (!is_really_simple(e) || reloc_value(e) != 0)
+           else if (!nasm_is_really_simple(e) || nasm_reloc_value(e) != 0)
                v = (j == TOKEN_NE);   /* unequal, so return TRUE if NE */
            else
                v = (j == TOKEN_EQ);   /* equal, so return TRUE if EQ */
            break;
          default:
-           if (is_unknown(e))
+           if (nasm_is_unknown(e))
                v = -1;                /* means unknown */
-           else if (!is_really_simple(e)) {
+           else if (!nasm_is_really_simple(e)) {
                error(ERR_NONFATAL, "`%s': operands differ by a non-scalar",
                      (j == TOKEN_LE ? "<=" : j == TOKEN_LT ? "<" :
                       j == TOKEN_GE ? ">=" : ">"));
                v = 0;                 /* must set it to _something_ */
            } else {
-               int vv = reloc_value(e);
+               int vv = nasm_reloc_value(e);
                if (vv == 0)
                    v = (j == TOKEN_LE || j == TOKEN_GE);
                else if (vv > 0)
@@ -405,9 +401,9 @@ static expr *rexp3(int critical)
     return e;
 }
 
-static expr *expr0(int critical) 
+static nasm_expr *expr0(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr1(critical);
     if (!e)
@@ -419,23 +415,23 @@ static expr *expr0(int critical)
        f = expr1(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`|' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect (reloc_value(e) | reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) | nasm_reloc_value(f));
     }
     return e;
 }
 
-static expr *expr1(int critical) 
+static nasm_expr *expr1(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr2(critical);
     if (!e)
@@ -446,23 +442,23 @@ static expr *expr1(int critical)
        f = expr2(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`^' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect (reloc_value(e) ^ reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) ^ nasm_reloc_value(f));
     }
     return e;
 }
 
-static expr *expr2(int critical) 
+static nasm_expr *expr2(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr3(critical);
     if (!e)
@@ -473,23 +469,23 @@ static expr *expr2(int critical)
        f = expr3(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "`&' operator may only be applied to"
                  " scalar values");
        }
-       if (is_just_unknown(e) || is_just_unknown(f))
+       if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
            e = unknown_expr();
        else
-           e = scalarvect (reloc_value(e) & reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) & nasm_reloc_value(f));
     }
     return e;
 }
 
-static expr *expr3(int critical) 
+static nasm_expr *expr3(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr4(critical);
     if (!e)
@@ -502,29 +498,29 @@ static expr *expr3(int critical)
        f = expr4(critical);
        if (!f)
            return NULL;
-       if (!(is_simple(e) || is_just_unknown(e)) ||
-           !(is_simple(f) || is_just_unknown(f))) 
+       if (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+           !(nasm_is_simple(f) || nasm_is_just_unknown(f))) 
        {
            error(ERR_NONFATAL, "shift operator may only be applied to"
                  " scalar values");
-       } else if (is_just_unknown(e) || is_just_unknown(f)) {
+       } else if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f)) {
            e = unknown_expr();
        } else switch (j) {
          case TOKEN_SHL:
-           e = scalarvect (reloc_value(e) << reloc_value(f));
+           e = scalarvect (nasm_reloc_value(e) << nasm_reloc_value(f));
            break;
          case TOKEN_SHR:
-           e = scalarvect (((unsigned long)reloc_value(e)) >>
-                           reloc_value(f));
+           e = scalarvect (((unsigned long)nasm_reloc_value(e)) >>
+                           nasm_reloc_value(f));
            break;
        }
     }
     return e;
 }
 
-static expr *expr4(int critical) 
+static nasm_expr *expr4(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr5(critical);
     if (!e)
@@ -548,9 +544,9 @@ static expr *expr4(int critical)
     return e;
 }
 
-static expr *expr5(int critical) 
+static nasm_expr *expr5(int critical) 
 {
-    expr *e, *f;
+    nasm_expr *e, *f;
 
     e = expr6(critical);
     if (!e)
@@ -563,24 +559,24 @@ static expr *expr5(int critical)
        f = expr6(critical);
        if (!f)
            return NULL;
-       if (j != '*' && (!(is_simple(e) || is_just_unknown(e)) ||
-                        !(is_simple(f) || is_just_unknown(f)))) 
+       if (j != '*' && (!(nasm_is_simple(e) || nasm_is_just_unknown(e)) ||
+                        !(nasm_is_simple(f) || nasm_is_just_unknown(f)))) 
        {
            error(ERR_NONFATAL, "division operator may only be applied to"
                  " scalar values");
            return NULL;
        }
-       if (j != '*' && !is_unknown(f) && reloc_value(f) == 0) {
+       if (j != '*' && !nasm_is_unknown(f) && nasm_reloc_value(f) == 0) {
            error(ERR_NONFATAL, "division by zero");
            return NULL;
        }
        switch (j) {
          case '*':
-           if (is_simple(e))
-               e = scalar_mult (f, reloc_value(e), TRUE);
-           else if (is_simple(f))
-               e = scalar_mult (e, reloc_value(f), TRUE);
-           else if (is_just_unknown(e) && is_just_unknown(f))
+           if (nasm_is_simple(e))
+               e = scalar_mult (f, nasm_reloc_value(e), TRUE);
+           else if (nasm_is_simple(f))
+               e = scalar_mult (e, nasm_reloc_value(f), TRUE);
+           else if (nasm_is_just_unknown(e) && nasm_is_just_unknown(f))
                e = unknown_expr();
            else {
                error(ERR_NONFATAL, "unable to multiply two "
@@ -589,42 +585,42 @@ static expr *expr5(int critical)
            }
            break;
          case '/':
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((unsigned long)reloc_value(e)) /
-                               ((unsigned long)reloc_value(f)));
+               e = scalarvect (((unsigned long)nasm_reloc_value(e)) /
+                               ((unsigned long)nasm_reloc_value(f)));
            break;
          case '%':
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((unsigned long)reloc_value(e)) %
-                               ((unsigned long)reloc_value(f)));
+               e = scalarvect (((unsigned long)nasm_reloc_value(e)) %
+                               ((unsigned long)nasm_reloc_value(f)));
            break;
          case TOKEN_SDIV:
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((signed long)reloc_value(e)) /
-                               ((signed long)reloc_value(f)));
+               e = scalarvect (((signed long)nasm_reloc_value(e)) /
+                               ((signed long)nasm_reloc_value(f)));
            break;
          case TOKEN_SMOD:
-           if (is_just_unknown(e) || is_just_unknown(f))
+           if (nasm_is_just_unknown(e) || nasm_is_just_unknown(f))
                e = unknown_expr();
            else
-               e = scalarvect (((signed long)reloc_value(e)) %
-                               ((signed long)reloc_value(f)));
+               e = scalarvect (((signed long)nasm_reloc_value(e)) %
+                               ((signed long)nasm_reloc_value(f)));
            break;
        }
     }
     return e;
 }
 
-static expr *expr6(int critical) 
+static nasm_expr *expr6(int critical) 
 {
     long type;
-    expr *e;
+    nasm_expr *e;
     long label_seg, label_ofs;
 
     if (i == '-') {
@@ -641,14 +637,14 @@ static expr *expr6(int critical)
        e = expr6(critical);
        if (!e)
            return NULL;
-       if (is_just_unknown(e))
+       if (nasm_is_just_unknown(e))
            return unknown_expr();
-       else if (!is_simple(e)) {
+       else if (!nasm_is_simple(e)) {
            error(ERR_NONFATAL, "`~' operator may only be applied to"
                  " scalar values");
            return NULL;
        }
-       return scalarvect(~reloc_value(e));
+       return scalarvect(~nasm_reloc_value(e));
     } else if (i == TOKEN_SEG) {
        i = scan(scpriv, tokval);
        e = expr6(critical);
@@ -657,7 +653,7 @@ static expr *expr6(int critical)
        e = segment_part(e);
        if (!e)
            return NULL;
-       if (is_unknown(e) && critical) {
+       if (nasm_is_unknown(e) && critical) {
            error(ERR_NONFATAL, "unable to determine segment base");
            return NULL;
        }
@@ -732,8 +728,10 @@ static expr *expr6(int critical)
                    label_ofs = 1;
                }
            }
-               if (opflags && is_extern (tokval->t_charptr))
+#if 0
+               if (opflags && nasm_is_extern (tokval->t_charptr))
                    *opflags |= OPFLAG_EXTERN;
+#endif
            }
            addtotemp(type, label_ofs);
            if (label_seg!=NO_SEG)
@@ -748,19 +746,19 @@ static expr *expr6(int critical)
     }
 }
 
-void eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp) 
+void nasm_eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp) 
 {
     outfmt = output;
     labelfunc = lookup_label;
     location = locp;
 }
 
-expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
+nasm_expr *nasm_evaluate (scanner sc, void *scprivate, struct tokenval *tv,
                int *fwref, int critical, efunc report_error,
                struct eval_hints *hints) 
 {
-    expr *e;
-    expr *f = NULL;
+    nasm_expr *e;
+    nasm_expr *f = NULL;
 
     hint = hints;
     if (hint)
@@ -798,19 +796,19 @@ expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
     }
     e = scalar_mult (e, 1L, FALSE);    /* strip far-absolute segment part */
     if (f) {
-       expr *g;
-       if (is_just_unknown(f))
+       nasm_expr *g;
+       if (nasm_is_just_unknown(f))
            g = unknown_expr();
        else {
            long value;
            begintemp();
-           if (!is_reloc(f)) {
+           if (!nasm_is_reloc(f)) {
                error(ERR_NONFATAL, "invalid right-hand operand to WRT");
                return NULL;
            }
-           value = reloc_seg(f);
+           value = nasm_reloc_seg(f);
            if (value == NO_SEG)
-               value = reloc_value(f) | SEG_ABS;
+               value = nasm_reloc_value(f) | SEG_ABS;
            else if (!(value & SEG_ABS) && !(value % 2) && critical) 
            {
                error(ERR_NONFATAL, "invalid right-hand operand to WRT");
index a933cbfd0a69dd3022fc16d8165a91e03ec2e9fe..92495937bf93882928232d2016d40d0d0e0cd7a1 100644 (file)
  * providing segment-base details, and what function can be used to
  * look labels up.
  */
-void eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp);
+void nasm_eval_global_info (struct ofmt *output, lfunc lookup_label, loc_t *locp);
 
 /*
  * The evaluator itself.
  */
-expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
+nasm_expr *nasm_evaluate (scanner sc, void *scprivate, struct tokenval *tv,
                int *fwref, int critical, efunc report_error,
                struct eval_hints *hints);
 
-void eval_cleanup(void);
+void nasm_eval_cleanup(void);
 
 #endif
index 0770812ed5285e21256c1c8f85f024e77f0e7b47..8b7278b10d2be59c13cd1d0102c2c53f4bf3dd01 100644 (file)
  *
  * detoken is used to convert the line back to text
  */
-
-#include <stdio.h>
+#include "util.h"
 #include <stdarg.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
 #include <ctype.h>
 #include <limits.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
+#include "nasm-pp.h"
 
 typedef struct SMacro SMacro;
 typedef struct MMacro MMacro;
@@ -343,7 +340,7 @@ static const char *tasm_directives[] = {
 };
 
 static int StackSize = 4;
-static char *StackPointer = "ebp";
+static const char *StackPointer = "ebp";
 static int ArgOffset = 8;
 static int LocalOffset = 4;
 
@@ -395,7 +392,7 @@ static MMacro *defining;
  * The standard macro set: defined as `static char *stdmac[]'. Also
  * gives our position in the macro set, when we're processing it.
  */
-#include "macros.c"
+#include "nasm-macros.c"
 static const char **stdmacpos;
 
 /*
@@ -428,7 +425,7 @@ static void make_tok_num(Token * tok, long val);
 static void error(int severity, const char *fmt, ...);
 static void *new_Block(size_t size);
 static void delete_Blocks(void);
-static Token *new_Token(Token * next, int type, char *text, int txtlen);
+static Token *new_Token(Token * next, int type, const char *text, int txtlen);
 static Token *delete_Token(Token * t);
 
 /*
@@ -571,11 +568,11 @@ hash(char *s)
  * Free a linked list of tokens.
  */
 static void
-free_tlist(Token * list)
+free_tlist(Token * list_)
 {
-    while (list)
+    while (list_)
     {
-       list = delete_Token(list);
+       list_ = delete_Token(list_);
     }
 }
 
@@ -583,13 +580,13 @@ free_tlist(Token * list)
  * Free a linked list of lines.
  */
 static void
-free_llist(Line * list)
+free_llist(Line * list_)
 {
     Line *l;
-    while (list)
+    while (list_)
     {
-       l = list;
-       list = list->next;
+       l = list_;
+       list_ = list_->next;
        free_tlist(l->first);
        nasm_free(l);
     }
@@ -735,7 +732,7 @@ read_line(void)
        return NULL;
     }
 
-    src_set_linnum(src_get_linnum() + istk->lineinc + (continued_count * istk->lineinc));
+    nasm_src_set_linnum(nasm_src_get_linnum() + istk->lineinc + (continued_count * istk->lineinc));
 
     /*
      * Play safe: remove CRs as well as LFs, if any of either are
@@ -765,8 +762,8 @@ tokenise(char *line)
 {
     char *p = line;
     int type;
-    Token *list = NULL;
-    Token *t, **tail = &list;
+    Token *list_ = NULL;
+    Token *t, **tail = &list_;
 
     while (*line)
     {
@@ -908,7 +905,7 @@ tokenise(char *line)
        }
        line = p;
     }
-    return list;
+    return list_;
 }
 
 /*
@@ -965,7 +962,7 @@ delete_Blocks(void)
  *  also the mac and next elements to NULL.
  */
 static Token *
-new_Token(Token * next, int type, char *text, int txtlen)
+new_Token(Token * next, int type, const char *text, int txtlen)
 {
     Token *t;
     int i;
@@ -1024,10 +1021,10 @@ detoken(Token * tlist, int expand_locals)
     {
        if (t->type == TOK_PREPROC_ID && t->text[1] == '!')
        {
-           char *p = getenv(t->text + 2);
+           char *p2 = getenv(t->text + 2);
            nasm_free(t->text);
-           if (p)
-               t->text = nasm_strdup(p);
+           if (p2)
+               t->text = nasm_strdup(p2);
            else
                t->text = NULL;
        }
@@ -1040,13 +1037,13 @@ detoken(Token * tlist, int expand_locals)
            if (ctx)
            {
                char buffer[40];
-               char *p, *q = t->text + 2;
+               char *p2, *q = t->text + 2;
 
                q += strspn(q, "$");
                sprintf(buffer, "..@%lu.", ctx->number);
-               p = nasm_strcat(buffer, q);
+               p2 = nasm_strcat(buffer, q);
                nasm_free(t->text);
-               t->text = p;
+               t->text = p2;
            }
        }
        if (t->type == TOK_WHITESPACE)
@@ -1128,7 +1125,7 @@ ppscan(void *private_data, struct tokenval *tokval)
     {
        int rn_error;
 
-       tokval->t_integer = readnum(tline->text, &rn_error);
+       tokval->t_integer = nasm_readnum(tline->text, &rn_error);
        if (rn_error)
            return tokval->t_type = TOKEN_ERRNUM;
        tokval->t_charptr = NULL;
@@ -1147,7 +1144,7 @@ ppscan(void *private_data, struct tokenval *tokval)
 
        if (l == 0 || r[l - 1] != q)
            return tokval->t_type = TOKEN_ERRNUM;
-       tokval->t_integer = readstrnum(r, l - 1, &rn_warn);
+       tokval->t_integer = nasm_readstrnum(r, l - 1, &rn_warn);
        if (rn_warn)
            error(ERR_WARNING | ERR_PASS1, "character constant too long");
        tokval->t_charptr = NULL;
@@ -1281,7 +1278,8 @@ static FILE *
 inc_fopen(char *file)
 {
     FILE *fp;
-    char *prefix = "", *combine;
+    const char *prefix = "";
+    char *combine;
     IncPath *ip = ipath;
     static int namelen = 0;
     int len = strlen(file);
@@ -1440,7 +1438,7 @@ if_condition(Token * tline, int i)
     int j, casesense;
     Token *t, *tt, **tptr, *origline;
     struct tokenval tokval;
-    expr *evalresult;
+    nasm_expr *evalresult;
 
     origline = tline;
 
@@ -1601,7 +1599,7 @@ if_condition(Token * tline, int i)
            else
            {
                searching.nparam_min = searching.nparam_max =
-                       readnum(tline->text, &j);
+                       nasm_readnum(tline->text, &j);
                if (j)
                    error(ERR_NONFATAL,
                          "unable to parse parameter count `%s'",
@@ -1618,7 +1616,7 @@ if_condition(Token * tline, int i)
                          directives[i]);
                else
                {
-                   searching.nparam_max = readnum(tline->text, &j);
+                   searching.nparam_max = nasm_readnum(tline->text, &j);
                    if (j)
                        error(ERR_NONFATAL,
                                "unable to parse parameter count `%s'",
@@ -1713,13 +1711,13 @@ if_condition(Token * tline, int i)
            if (tokval.t_type)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL,
                        "non-constant value given to `%s'", directives[i]);
                return -1;
            }
-           return reloc_value(evalresult) != 0;
+           return nasm_reloc_value(evalresult) != 0;
 
        default:
            error(ERR_FATAL,
@@ -1735,7 +1733,7 @@ if_condition(Token * tline, int i)
  * First tokenise the string, apply "expand_smacro" and then de-tokenise back.
  * The returned variable should ALWAYS be freed after usage.
  */
-void
+static void
 expand_macros_in_string(char **p)
 {
     Token *line = tokenise(*p);
@@ -1769,7 +1767,7 @@ do_directive(Token * tline)
     Token *t, *tt, *param_start, *macro_start, *last, **tptr, *origline;
     Line *l;
     struct tokenval tokval;
-    expr *evalresult;
+    nasm_expr *evalresult;
     MMacro *tmp_defining;      /* Used when manipulating rep_nest */
 
     origline = tline;
@@ -2095,9 +2093,9 @@ do_directive(Token * tline)
            {
                while (mmacros[j])
                {
-                   MMacro *m = mmacros[j];
-                   mmacros[j] = m->next;
-                   free_mmacro(m);
+                   MMacro *m2 = mmacros[j];
+                   mmacros[j] = m2->next;
+                   free_mmacro(m2);
                }
                while (smacros[j])
                {
@@ -2136,8 +2134,8 @@ do_directive(Token * tline)
            inc->next = istk;
            inc->conds = NULL;
            inc->fp = inc_fopen(p);
-           inc->fname = src_set_fname(p);
-           inc->lineno = src_set_linnum(0);
+           inc->fname = nasm_src_set_fname(p);
+           inc->lineno = nasm_src_set_linnum(0);
            inc->lineinc = 1;
            inc->expansion = NULL;
            inc->mstk = NULL;
@@ -2353,7 +2351,7 @@ do_directive(Token * tline)
            else
            {
                defining->nparam_min = defining->nparam_max =
-                       readnum(tline->text, &j);
+                       nasm_readnum(tline->text, &j);
                if (j)
                    error(ERR_NONFATAL,
                            "unable to parse parameter count `%s'",
@@ -2370,7 +2368,7 @@ do_directive(Token * tline)
                            (i == PP_IMACRO ? "i" : ""));
                else
                {
-                   defining->nparam_max = readnum(tline->text, &j);
+                   defining->nparam_max = nasm_readnum(tline->text, &j);
                    if (j)
                        error(ERR_NONFATAL,
                                "unable to parse parameter count `%s'",
@@ -2464,7 +2462,7 @@ do_directive(Token * tline)
            if (tokval.t_type)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL, "non-constant value given to `%%rotate'");
                return DIRECTIVE_FOUND;
@@ -2484,7 +2482,7 @@ do_directive(Token * tline)
            }
            else
            {
-               mmac->rotate = mmac->rotate + reloc_value(evalresult);
+               mmac->rotate = mmac->rotate + nasm_reloc_value(evalresult);
                
                if (mmac->rotate < 0)
                    mmac->rotate = 
@@ -2518,7 +2516,7 @@ do_directive(Token * tline)
            if (tokval.t_type)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL, "non-constant value given to `%%rep'");
                return DIRECTIVE_FOUND;
@@ -2529,7 +2527,7 @@ do_directive(Token * tline)
            defining->casesense = 0;
            defining->plus = FALSE;
            defining->nolist = nolist;
-           defining->in_progress = reloc_value(evalresult) + 1;
+           defining->in_progress = nasm_reloc_value(evalresult) + 1;
            defining->nparam_min = defining->nparam_max = 0;
            defining->defaults = NULL;
            defining->dlist = NULL;
@@ -2901,7 +2899,7 @@ do_directive(Token * tline)
                free_tlist(origline);
                return DIRECTIVE_FOUND;
            }
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL, "non-constant value given to `%%substr`");
                free_tlist(tline);
@@ -3003,7 +3001,7 @@ do_directive(Token * tline)
                error(ERR_WARNING,
                        "trailing garbage after expression ignored");
 
-           if (!is_simple(evalresult))
+           if (!nasm_is_simple(evalresult))
            {
                error(ERR_NONFATAL,
                        "non-constant value given to `%%%sassign'",
@@ -3014,7 +3012,7 @@ do_directive(Token * tline)
 
            macro_start = nasm_malloc(sizeof(*macro_start));
            macro_start->next = NULL;
-           make_tok_num(macro_start, reloc_value(evalresult));
+           make_tok_num(macro_start, nasm_reloc_value(evalresult));
            macro_start->mac = NULL;
 
            /*
@@ -3065,7 +3063,7 @@ do_directive(Token * tline)
                free_tlist(origline);
                return DIRECTIVE_FOUND;
            }
-           k = readnum(tline->text, &j);
+           k = nasm_readnum(tline->text, &j);
            m = 1;
            tline = tline->next;
            if (tok_is_(tline, "+"))
@@ -3077,15 +3075,15 @@ do_directive(Token * tline)
                    free_tlist(origline);
                    return DIRECTIVE_FOUND;
                }
-               m = readnum(tline->text, &j);
+               m = nasm_readnum(tline->text, &j);
                tline = tline->next;
            }
            skip_white_(tline);
-           src_set_linnum(k);
+           nasm_src_set_linnum(k);
            istk->lineinc = m;
            if (tline)
            {
-               nasm_free(src_set_fname(detoken(tline, FALSE)));
+               nasm_free(nasm_src_set_fname(detoken(tline, FALSE)));
            }
            free_tlist(origline);
            return DIRECTIVE_FOUND;
@@ -3409,7 +3407,7 @@ expand_smacro(Token * tline)
                        if (!strcmp("__FILE__", m->name))
                        {
                            long num = 0;
-                           src_get(&num, &(tline->text));
+                           nasm_src_get(&num, &(tline->text));
                            nasm_quote(&(tline->text));
                            tline->type = TOK_STRING;
                            continue;
@@ -3417,7 +3415,7 @@ expand_smacro(Token * tline)
                        if (!strcmp("__LINE__", m->name))
                        {
                            nasm_free(tline->text);
-                           make_tok_num(tline, src_get_linnum());
+                           make_tok_num(tline, nasm_src_get_linnum());
                            continue;
                        }
                        tline = delete_Token(tline);
@@ -4058,7 +4056,7 @@ error(int severity, const char *fmt, ...)
 }
 
 static void
-pp_reset(char *file, int apass, efunc errfunc, evalfunc eval,
+pp_reset(FILE *f, const char *file, int apass, efunc errfunc, evalfunc eval,
        ListGen * listgen)
 {
     int h;
@@ -4070,13 +4068,11 @@ pp_reset(char *file, int apass, efunc errfunc, evalfunc eval,
     istk->conds = NULL;
     istk->expansion = NULL;
     istk->mstk = NULL;
-    istk->fp = fopen(file, "r");
+    istk->fp = f;
     istk->fname = NULL;
-    src_set_fname(nasm_strdup(file));
-    src_set_linnum(0);
+    nasm_src_set_fname(nasm_strdup(file));
+    nasm_src_set_linnum(0);
     istk->lineinc = 1;
-    if (!istk->fp)
-       error(ERR_FATAL | ERR_NOFILE, "unable to open input file `%s'", file);
     defining = NULL;
     for (h = 0; h < NHASH; h++)
     {
@@ -4232,8 +4228,8 @@ pp_getline(void)
                /* only set line and file name if there's a next node */
                if (i->next) 
                {
-                   src_set_linnum(i->lineno);
-                   nasm_free(src_set_fname(i->fname));
+                   nasm_src_set_linnum(i->lineno);
+                   nasm_free(nasm_src_set_fname(i->fname));
                }
                istk = i->next;
                list->downlevel(LIST_INCLUDE);
@@ -4324,7 +4320,7 @@ pp_getline(void)
 }
 
 static void
-pp_cleanup(int pass)
+pp_cleanup(int pass_)
 {
     int h;
 
@@ -4363,7 +4359,7 @@ pp_cleanup(int pass)
     }
     while (cstk)
        ctx_pop();
-    if (pass == 0)
+    if (pass_ == 0)
        {
                free_llist(predef);
                delete_Blocks();
index 0b7df114e62db8b67438e776cd186aad415e1a4d..82a1569c049bc250b3950c817eae741916dfb9f5 100644 (file)
@@ -6,8 +6,8 @@
  * distributed in the NASM archive.
  */
 
-#ifndef NASM_PREPROC_H
-#define NASM_PREPROC_H
+#ifndef YASM_NASM_PREPROC_H
+#define YASM_NASM_PREPROC_H
 
 void pp_include_path (char *);
 void pp_pre_include (char *);
diff --git a/src/preprocs/nasm/nasm-preproc.c b/src/preprocs/nasm/nasm-preproc.c
new file mode 100644 (file)
index 0000000..38c2aea
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Imported NASM preprocessor - glue code
+ *
+ *  Copyright (C) 2002  Peter Johnson
+ *
+ *  This file is part of YASM.
+ *
+ *  YASM is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  YASM is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include "util.h"
+/*@unused@*/ RCSID("$IdPath$");
+
+#include "errwarn.h"
+#include "linemgr.h"
+
+#include "preproc.h"
+#include "nasm.h"
+#include "nasmlib.h"
+#include "nasm-pp.h"
+#include "nasm-eval.h"
+
+static FILE *in;
+static linemgr *cur_lm;
+static errwarn *cur_we;
+static char *line, *linepos;
+static size_t lineleft;
+static char *file_name;
+static long prior_linnum;
+static int lineinc;
+int tasm_compatible_mode = 0;
+
+
+static void
+nil_listgen_init(char *p, efunc e)
+{
+}
+
+static void
+nil_listgen_cleanup(void)
+{
+}
+
+static void
+nil_listgen_output(long v, const void *d, unsigned long v2)
+{
+}
+
+static void
+nil_listgen_line(int v, char *p)
+{
+}
+
+static void
+nil_listgen_uplevel(int v)
+{
+}
+
+static void
+nil_listgen_downlevel(int v)
+{
+}
+
+static ListGen nil_list = {
+    nil_listgen_init,
+    nil_listgen_cleanup,
+    nil_listgen_output,
+    nil_listgen_line,
+    nil_listgen_uplevel,
+    nil_listgen_downlevel
+};
+
+
+static void
+nasm_efunc(int severity, const char *fmt, ...)
+{
+    va_list va;
+
+    va_start(va, fmt);
+    switch (severity & ERR_MASK) {
+       case ERR_WARNING:
+           cur_we->warning_va(WARN_PREPROC, cur_lm->get_current(), fmt, va);
+           break;
+       case ERR_NONFATAL:
+           cur_we->error_va(cur_lm->get_current(), fmt, va);
+           break;
+       case ERR_FATAL:
+           cur_we->fatal(FATAL_UNKNOWN);   /* FIXME */
+           break;
+       case ERR_PANIC:
+           cur_we->internal_error(fmt);    /* FIXME */
+           break;
+       case ERR_DEBUG:
+           break;
+    }
+    va_end(va);
+}
+
+static void
+nasm_preproc_initialize(FILE *f, const char *in_filename, linemgr *lm,
+                       errwarn *we)
+{
+    in = f;
+    cur_lm = lm;
+    cur_we = we;
+    line = NULL;
+    file_name = NULL;
+    prior_linnum = 0;
+    lineinc = 0;
+    nasmpp.reset(f, in_filename, 2, nasm_efunc, nasm_evaluate, &nil_list);
+}
+
+static void
+nasm_preproc_cleanup(void)
+{
+    nasmpp.cleanup(0);
+}
+
+static size_t
+nasm_preproc_input(char *buf, size_t max_size)
+{
+    size_t tot = 0, n;
+    long linnum = prior_linnum += lineinc;
+    int altline;
+
+    if (!line) {
+       line = nasmpp.getline();
+       if (!line)
+           return 0;
+       linepos = line;
+       lineleft = strlen(line) + 1;
+       line[lineleft-1] = '\n';
+    }
+
+    altline = nasm_src_get(&linnum, &file_name);
+    if (altline) {
+       if (altline == 1 && lineinc == 1) {
+           *buf++ = '\n';
+           max_size--;
+           tot++;
+       } else {
+           lineinc = (altline != -1 || lineinc != 1);
+           n = sprintf(buf, "%%line %ld+%d %s\n", linnum, lineinc, file_name);
+           buf += n;
+           max_size -= n;
+           tot += n;
+       }
+       prior_linnum = linnum;
+    }
+
+    n = lineleft<max_size?lineleft:max_size;
+    strncpy(buf, linepos, n);
+    tot += n;
+
+    if (n == lineleft) {
+       xfree(line);
+       line = NULL;
+    } else {
+       lineleft -= n;
+       linepos += n;
+    }
+
+    return tot;
+}
+
+
+/* Define preproc structure -- see preproc.h for details */
+preproc yasm_nasm_LTX_preproc = {
+    "Real NASM Preprocessor",
+    "nasm",
+    nasm_preproc_initialize,
+    nasm_preproc_cleanup,
+    nasm_preproc_input
+};
index 8f4f293c562401b3724775ea1315a34b4840bfb2..890991b9785f53144cb1c6bf85da0c3196aa7785 100644 (file)
@@ -7,12 +7,8 @@
  *
  * initial version: 27/iii/95 by Simon Tatham
  */
-
-#ifndef NASM_NASM_H
-#define NASM_NASM_H
-
-#include <stdio.h>
-#include "version.h"                  /* generated NASM version macros */
+#ifndef YASM_NASM_H
+#define YASM_NASM_H
 
 #ifndef NULL
 #define NULL 0
@@ -237,7 +233,7 @@ typedef struct {
 typedef struct {
     long type;                        /* a register, or EXPR_xxx */
     long value;                               /* must be >= 32 bits */
-} expr;
+} nasm_expr;
 
 /*
  * The evaluator can also return hints about which of two registers
@@ -274,7 +270,7 @@ struct eval_hints {
  * the base register in complex effective addresses.
  */
 #define CRITICAL 0x100
-typedef expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv,
+typedef nasm_expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv,
                           int *fwref, int critical, efunc error,
                           struct eval_hints *hints);
 
@@ -300,7 +296,7 @@ typedef struct {
      * of the pass, an error reporting function, an evaluator
      * function, and a listing generator to talk to.
      */
-    void (*reset) (char *, int, efunc, evalfunc, ListGen *);
+    void (*reset) (FILE *, const char *, int, efunc, evalfunc, ListGen *);
 
     /*
      * Called to fetch a line of preprocessed source. The line
@@ -429,16 +425,17 @@ enum {
 #define UNITY     0x00802000L         /* for shift/rotate instructions */
 #define BYTENESS  0x40000000L          /* so SBYTE == IMMEDIATE | BYTENESS */
 #define SBYTE    0x40002000L          /* for op r16/32,immediate instrs. */
-               
+       
+
 /* Register names automatically generated from regs.dat */
-#include "regs.h"
+/*#include "regs.h"*/
 
 enum {                                /* condition code names */
     C_A, C_AE, C_B, C_BE, C_C, C_E, C_G, C_GE, C_L, C_LE, C_NA, C_NAE,
     C_NB, C_NBE, C_NC, C_NE, C_NG, C_NGE, C_NL, C_NLE, C_NO, C_NP,
     C_NS, C_NZ, C_O, C_P, C_PE, C_PO, C_S, C_Z
 };
-
+#if 0
 /*
  * Note that because segment registers may be used as instruction
  * prefixes, we must ensure the enumerations for prefixes and
@@ -449,7 +446,7 @@ enum {                                     /* instruction prefixes */
     P_A16 = PREFIX_ENUM_START, P_A32, P_LOCK, P_O16, P_O32, P_REP, P_REPE,
     P_REPNE, P_REPNZ, P_REPZ, P_TIMES
 };
-
+#endif
 enum {                                /* extended operand types */
     EOT_NOTHING, EOT_DB_STRING, EOT_DB_NUMBER
 };
index bb0ab29e0e14dabc93569c5f3519e6dfd6da4f47..5eb2be1a7500c62d6c4a0f1c3376372dad7f5f94 100644 (file)
  * redistributable under the licence given in the file "Licence"
  * distributed in the NASM archive.
  */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "util.h"
 #include <ctype.h>
 
 #include "nasm.h"
 #include "nasmlib.h"
-#include "insns.h"             /* For MAX_KEYWORD */
-
-static efunc nasm_malloc_error;
-
-#ifdef LOGALLOC
-static FILE *logfp;
-#endif
-
-void nasm_set_malloc_error (efunc error) 
-{
-    nasm_malloc_error = error;
-#ifdef LOGALLOC
-    logfp = fopen ("malloc.log", "w");
-    setvbuf (logfp, NULL, _IOLBF, BUFSIZ);
-    fprintf (logfp, "null pointer is %p\n", NULL);
-#endif
-}
-
-#ifdef LOGALLOC
-void *nasm_malloc_log (char *file, int line, size_t size)
-#else
-void *nasm_malloc (size_t size)
-#endif
-{
-    void *p = malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else
-       fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    return p;
-}
-
-#ifdef LOGALLOC
-void *nasm_realloc_log (char *file, int line, void *q, size_t size)
-#else
-void *nasm_realloc (void *q, size_t size)
-#endif
-{
-    void *p = q ? realloc(q, size) : malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else if (q)
-       fprintf(logfp, "%s %d realloc(%p,%ld) returns %p\n",
-               file, line, q, (long)size, p);
-    else
-       fprintf(logfp, "%s %d malloc(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    return p;
-}
-
-#ifdef LOGALLOC
-void nasm_free_log (char *file, int line, void *q)
-#else
-void nasm_free (void *q)
-#endif
-{
-    if (q) {
-       free (q);
-#ifdef LOGALLOC
-       fprintf(logfp, "%s %d free(%p)\n",
-               file, line, q);
-#endif
-    }
-}
-
-#ifdef LOGALLOC
-char *nasm_strdup_log (char *file, int line, const char *s)
-#else
-char *nasm_strdup (const char *s)
-#endif
-{
-    char *p;
-    int size = strlen(s)+1;
-
-    p = malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else
-       fprintf(logfp, "%s %d strdup(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    strcpy (p, s);
-    return p;
-}
-
-#ifdef LOGALLOC
-char *nasm_strndup_log (char *file, int line, char *s, size_t len)
-#else
-char *nasm_strndup (char *s, size_t len)
-#endif
-{
-    char *p;
-    int size = len+1;
-
-    p = malloc(size);
-    if (!p)
-       nasm_malloc_error (ERR_FATAL | ERR_NOFILE, "out of memory");
-#ifdef LOGALLOC
-    else
-       fprintf(logfp, "%s %d strndup(%ld) returns %p\n",
-               file, line, (long)size, p);
-#endif
-    strncpy (p, s, len);
-    p[len] = '\0';
-    return p;
-}
-
-#if !defined(stricmp) && !defined(strcasecmp)
-int nasm_stricmp (const char *s1, const char *s2) 
-{
-    while (*s1 && tolower(*s1) == tolower(*s2))
-       s1++, s2++;
-    if (!*s1 && !*s2)
-       return 0;
-    else if (tolower(*s1) < tolower(*s2))
-       return -1;
-    else
-       return 1;
-}
-#endif
-
-#if !defined(strnicmp) && !defined(strncasecmp)
-int nasm_strnicmp (const char *s1, const char *s2, int n) 
-{
-    while (n > 0 && *s1 && tolower(*s1) == tolower(*s2))
-       s1++, s2++, n--;
-    if ((!*s1 && !*s2) || n==0)
-       return 0;
-    else if (tolower(*s1) < tolower(*s2))
-       return -1;
-    else
-       return 1;
-}
-#endif
+/*#include "insns.h"*/         /* For MAX_KEYWORD */
 
 #define lib_isnumchar(c)   ( isalnum(c) || (c) == '$')
 #define numvalue(c)  ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
 
-long readnum (char *str, int *error) 
+long nasm_readnum (char *str, int *error) 
 {
     char *r = str, *q;
     long radix;
@@ -243,16 +101,16 @@ long readnum (char *str, int *error)
        result = radix * result + digit;
        r++;
     }
-
+#if 0
     if (warn)
        nasm_malloc_error (ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV,
                           "numeric constant %s does not fit in 32 bits",
                           str);
-
+#endif
     return result*sign;
 }
 
-long readstrnum (char *str, int length, int *warn) 
+long nasm_readstrnum (char *str, int length, int *warn) 
 {
     long charconst = 0;
     int i;
@@ -271,603 +129,21 @@ long readstrnum (char *str, int length, int *warn)
 
 static long next_seg;
 
-void seg_init(void) 
+void nasm_seg_init(void) 
 {
     next_seg = 0;
 }
 
-long seg_alloc(void) 
+long nasm_seg_alloc(void) 
 {
     return (next_seg += 2) - 2;
 }
 
-void fwriteshort (int data, FILE *fp) 
-{
-    fputc ((int) (data & 255), fp);
-    fputc ((int) ((data >> 8) & 255), fp);
-}
-
-void fwritelong (long data, FILE *fp) 
-{
-    fputc ((int) (data & 255), fp);
-    fputc ((int) ((data >> 8) & 255), fp);
-    fputc ((int) ((data >> 16) & 255), fp);
-    fputc ((int) ((data >> 24) & 255), fp);
-}
-
-void standard_extension (char *inname, char *outname, char *extension,
-                        efunc error) 
-{
-    char *p, *q;
-
-    if (*outname)                     /* file name already exists, */
-       return;                        /* so do nothing */
-    q = inname;
-    p = outname;
-    while (*q) *p++ = *q++;           /* copy, and find end of string */
-    *p = '\0';                        /* terminate it */
-    while (p > outname && *--p != '.');/* find final period (or whatever) */
-    if (*p != '.') while (*p) p++;     /* go back to end if none found */
-    if (!strcmp(p, extension)) {       /* is the extension already there? */
-       if (*extension)
-           error(ERR_WARNING | ERR_NOFILE,
-                 "file name already ends in `%s': "
-                 "output will be in `nasm.out'",
-                 extension);
-       else
-           error(ERR_WARNING | ERR_NOFILE,
-                 "file name already has no extension: "
-                 "output will be in `nasm.out'");
-       strcpy(outname, "nasm.out");
-    } else
-       strcpy(p, extension);
-}
-
-#define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
-#define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
-
-#define LAYERSIZ(r) ( (r)->layers==0 ? RAA_BLKSIZE : RAA_LAYERSIZE )
-
-static struct RAA *real_raa_init (int layers) 
-{
-    struct RAA *r;
-    int i;
-
-    if (layers == 0) {
-       r = nasm_malloc (LEAFSIZ);
-       r->layers = 0;
-       memset (r->u.l.data, 0, sizeof(r->u.l.data));
-       r->stepsize = 1L;
-    } else {
-       r = nasm_malloc (BRANCHSIZ);
-       r->layers = layers;
-       for ( i = 0 ; i < RAA_LAYERSIZE ; i++ )
-         r->u.b.data[i] = NULL;
-       r->stepsize = RAA_BLKSIZE;
-       while (--layers)
-           r->stepsize *= RAA_LAYERSIZE;
-    }
-    return r;
-}
-
-struct RAA *raa_init (void) 
-{
-    return real_raa_init (0);
-}
-
-void raa_free (struct RAA *r) 
-{
-    if (r->layers == 0)
-       nasm_free (r);
-    else {
-       struct RAA **p;
-       for (p = r->u.b.data; p - r->u.b.data < RAA_LAYERSIZE; p++)
-           if (*p)
-               raa_free (*p);
-    }
-}
-
-long raa_read (struct RAA *r, long posn) 
-{
-    if (posn >= r->stepsize * LAYERSIZ(r))
-       return 0;               /* Return 0 for undefined entries */
-    while (r->layers > 0) {
-       ldiv_t l;
-       l = ldiv (posn, r->stepsize);
-       r = r->u.b.data[l.quot];
-       posn = l.rem;
-       if (!r)
-           return 0;           /* Return 0 for undefined entries */
-    }
-    return r->u.l.data[posn];
-}
-
-struct RAA *raa_write (struct RAA *r, long posn, long value) 
-{
-    struct RAA *result;
-
-    if (posn < 0)
-       nasm_malloc_error (ERR_PANIC, "negative position in raa_write");
-
-    while (r->stepsize * LAYERSIZ(r) <= posn) {
-       /*
-        * Must add a layer.
-        */
-       struct RAA *s;
-       int i;
-
-       s = nasm_malloc (BRANCHSIZ);
-       for ( i = 0 ; i < RAA_LAYERSIZE ; i++ )
-           s->u.b.data[i] = NULL;
-       s->layers = r->layers + 1;
-       s->stepsize = LAYERSIZ(r) * r->stepsize;
-       s->u.b.data[0] = r;
-       r = s;
-    }
-
-    result = r;
-
-    while (r->layers > 0) {
-       ldiv_t l;
-       struct RAA **s;
-       l = ldiv (posn, r->stepsize);
-       s = &r->u.b.data[l.quot];
-       if (!*s)
-           *s = real_raa_init (r->layers - 1);
-       r = *s;
-       posn = l.rem;
-    }
-
-    r->u.l.data[posn] = value;
-
-    return result;
-}
-
-#define SAA_MAXLEN 8192
-
-struct SAA *saa_init (long elem_len) 
-{
-    struct SAA *s;
-
-    if (elem_len > SAA_MAXLEN)
-       nasm_malloc_error (ERR_PANIC | ERR_NOFILE, "SAA with huge elements");
-
-    s = nasm_malloc (sizeof(struct SAA));
-    s->posn = s->start = 0L;
-    s->elem_len = elem_len;
-    s->length = SAA_MAXLEN - (SAA_MAXLEN % elem_len);
-    s->data = nasm_malloc (s->length);
-    s->next = NULL;
-    s->end = s;
-
-    return s;
-}
-
-void saa_free (struct SAA *s) 
-{
-    struct SAA *t;
-
-    while (s) {
-       t = s->next;
-       nasm_free (s->data);
-       nasm_free (s);
-       s = t;
-    }
-}
-
-void *saa_wstruct (struct SAA *s) 
-{
-    void *p;
-
-    if (s->end->length - s->end->posn < s->elem_len) {
-       s->end->next = nasm_malloc (sizeof(struct SAA));
-       s->end->next->start = s->end->start + s->end->posn;
-       s->end = s->end->next;
-       s->end->length = s->length;
-       s->end->next = NULL;
-       s->end->posn = 0L;
-       s->end->data = nasm_malloc (s->length);
-    }
-
-    p = s->end->data + s->end->posn;
-    s->end->posn += s->elem_len;
-    return p;
-}
-
-void saa_wbytes (struct SAA *s, const void *data, long len) 
-{
-    const char *d = data;
-
-    while (len > 0) {
-       long l = s->end->length - s->end->posn;
-       if (l > len)
-           l = len;
-       if (l > 0) {
-           if (d) {
-               memcpy (s->end->data + s->end->posn, d, l);
-               d += l;
-           } else
-               memset (s->end->data + s->end->posn, 0, l);
-           s->end->posn += l;
-           len -= l;
-       }
-       if (len > 0) {
-           s->end->next = nasm_malloc (sizeof(struct SAA));
-           s->end->next->start = s->end->start + s->end->posn;
-           s->end = s->end->next;
-           s->end->length = s->length;
-           s->end->next = NULL;
-           s->end->posn = 0L;
-           s->end->data = nasm_malloc (s->length);
-       }
-    }
-}
-
-void saa_rewind (struct SAA *s) 
-{
-    s->rptr = s;
-    s->rpos = 0L;
-}
-
-void *saa_rstruct (struct SAA *s) 
-{
-    void *p;
-
-    if (!s->rptr)
-       return NULL;
-
-    if (s->rptr->posn - s->rpos < s->elem_len) {
-       s->rptr = s->rptr->next;
-       if (!s->rptr)
-           return NULL;               /* end of array */
-       s->rpos = 0L;
-    }
-
-    p = s->rptr->data + s->rpos;
-    s->rpos += s->elem_len;
-    return p;
-}
-
-void *saa_rbytes (struct SAA *s, long *len) 
-{
-    void *p;
-
-    if (!s->rptr)
-       return NULL;
-
-    p = s->rptr->data + s->rpos;
-    *len = s->rptr->posn - s->rpos;
-    s->rptr = s->rptr->next;
-    s->rpos = 0L;
-    return p;
-}
-
-void saa_rnbytes (struct SAA *s, void *data, long len) 
-{
-    char *d = data;
-
-    while (len > 0) {
-       long l;
-
-       if (!s->rptr)
-           return;
-
-       l = s->rptr->posn - s->rpos;
-       if (l > len)
-           l = len;
-       if (l > 0) {
-           memcpy (d, s->rptr->data + s->rpos, l);
-           d += l;
-           s->rpos += l;
-           len -= l;
-       }
-       if (len > 0) {
-           s->rptr = s->rptr->next;
-           s->rpos = 0L;
-       }
-    }
-}
-
-void saa_fread (struct SAA *s, long posn, void *data, long len) 
-{
-    struct SAA *p;
-    long pos;
-    char *cdata = data;
-
-    if (!s->rptr || posn < s->rptr->start)
-       saa_rewind (s);
-    p = s->rptr;
-    while (posn >= p->start + p->posn) {
-       p = p->next;
-       if (!p)
-           return;                    /* what else can we do?! */
-    }
-
-    pos = posn - p->start;
-    while (len) {
-       long l = p->posn - pos;
-       if (l > len)
-           l = len;
-       memcpy (cdata, p->data+pos, l);
-       len -= l;
-       cdata += l;
-       p = p->next;
-       if (!p)
-           return;
-       pos = 0L;
-    }
-    s->rptr = p;
-}
-
-void saa_fwrite (struct SAA *s, long posn, void *data, long len) 
-{
-    struct SAA *p;
-    long pos;
-    char *cdata = data;
-
-    if (!s->rptr || posn < s->rptr->start)
-       saa_rewind (s);
-    p = s->rptr;
-    while (posn >= p->start + p->posn) {
-       p = p->next;
-       if (!p)
-           return;                    /* what else can we do?! */
-    }
-
-    pos = posn - p->start;
-    while (len) {
-       long l = p->posn - pos;
-       if (l > len)
-           l = len;
-       memcpy (p->data+pos, cdata, l);
-       len -= l;
-       cdata += l;
-       p = p->next;
-       if (!p)
-           return;
-       pos = 0L;
-    }
-    s->rptr = p;
-}
-
-void saa_fpwrite (struct SAA *s, FILE *fp) 
-{
-    char *data;
-    long len;
-
-    saa_rewind (s);
-    while ( (data = saa_rbytes (s, &len)) )
-       fwrite (data, 1, len, fp);
-}
-
-/*
- * Register, instruction, condition-code and prefix keywords used
- * by the scanner.
- */
-#include "names.c"
-static const char *special_names[] = {
-    "byte", "dword", "far", "long", "near", "nosplit", "qword",
-    "short", "strict", "to", "tword", "word"
-};
-static const char *prefix_names[] = {
-    "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
-    "repnz", "repz", "times"
-};
-
-
-/*
- * Standard scanner routine used by parser.c and some output
- * formats. It keeps a succession of temporary-storage strings in
- * stdscan_tempstorage, which can be cleared using stdscan_reset.
- */
-static char **stdscan_tempstorage = NULL;
-static int stdscan_tempsize = 0, stdscan_templen = 0;
-#define STDSCAN_TEMP_DELTA 256
-
-static void stdscan_pop(void) 
-{
-    nasm_free (stdscan_tempstorage[--stdscan_templen]);
-}
-
-void stdscan_reset(void) 
-{
-    while (stdscan_templen > 0)
-       stdscan_pop();
-}
-
-/*
- * Unimportant cleanup is done to avoid confusing people who are trying
- * to debug real memory leaks
- */
-void nasmlib_cleanup (void) 
-{
-    stdscan_reset();
-    nasm_free (stdscan_tempstorage);
-}
-
-static char *stdscan_copy(char *p, int len) 
-{
-    char *text;
-
-    text = nasm_malloc(len+1);
-    strncpy (text, p, len);
-    text[len] = '\0';
-
-    if (stdscan_templen >= stdscan_tempsize) {
-       stdscan_tempsize += STDSCAN_TEMP_DELTA;
-       stdscan_tempstorage = nasm_realloc(stdscan_tempstorage,
-                                          stdscan_tempsize*sizeof(char *));
-    }
-    stdscan_tempstorage[stdscan_templen++] = text;
-
-    return text;
-}
-
-char *stdscan_bufptr = NULL;
-int stdscan (void *private_data, struct tokenval *tv) 
-{
-    char ourcopy[MAX_KEYWORD+1], *r, *s;
-
-    (void) private_data;  /* Don't warn that this parameter is unused */
-
-    while (isspace(*stdscan_bufptr)) stdscan_bufptr++;
-    if (!*stdscan_bufptr)
-       return tv->t_type = 0;
-
-    /* we have a token; either an id, a number or a char */
-    if (isidstart(*stdscan_bufptr) ||
-       (*stdscan_bufptr == '$' && isidstart(stdscan_bufptr[1]))) {
-       /* now we've got an identifier */
-       int i;
-       int is_sym = FALSE;
-
-       if (*stdscan_bufptr == '$') {
-           is_sym = TRUE;
-           stdscan_bufptr++;
-       }
-
-       r = stdscan_bufptr++;
-       while (isidchar(*stdscan_bufptr)) stdscan_bufptr++;
-       tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
-
-       if (is_sym || stdscan_bufptr-r > MAX_KEYWORD)
-           return tv->t_type = TOKEN_ID;/* bypass all other checks */
-    
-       for (s=tv->t_charptr, r=ourcopy; *s; s++)
-           *r++ = tolower (*s);
-       *r = '\0';
-       /* right, so we have an identifier sitting in temp storage. now,
-        * is it actually a register or instruction name, or what? */
-       if ((tv->t_integer=bsi(ourcopy, reg_names,
-                              elements(reg_names)))>=0) {
-           tv->t_integer += EXPR_REG_START;
-           return tv->t_type = TOKEN_REG;
-       } else if ((tv->t_integer=bsi(ourcopy, insn_names,
-                                     elements(insn_names)))>=0) {
-           return tv->t_type = TOKEN_INSN;
-       }
-       for (i=0; i<elements(icn); i++)
-           if (!strncmp(ourcopy, icn[i], strlen(icn[i]))) {
-               char *p = ourcopy + strlen(icn[i]);
-               tv->t_integer = ico[i];
-               if ((tv->t_inttwo=bsi(p, conditions,
-                                        elements(conditions)))>=0)
-                   return tv->t_type = TOKEN_INSN;
-           }
-       if ((tv->t_integer=bsi(ourcopy, prefix_names,
-                                 elements(prefix_names)))>=0) {
-           tv->t_integer += PREFIX_ENUM_START;
-           return tv->t_type = TOKEN_PREFIX;
-       }
-       if ((tv->t_integer=bsi(ourcopy, special_names,
-                                 elements(special_names)))>=0)
-           return tv->t_type = TOKEN_SPECIAL;
-       if (!nasm_stricmp(ourcopy, "seg"))
-           return tv->t_type = TOKEN_SEG;
-       if (!nasm_stricmp(ourcopy, "wrt"))
-           return tv->t_type = TOKEN_WRT;
-       return tv->t_type = TOKEN_ID;
-    } else if (*stdscan_bufptr == '$' && !isnumchar(stdscan_bufptr[1])) {
-       /*
-        * It's a $ sign with no following hex number; this must
-        * mean it's a Here token ($), evaluating to the current
-        * assembly location, or a Base token ($$), evaluating to
-        * the base of the current segment.
-        */
-       stdscan_bufptr++;
-       if (*stdscan_bufptr == '$') {
-           stdscan_bufptr++;
-           return tv->t_type = TOKEN_BASE;
-       }
-       return tv->t_type = TOKEN_HERE;
-    } else if (isnumstart(*stdscan_bufptr)) {  /* now we've got a number */
-       int rn_error;
-
-       r = stdscan_bufptr++;
-       while (isnumchar(*stdscan_bufptr))
-           stdscan_bufptr++;
-
-       if (*stdscan_bufptr == '.') {
-           /*
-            * a floating point constant
-            */
-           stdscan_bufptr++;
-           while (isnumchar(*stdscan_bufptr) ||
-                  ((stdscan_bufptr[-1] == 'e' || stdscan_bufptr[-1] == 'E')
-                   && (*stdscan_bufptr == '-' || *stdscan_bufptr == '+')) ) 
-           {
-               stdscan_bufptr++;
-           }
-           tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
-           return tv->t_type = TOKEN_FLOAT;
-       }
-       r = stdscan_copy(r, stdscan_bufptr - r);
-       tv->t_integer = readnum(r, &rn_error);
-       stdscan_pop();
-       if (rn_error)
-           return tv->t_type = TOKEN_ERRNUM;/* some malformation occurred */
-       tv->t_charptr = NULL;
-       return tv->t_type = TOKEN_NUM;
-    } else if (*stdscan_bufptr == '\'' ||
-              *stdscan_bufptr == '"') {/* a char constant */
-       char quote = *stdscan_bufptr++, *r;
-       int rn_warn;
-       r = tv->t_charptr = stdscan_bufptr;
-       while (*stdscan_bufptr && *stdscan_bufptr != quote) stdscan_bufptr++;
-       tv->t_inttwo = stdscan_bufptr - r;      /* store full version */
-       if (!*stdscan_bufptr)
-           return tv->t_type = TOKEN_ERRNUM;       /* unmatched quotes */
-       stdscan_bufptr++;                       /* skip over final quote */
-       tv->t_integer = readstrnum(r, tv->t_inttwo, &rn_warn);
-       /* FIXME: rn_warn is not checked! */
-       return tv->t_type = TOKEN_NUM;
-    } else if (*stdscan_bufptr == ';') {  /* a comment has happened - stay */
-       return tv->t_type = 0;
-    } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '>') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SHR;
-    } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '<') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SHL;
-    } else if (stdscan_bufptr[0] == '/' && stdscan_bufptr[1] == '/') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SDIV;
-    } else if (stdscan_bufptr[0] == '%' && stdscan_bufptr[1] == '%') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_SMOD;
-    } else if (stdscan_bufptr[0] == '=' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_EQ;
-    } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '>') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_NE;
-    } else if (stdscan_bufptr[0] == '!' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_NE;
-    } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_LE;
-    } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '=') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_GE;
-    } else if (stdscan_bufptr[0] == '&' && stdscan_bufptr[1] == '&') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_DBL_AND;
-    } else if (stdscan_bufptr[0] == '^' && stdscan_bufptr[1] == '^') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_DBL_XOR;
-    } else if (stdscan_bufptr[0] == '|' && stdscan_bufptr[1] == '|') {
-       stdscan_bufptr += 2;
-       return tv->t_type = TOKEN_DBL_OR;
-    } else                            /* just an ordinary char */
-       return tv->t_type = (unsigned char) (*stdscan_bufptr++);
-}
-
 /*
  * Return TRUE if the argument is a simple scalar. (Or a far-
  * absolute, which counts.)
  */
-int is_simple (expr *vect) 
+int nasm_is_simple (nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -886,7 +162,7 @@ int is_simple (expr *vect)
  * Return TRUE if the argument is a simple scalar, _NOT_ a far-
  * absolute.
  */
-int is_really_simple (expr *vect) 
+int nasm_is_really_simple (nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -905,7 +181,7 @@ int is_really_simple (expr *vect)
  * Return TRUE if the argument is relocatable (i.e. a simple
  * scalar, plus at most one segment-base, plus possibly a WRT).
  */
-int is_reloc (expr *vect) 
+int nasm_is_reloc (nasm_expr *vect) 
 {
     while (vect->type && !vect->value) /* skip initial value-0 terms */
        vect++;
@@ -940,7 +216,7 @@ int is_reloc (expr *vect)
 /*
  * Return TRUE if the argument contains an `unknown' part.
  */
-int is_unknown(expr *vect) 
+int nasm_is_unknown(nasm_expr *vect) 
 {
     while (vect->type && vect->type < EXPR_UNKNOWN)
        vect++;
@@ -951,7 +227,7 @@ int is_unknown(expr *vect)
  * Return TRUE if the argument contains nothing but an `unknown'
  * part.
  */
-int is_just_unknown(expr *vect) 
+int nasm_is_just_unknown(nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -962,7 +238,7 @@ int is_just_unknown(expr *vect)
  * Return the scalar part of a relocatable vector. (Including
  * simple scalar vectors - those qualify as relocatable.)
  */
-long reloc_value (expr *vect) 
+long nasm_reloc_value (nasm_expr *vect) 
 {
     while (vect->type && !vect->value)
        vect++;
@@ -977,7 +253,7 @@ long reloc_value (expr *vect)
  * Return the segment number of a relocatable vector, or NO_SEG for
  * simple scalars.
  */
-long reloc_seg (expr *vect) 
+long nasm_reloc_seg (nasm_expr *vect) 
 {
     while (vect->type && (vect->type == EXPR_WRT || !vect->value))
        vect++;
@@ -996,7 +272,7 @@ long reloc_seg (expr *vect)
  * Return the WRT segment number of a relocatable vector, or NO_SEG
  * if no WRT part is present.
  */
-long reloc_wrt (expr *vect) 
+long nasm_reloc_wrt (nasm_expr *vect) 
 {
     while (vect->type && vect->type < EXPR_WRT)
        vect++;
@@ -1009,7 +285,7 @@ long reloc_wrt (expr *vect)
 /*
  * Binary search.
  */
-int bsi (char *string, const char **array, int size) 
+int nasm_bsi (char *string, const char **array, int size) 
 {
     int i = -1, j = size;             /* always, i < index < j */
     while (j-i >= 2) {
@@ -1028,26 +304,26 @@ int bsi (char *string, const char **array, int size)
 static char *file_name = NULL;
 static long line_number = 0;
 
-char *src_set_fname(char *newname) 
+char *nasm_src_set_fname(char *newname) 
 {
     char *oldname = file_name;
     file_name = newname;
     return oldname;
 }
 
-long src_set_linnum(long newline) 
+long nasm_src_set_linnum(long newline) 
 {
     long oldline = line_number;
     line_number = newline;
     return oldline;
 }
 
-long src_get_linnum(void) 
+long nasm_src_get_linnum(void) 
 {
     return line_number;
 }
 
-int src_get(long *xline, char **xname) 
+int nasm_src_get(long *xline, char **xname) 
 {
     if (!file_name || !*xname || strcmp(*xname, file_name)) 
     {
@@ -1092,25 +368,3 @@ char *nasm_strcat(char *one, char *two)
     strcpy(rslt+l1, two);
     return rslt;
 }
-
-void null_debug_init(struct ofmt *of, void *id, FILE *fp, efunc error ) {}
-void null_debug_linenum(const char *filename, long linenumber, long segto) {}
-void null_debug_deflabel(char *name, long segment, long offset, int is_global, char *special) {}
-void null_debug_routine(const char *directive, const char *params) {}
-void null_debug_typevalue(long type) {}
-void null_debug_output(int type, void *param) {}
-void null_debug_cleanup(void){}
-
-struct dfmt null_debug_form = {
-    "Null debug format",
-    "null",
-    null_debug_init,
-    null_debug_linenum,
-    null_debug_deflabel,
-    null_debug_routine,
-    null_debug_typevalue,
-    null_debug_output,
-    null_debug_cleanup
-};
-
-struct dfmt *null_debug_arr[2] = { &null_debug_form, NULL };
index 54964539e9251c66dee922e28509b244bf0b3b6c..5163758d60113c268e7283927b6304009d8da8ca 100644 (file)
@@ -6,17 +6,8 @@
  * distributed in the NASM archive.
  */
 
-#ifndef NASM_NASMLIB_H
-#define NASM_NASMLIB_H
-
-/*
- * If this is defined, the wrappers around malloc et al will
- * transform into logging variants, which will cause NASM to create
- * a file called `malloc.log' when run, and spew details of all its
- * memory management into that. That can then be analysed to detect
- * memory leaks and potentially other problems too.
- */
-/* #define LOGALLOC */
+#ifndef YASM_NASMLIB_H
+#define YASM_NASMLIB_H
 
 /*
  * Wrappers around malloc, realloc and free. nasm_malloc will
  * passed a NULL pointer; nasm_free will do nothing if it is passed
  * a NULL pointer.
  */
-#ifdef NASM_NASM_H                    /* need efunc defined for this */
-void nasm_set_malloc_error (efunc);
-#ifndef LOGALLOC
-void *nasm_malloc (size_t);
-void *nasm_realloc (void *, size_t);
-void nasm_free (void *);
-char *nasm_strdup (const char *);
-char *nasm_strndup (char *, size_t);
-#else
-void *nasm_malloc_log (char *, int, size_t);
-void *nasm_realloc_log (char *, int, void *, size_t);
-void nasm_free_log (char *, int, void *);
-char *nasm_strdup_log (char *, int, const char *);
-char *nasm_strndup_log (char *, int, char *, size_t);
-#define nasm_malloc(x) nasm_malloc_log(__FILE__,__LINE__,x)
-#define nasm_realloc(x,y) nasm_realloc_log(__FILE__,__LINE__,x,y)
-#define nasm_free(x) nasm_free_log(__FILE__,__LINE__,x)
-#define nasm_strdup(x) nasm_strdup_log(__FILE__,__LINE__,x)
-#define nasm_strndup(x,y) nasm_strndup_log(__FILE__,__LINE__,x,y)
-#endif
-#endif
-
-/*
- * ANSI doesn't guarantee the presence of `stricmp' or
- * `strcasecmp'.
- */
-#if defined(stricmp) || defined(strcasecmp)
-#if defined(stricmp)
-#define nasm_stricmp stricmp
-#else
+#define nasm_malloc xmalloc
+#define nasm_realloc xrealloc
+#define nasm_free xfree
+#define nasm_strdup xstrdup
+#define nasm_strndup xstrndup
 #define nasm_stricmp strcasecmp
-#endif
-#else
-int nasm_stricmp (const char *, const char *);
-#endif
-
-#if defined(strnicmp) || defined(strncasecmp)
-#if defined(strnicmp)
-#define nasm_strnicmp strnicmp
-#else
 #define nasm_strnicmp strncasecmp
-#endif
-#else
-int nasm_strnicmp (const char *, const char *, int);
-#endif
 
 /*
  * Convert a string into a number, using NASM number rules. Sets
  * `*error' to TRUE if an error occurs, and FALSE otherwise.
  */
-long readnum(char *str, int *error);
+long nasm_readnum(char *str, int *error);
 
 /*
  * Convert a character constant into a number. Sets
@@ -83,150 +36,27 @@ long readnum(char *str, int *error);
  * str points to and length covers the middle of the string,
  * without the quotes.
  */
-long readstrnum(char *str, int length, int *warn);
+long nasm_readstrnum(char *str, int length, int *warn);
 
 /*
  * seg_init: Initialise the segment-number allocator.
  * seg_alloc: allocate a hitherto unused segment number.
  */
-void seg_init(void);
-long seg_alloc(void);
-
-/*
- * many output formats will be able to make use of this: a standard
- * function to add an extension to the name of the input file
- */
-#ifdef NASM_NASM_H
-void standard_extension (char *inname, char *outname, char *extension,
-                        efunc error);
-#endif
-
-/*
- * some handy macros that will probably be of use in more than one
- * output format: convert integers into little-endian byte packed
- * format in memory
- */
-
-#define WRITELONG(p,v) \
-  do { \
-    *(p)++ = (v) & 0xFF; \
-    *(p)++ = ((v) >> 8) & 0xFF; \
-    *(p)++ = ((v) >> 16) & 0xFF; \
-    *(p)++ = ((v) >> 24) & 0xFF; \
-  } while (0)
-
-#define WRITESHORT(p,v) \
-  do { \
-    *(p)++ = (v) & 0xFF; \
-    *(p)++ = ((v) >> 8) & 0xFF; \
-  } while (0)
-
-/*
- * and routines to do the same thing to a file
- */
-void fwriteshort (int data, FILE *fp);
-void fwritelong (long data, FILE *fp);
-
-/*
- * Routines to manage a dynamic random access array of longs which
- * may grow in size to be more than the largest single malloc'able
- * chunk.
- */
-
-#define RAA_BLKSIZE 4096              /* this many longs allocated at once */
-#define RAA_LAYERSIZE 1024            /* this many _pointers_ allocated */
-
-typedef struct RAA RAA;
-typedef union RAA_UNION RAA_UNION;
-typedef struct RAA_LEAF RAA_LEAF;
-typedef struct RAA_BRANCH RAA_BRANCH;
-
-struct RAA {
-    /*
-     * Number of layers below this one to get to the real data. 0
-     * means this structure is a leaf, holding RAA_BLKSIZE real
-     * data items; 1 and above mean it's a branch, holding
-     * RAA_LAYERSIZE pointers to the next level branch or leaf
-     * structures.
-     */
-    int layers;
-    /*
-     * Number of real data items spanned by one position in the
-     * `data' array at this level. This number is 1, trivially, for
-     * a leaf (level 0): for a level 1 branch it should be
-     * RAA_BLKSIZE, and for a level 2 branch it's
-     * RAA_LAYERSIZE*RAA_BLKSIZE.
-     */
-    long stepsize;
-    union RAA_UNION {
-       struct RAA_LEAF {
-           long data[RAA_BLKSIZE];
-       } l;
-       struct RAA_BRANCH {
-           struct RAA *data[RAA_LAYERSIZE];
-       } b;
-    } u;
-};
-
-
-struct RAA *raa_init (void);
-void raa_free (struct RAA *);
-long raa_read (struct RAA *, long);
-struct RAA *raa_write (struct RAA *r, long posn, long value);
-
-/*
- * Routines to manage a dynamic sequential-access array, under the
- * same restriction on maximum mallocable block. This array may be
- * written to in two ways: a contiguous chunk can be reserved of a
- * given size, and a pointer returned, or single-byte data may be
- * written. The array can also be read back in the same two ways:
- * as a series of big byte-data blocks or as a list of structures
- * of a given size.
- */
-
-struct SAA {
-    /*
-     * members `end' and `elem_len' are only valid in first link in
-     * list; `rptr' and `rpos' are used for reading
-     */
-    struct SAA *next, *end, *rptr;
-    long elem_len, length, posn, start, rpos;
-    char *data;
-};
-
-struct SAA *saa_init (long elem_len);  /* 1 == byte */
-void saa_free (struct SAA *);
-void *saa_wstruct (struct SAA *);      /* return a structure of elem_len */
-void saa_wbytes (struct SAA *, const void *, long);  /* write arbitrary bytes */
-void saa_rewind (struct SAA *);               /* for reading from beginning */
-void *saa_rstruct (struct SAA *);      /* return NULL on EOA */
-void *saa_rbytes (struct SAA *, long *);   /* return 0 on EOA */
-void saa_rnbytes (struct SAA *, void *, long); /* read a given no. of bytes */
-void saa_fread (struct SAA *s, long posn, void *p, long len);   /* fixup */
-void saa_fwrite (struct SAA *s, long posn, void *p, long len);   /* fixup */
-void saa_fpwrite (struct SAA *, FILE *);
-
-#ifdef NASM_NASM_H
-/*
- * Standard scanner.
- */
-extern char *stdscan_bufptr;
-void stdscan_reset(void);
-int stdscan (void *private_data, struct tokenval *tv);
-#endif
+void nasm_seg_init(void);
+long nasm_seg_alloc(void);
 
-#ifdef NASM_NASM_H
+#ifdef YASM_NASM_H
 /*
  * Library routines to manipulate expression data types.
  */
-int is_reloc(expr *);
-int is_simple(expr *);
-int is_really_simple (expr *);
-int is_unknown(expr *);
-int is_just_unknown(expr *);
-long reloc_value(expr *);
-long reloc_seg(expr *);
-long reloc_wrt(expr *);
+int nasm_is_reloc(nasm_expr *);
+int nasm_is_simple(nasm_expr *);
+int nasm_is_really_simple (nasm_expr *);
+int nasm_is_unknown(nasm_expr *);
+int nasm_is_just_unknown(nasm_expr *);
+long nasm_reloc_value(nasm_expr *);
+long nasm_reloc_seg(nasm_expr *);
+long nasm_reloc_wrt(nasm_expr *);
 #endif
 
 /*
@@ -234,25 +64,21 @@ long reloc_wrt(expr *);
  * matching `string', or <0 if no match. `array' is taken to
  * contain `size' elements.
  */
-int bsi (char *string, const char **array, int size);
+int nasm_bsi (char *string, const char **array, int size);
 
 
-char *src_set_fname(char *newname);
-long src_set_linnum(long newline);
-long src_get_linnum(void);
+char *nasm_src_set_fname(char *newname);
+long nasm_src_set_linnum(long newline);
+long nasm_src_get_linnum(void);
 /*
  * src_get may be used if you simply want to know the source file and line.
  * It is also used if you maintain private status about the source location
  * It return 0 if the information was the same as the last time you
  * checked, -1 if the name changed and (new-old) if just the line changed.
  */
-int src_get(long *xline, char **xname);
+int nasm_src_get(long *xline, char **xname);
 
 void nasm_quote(char **str);
 char *nasm_strcat(char *one, char *two);
-void nasmlib_cleanup(void);
 
-void null_debug_routine(const char *directive, const char *params);
-extern struct dfmt null_debug_form;
-extern struct dfmt *null_debug_arr[2];
 #endif