Mercurial > hg-old > index.cgi
diff lwasm/symbol.c @ 344:0215a0fbf61b
Added assembly error system and additional checks for symbol syntax
author | lost@starbug |
---|---|
date | Thu, 25 Mar 2010 22:06:50 -0600 |
parents | 7b4123dce741 |
children | a82c55070624 |
line wrap: on
line diff
--- a/lwasm/symbol.c Thu Mar 25 20:51:34 2010 -0600 +++ b/lwasm/symbol.c Thu Mar 25 22:06:50 2010 -0600 @@ -29,17 +29,44 @@ #include "lwasm.h" -struct symtabe *register_symbol(asmstate_t *as, char *sym, lw_expr_t val, int flags) +// these are allowed chars BELOW 0x80 +#define SSYMCHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_@$" +#define SYMCHARS SSYMCHARS ".?0123456789" + +struct symtabe *register_symbol(asmstate_t *as, line_t *cl, char *sym, lw_expr_t val, int flags) { struct symtabe *se; int islocal = 0; int context = -1; int version = -1; + char *cp; - if (strchr(sym, '@') || strchr(sym, '?')) - islocal = 1; - if (!(as -> pragmas & PRAGMA_DOLLARNOTLOCAL) && strchr(sym, '$')) - islocal = 1; + if (*sym < 0x80 && !strchr(SSYMCHARS, *sym)) + { + lwasm_register_error(as, cl, "Bad symbol (%s)", sym); + return NULL; + } + + if ((*sym == '$' || *sym == '@') && (sym[1] >= '0' && sym[1] <= '9')) + { + lwasm_register_error(as, cl, "Bad symbol (%s)", sym); + return NULL; + } + + for (cp = sym; *cp; cp++) + { + if (*cp == '@' || *cp == '?') + islocal = 1; + if (*cp == '$' && !(as -> pragmas & PRAGMA_DOLLARNOTLOCAL)) + islocal = 1; + + // bad symbol + if (*cp < 0x80 && !strchr(SYMCHARS, *cp)) + { + lwasm_register_error(as, cl, "Bad symbol (%s)", sym); + return NULL; + } + } if (islocal) context = as -> context; @@ -63,6 +90,7 @@ if (se) { // multiply defined symbol + lwasm_register_error(as, cl, "Multiply defined symbol (%s)", sym); return NULL; } @@ -81,7 +109,7 @@ return se; } -struct symtabe * lookup_symbol(asmstate_t *as, char *sym, int context, int version) +struct symtabe * lookup_symbol(asmstate_t *as, line_t *cl, char *sym, int context, int version) { return NULL; }