# HG changeset patch # User William Astle # Date 1339280719 21600 # Node ID 5d969517db7462ed8561c00f46ea100fe476a268 # Parent 52d9dd71f555cd90d46f38280eb87a1b164a2390 Added condundefzero pragma Added pragma condundefzero to allow the assembler to treat symbols that are undefined in a conditional expression as if their value had been set to zero. diff -r 52d9dd71f555 -r 5d969517db74 docs/manual.docbook.sgml --- a/docs/manual.docbook.sgml Sat Jun 09 16:03:36 2012 -0600 +++ b/docs/manual.docbook.sgml Sat Jun 09 16:25:19 2012 -0600 @@ -1673,6 +1673,25 @@ all cases when using the object file assembly target. It is intended for use only when the assembler will be producing the final binary. + +condundefzero + + +This pragma will cause the assembler to change the way it handles +symbols in conditional expressions. Ordinarily, any symbol that is not +defined prior to the conditional will throw an undefined symbol error. With +this pragma in effect, symbols that are not yet defined at the point the +conditional is encountered will be treated as zero. + +This is not the default because it encourages poor code design. One +should use the "IFDEF" or "IFNDEF" conditionals to test for the presence of +a symbol. + +It is important to note that if a symbol is defined but it does not +yet evaluate to a constant value at the point where the conditional appears, +the assembler will still complain about a non constant condition. + + diff -r 52d9dd71f555 -r 5d969517db74 lwasm/lwasm.c --- a/lwasm/lwasm.c Sat Jun 09 16:03:36 2012 -0600 +++ b/lwasm/lwasm.c Sat Jun 09 16:25:19 2012 -0600 @@ -58,6 +58,12 @@ return e; } + if (as -> undefzero) + { + e = lw_expr_build(lw_expr_type_int, 0); + return e; + } + // undefined here is undefied unless output is object if (as -> output_format != OUTPUT_OBJ) goto nomatch; @@ -896,6 +902,14 @@ return NULL; } + /* handle condundefzero */ + if (CURPRAGMA(as -> cl, PRAGMA_CONDUNDEFZERO)) + { + as -> undefzero = 1; + lwasm_reduce_expr(as, e); + as -> undefzero = 0; + } + /* we need to simplify the expression here */ debug_message(as, 250, "Doing interim reductions"); lwasm_interim_reduce(as); diff -r 52d9dd71f555 -r 5d969517db74 lwasm/lwasm.h --- a/lwasm/lwasm.h Sat Jun 09 16:03:36 2012 -0600 +++ b/lwasm/lwasm.h Sat Jun 09 16:25:19 2012 -0600 @@ -84,7 +84,8 @@ PRAGMA_NOLIST = 0x0080, // don't show line in listing PRAGMA_AUTOBRANCHLENGTH = 0x0100, // automatically select proper length for relative branches PRAGMA_EXPORT = 0x0200, // export symbols by default, unless local - PRAGMA_SYMBOLNOCASE = 0x400 // symbols defined under this pragma are matched case insensitively + PRAGMA_SYMBOLNOCASE = 0x400, // symbols defined under this pragma are matched case insensitively + PRAGMA_CONDUNDEFZERO = 0x800 // treat undefined symbols as zero in conditionals during pass 1 }; @@ -269,6 +270,7 @@ int endseen; // have we seen an "end" pseudo? int execaddr; // address from "end" int inmod; // inside an os9 module? + int undefzero; // used for handling "condundefzero" unsigned char crc[3]; // crc accumulator int badsymerr; // throw error on undef sym if set diff -r 52d9dd71f555 -r 5d969517db74 lwasm/pragma.c --- a/lwasm/pragma.c Sat Jun 09 16:03:36 2012 -0600 +++ b/lwasm/pragma.c Sat Jun 09 16:25:19 2012 -0600 @@ -59,6 +59,7 @@ { "export", "noexport", PRAGMA_EXPORT }, { "symbolnocase", "nosymbolnocase", PRAGMA_SYMBOLNOCASE }, { "nosymbolcase", "symbolcase", PRAGMA_SYMBOLNOCASE }, + { "condundefzero", "nocondundefzero", PRAGMA_CONDUNDEFZERO }, { 0, 0, 0} };