Mercurial > hg > index.cgi
changeset 101:ed7f970f3688
Added --define= option to predfine a symbol for assembly
author | lost@l-w.ca |
---|---|
date | Sat, 06 Aug 2011 22:15:43 -0600 |
parents | 7ce01324e391 |
children | f7a87c3a8e0e |
files | lwasm/lwasm.h lwasm/main.c lwasm/symbol.c |
diffstat | 3 files changed, 28 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/lwasm/lwasm.h Sat Aug 06 10:51:33 2011 -0600 +++ b/lwasm/lwasm.h Sat Aug 06 22:15:43 2011 -0600 @@ -328,6 +328,6 @@ #define OPLEN(op) (((op)>0xFF)?2:1) -#define CURPRAGMA(l,p) (((l)->pragmas & (p)) ? 1 : 0) +#define CURPRAGMA(l,p) (((l) && ((l)->pragmas & (p))) ? 1 : 0) #endif /* ___lwasm_h_seen___ */
--- a/lwasm/main.c Sat Aug 06 10:51:33 2011 -0600 +++ b/lwasm/main.c Sat Aug 06 22:15:43 2011 -0600 @@ -54,6 +54,7 @@ { "6809", '9', 0, 0, "Set assembler to 6809 only mode" }, { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" }, { "includedir", 'I', "PATH", 0, "Add entry to include path" }, + { "define", 'D', "SYM[=VAL]", 0, "Automatically define SYM to be VAL (or 1)"}, { 0 } }; @@ -67,7 +68,28 @@ case 'I': lw_stringlist_addstring(as -> include_list, arg); break; - + + case 'D': + { + char *offs; + int val = 1; + lw_expr_t te; + + if ((offs = strchr(arg, '='))) + { + *offs = '\0'; + val = strtol(offs + 1, NULL, 0); + } + + /* register global symbol */ + te = lw_expr_build(lw_expr_type_int, val); + register_symbol(as, NULL, arg, te, symbol_flag_nocheck | symbol_flag_set); + lw_expr_destroy(te); + + if (offs) + *offs = '='; + break; + } case 'o': if (as -> output_file) lw_free(as -> output_file);
--- a/lwasm/symbol.c Sat Aug 06 10:51:33 2011 -0600 +++ b/lwasm/symbol.c Sat Aug 06 22:15:43 2011 -0600 @@ -166,7 +166,10 @@ } se -> value = lw_expr_copy(val); se -> symbol = lw_strdup(sym); - se -> section = cl -> csect; + if (cl) + se -> section = cl -> csect; + else + se -> section = NULL; sprev = symbol_findprev(as, se); if (!sprev) {