# HG changeset patch # User lost@l-w.ca # Date 1312690543 21600 # Node ID ed7f970f3688b11777f5ed68e633a24ac0cb7bac # Parent 7ce01324e391510e8223b8dfbb8888cac3f7e785 Added --define= option to predfine a symbol for assembly diff -r 7ce01324e391 -r ed7f970f3688 lwasm/lwasm.h --- 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___ */ diff -r 7ce01324e391 -r ed7f970f3688 lwasm/main.c --- 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); diff -r 7ce01324e391 -r ed7f970f3688 lwasm/symbol.c --- 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) {