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
}
}
- /* 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"));
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
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
# $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,$@," > $@
# $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
--- /dev/null
+# $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
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";
*
* 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
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;
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]);
tempexpr[ntempexpr++].value = value;
}
-static expr *finishtemp(void)
+static nasm_expr *finishtemp(void)
{
addtotemp (0L, 0L); /* terminate */
while (ntempexprs >= tempexprs_size) {
* 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();
* 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);
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);
* 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;
* | 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)
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)
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)
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);
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)
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)
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)
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)
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)
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)
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)
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 "
}
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 == '-') {
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);
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;
}
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)
}
}
-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)
}
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");
* 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
*
* 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;
};
static int StackSize = 4;
-static char *StackPointer = "ebp";
+static const char *StackPointer = "ebp";
static int ArgOffset = 8;
static int LocalOffset = 4;
* 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;
/*
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);
/*
* 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_);
}
}
* 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);
}
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
{
char *p = line;
int type;
- Token *list = NULL;
- Token *t, **tail = &list;
+ Token *list_ = NULL;
+ Token *t, **tail = &list_;
while (*line)
{
}
line = p;
}
- return list;
+ return list_;
}
/*
* 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;
{
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;
}
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)
{
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;
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;
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);
int j, casesense;
Token *t, *tt, **tptr, *origline;
struct tokenval tokval;
- expr *evalresult;
+ nasm_expr *evalresult;
origline = tline;
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'",
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'",
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,
* 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);
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;
{
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])
{
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;
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'",
(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'",
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;
}
else
{
- mmac->rotate = mmac->rotate + reloc_value(evalresult);
+ mmac->rotate = mmac->rotate + nasm_reloc_value(evalresult);
if (mmac->rotate < 0)
mmac->rotate =
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;
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;
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);
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'",
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;
/*
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, "+"))
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;
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;
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);
}
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;
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++)
{
/* 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);
}
static void
-pp_cleanup(int pass)
+pp_cleanup(int pass_)
{
int h;
}
while (cstk)
ctx_pop();
- if (pass == 0)
+ if (pass_ == 0)
{
free_llist(predef);
delete_Blocks();
* 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 *);
--- /dev/null
+/*
+ * 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
+};
*
* 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
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
* 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);
* 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
#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
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
};
* 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;
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;
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++;
* 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++;
* 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++;
/*
* 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++;
* 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++;
* 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++;
* 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++;
* 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++;
/*
* 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) {
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))
{
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 };
* 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
* 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
/*
* 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
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
}
}
- /* 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"));
# $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,$@," > $@
# $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
--- /dev/null
+# $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
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";
*
* 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
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;
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]);
tempexpr[ntempexpr++].value = value;
}
-static expr *finishtemp(void)
+static nasm_expr *finishtemp(void)
{
addtotemp (0L, 0L); /* terminate */
while (ntempexprs >= tempexprs_size) {
* 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();
* 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);
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);
* 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;
* | 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)
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)
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)
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);
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)
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)
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)
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)
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)
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)
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)
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 "
}
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 == '-') {
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);
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;
}
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)
}
}
-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)
}
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");
* 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
*
* 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;
};
static int StackSize = 4;
-static char *StackPointer = "ebp";
+static const char *StackPointer = "ebp";
static int ArgOffset = 8;
static int LocalOffset = 4;
* 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;
/*
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);
/*
* 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_);
}
}
* 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);
}
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
{
char *p = line;
int type;
- Token *list = NULL;
- Token *t, **tail = &list;
+ Token *list_ = NULL;
+ Token *t, **tail = &list_;
while (*line)
{
}
line = p;
}
- return list;
+ return list_;
}
/*
* 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;
{
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;
}
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)
{
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;
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;
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);
int j, casesense;
Token *t, *tt, **tptr, *origline;
struct tokenval tokval;
- expr *evalresult;
+ nasm_expr *evalresult;
origline = tline;
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'",
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'",
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,
* 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);
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;
{
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])
{
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;
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'",
(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'",
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;
}
else
{
- mmac->rotate = mmac->rotate + reloc_value(evalresult);
+ mmac->rotate = mmac->rotate + nasm_reloc_value(evalresult);
if (mmac->rotate < 0)
mmac->rotate =
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;
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;
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);
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'",
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;
/*
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, "+"))
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;
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;
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);
}
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;
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++)
{
/* 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);
}
static void
-pp_cleanup(int pass)
+pp_cleanup(int pass_)
{
int h;
}
while (cstk)
ctx_pop();
- if (pass == 0)
+ if (pass_ == 0)
{
free_llist(predef);
delete_Blocks();
* 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 *);
--- /dev/null
+/*
+ * 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
+};
*
* 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
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
* 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);
* 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
#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
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
};
* 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;
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;
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++;
* 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++;
* 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++;
/*
* 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++;
* 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++;
* 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++;
* 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++;
* 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++;
/*
* 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) {
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))
{
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 };
* 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
* 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
/*
* 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