# HG changeset patch # User lost # Date 1231100198 0 # Node ID b9856da2674af1a099ecae1d1e96cee9911eab43 # Parent 04868fa52a15cba87739de63b69ae7cbef58dbaa Added file inclusion diff -r 04868fa52a15 -r b9856da2674a src/instab.c --- a/src/instab.c Sun Jan 04 20:14:54 2009 +0000 +++ b/src/instab.c Sun Jan 04 20:16:38 2009 +0000 @@ -44,6 +44,7 @@ extern OPFUNC(pseudo_org); extern OPFUNC(pseudo_equ); extern OPFUNC(pseudo_rmb); +extern OPFUNC(pseudo_include); instab_t instab[] = { @@ -294,6 +295,8 @@ { "rmb", { -1, -1, -1, -1 }, pseudo_rmb }, + { "include", { -1, -1, -1, -1 }, pseudo_include }, + /* flag end of table */ { NULL, { -0x1, -0x1, -0x1, -0x1 }, insn_inh } }; diff -r 04868fa52a15 -r b9856da2674a src/lwasm.c --- a/src/lwasm.c Sun Jan 04 20:14:54 2009 +0000 +++ b/src/lwasm.c Sun Jan 04 20:16:38 2009 +0000 @@ -170,11 +170,13 @@ struct symstateinfo *st; st = state; - + debug_message(3, "lwasm_expr_lookup_symbol(): find '%s' (context=%d)", sym, st -> as -> context); + // look for local symbol first then global symbol se = lwasm_find_symbol(st -> as, sym, st -> as -> context); if (!se) se = lwasm_find_symbol(st -> as, sym, -1); + debug_message(3, "lwasm_expr_lookup_symbol(): got '%p'", se); if (!se) return -1; *val = se -> value; diff -r 04868fa52a15 -r b9856da2674a src/parse.c --- a/src/parse.c Sun Jan 04 20:14:54 2009 +0000 +++ b/src/parse.c Sun Jan 04 20:16:38 2009 +0000 @@ -47,8 +47,9 @@ return 0; } - // for output generation later - l -> codeaddr = as -> addr; + // for output generation later but only on pass 1 + if (as -> passnum == 1) + l -> codeaddr = as -> addr; if (!isspace(*p) && *p != '*' && *p != ';') { diff -r 04868fa52a15 -r b9856da2674a src/pseudo.c --- a/src/pseudo.c Sun Jan 04 20:14:54 2009 +0000 +++ b/src/pseudo.c Sun Jan 04 20:16:38 2009 +0000 @@ -26,12 +26,24 @@ #include "lwasm.h" #include "instab.h" #include "expr.h" +#include "util.h" +extern int lwasm_read_file(asmstate_t *as, const char *filename); OPFUNC(pseudo_org) { int rval; lwasm_expr_stack_t *s; + + if (as -> passnum != 1) + { + // org is not needed to be processed on pass 2 + // this will prevent phasing errors for forward references that + // resolve on the second pass + // we saved the org address in l -> codeaddr on pass 1 + as -> addr = l -> codeaddr; + return; + } if (l -> sym) { @@ -57,30 +69,63 @@ } /* -void pseudo_include(asmstate_t *as, sourceline_t *cl, char **optr) +The operand for include is a string optionally enclosed in " +*/ +OPFUNC(pseudo_include) { int v1; + char *fn; + // only include files on pass 1 + // but make sure local include context is right + // for the next line... if (as -> passnum != 1) + { + as -> context += 1; return; - while (**optr && isspace(**optr)) - (*optr)++; - if (!**optr) + } + + while (**p && isspace(**p)) + (*p)++; + + if (!**p) { - register_error(as, cl, ERR_BADFN); + register_error(as, l, 1, "Bad file name"); return; } - for (v1 = 0; *((*optr)+v1) && !isspace(*((*optr)+v1)); v1++) - ; + + if (**p == '"') + { + // search for ending " + (*p)++; + for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++) + /* do nothing */ ; + if (*((*p)+v1) != '"') + { + register_error(as, l, 1, "Bad file name"); + return; + } + } + else { - char *fn = malloc(v1 + 1); - strncpy(fn, *optr, v1); - fn[v1] = '\0'; - lwasm_read_file(as, fn); + // search for a space type character + for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++) + ; } + + fn = lwasm_alloc(v1 + 1); + memcpy(fn, *p, v1); + fn[v1] = '\0'; + + // end local label context on include + as -> context += 1; + if (lwasm_read_file(as, fn) < 0) + { + register_error(as, l, 1, "File include error (%s)", fn); + } + lwasm_free(fn); } -*/ OPFUNC(pseudo_rmb) { int rval; @@ -256,7 +301,11 @@ { lwasm_expr_stack_t *s; int rval; - + + // equ is not needed to be processed on pass 2 + if (as -> passnum != 1) + return; + if (l -> sym == NULL) { register_error(as, l, 1, "No symbol specified"); diff -r 04868fa52a15 -r b9856da2674a src/symbol.c --- a/src/symbol.c Sun Jan 04 20:14:54 2009 +0000 +++ b/src/symbol.c Sun Jan 04 20:16:38 2009 +0000 @@ -60,7 +60,7 @@ for (p = sym; *p; p++) { - if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._$?@0123456789", *sym) && (unsigned char)*sym < 0x80) + if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._$?@0123456789", *sym)) { register_error(as, l, 1, "Bad symbol: %s", sym); return -1;