# HG changeset patch # User lost@l-w.ca # Date 1302061731 21600 # Node ID cb4efc47ce9de7ac45b3784955802f50f6bfc902 # Parent 51c840679a0e8a57d97ba82316c98d6806d878af Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default diff -r 51c840679a0e -r cb4efc47ce9d lwasm/lwasm.h --- a/lwasm/lwasm.h Tue Apr 05 21:48:22 2011 -0600 +++ b/lwasm/lwasm.h Tue Apr 05 21:48:51 2011 -0600 @@ -76,7 +76,8 @@ PRAGMA_UNDEFEXTERN = 0x0004, // undefined symbols are considered to be external PRAGMA_CESCAPES = 0x0008, // allow C style escapes in fcc, fcs, fcn, etc. PRAGMA_IMPORTUNDEFEXPORT = 0x0010, // imports symbol if undefined upon export - PRAGMA_PCASPCR = 0x0020 // treats ,PC as ,PCR instead of constant offset + PRAGMA_PCASPCR = 0x0020, // treats ,PC as ,PCR instead of constant offset + PRAGMA_SHADOW = 0x0040 // allow macros to shadow builtin operations }; diff -r 51c840679a0e -r cb4efc47ce9d lwasm/pass1.c --- a/lwasm/pass1.c Tue Apr 05 21:48:22 2011 -0600 +++ b/lwasm/pass1.c Tue Apr 05 21:48:51 2011 -0600 @@ -260,6 +260,16 @@ if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond)) goto linedone; + if (as -> pragmas & PRAGMA_SHADOW) + { + // check for macros even if they shadow real operations + // NOTE: "ENDM" cannot be shadowed + if (expand_macro(as, cl, &p1, sym) == 0) + { + // a macro was expanded here + goto linedone; + } + } if (instab[opnum].opcode == NULL) { cl -> insn = -1; diff -r 51c840679a0e -r cb4efc47ce9d lwasm/pragma.c --- a/lwasm/pragma.c Tue Apr 05 21:48:22 2011 -0600 +++ b/lwasm/pragma.c Tue Apr 05 21:48:51 2011 -0600 @@ -42,6 +42,7 @@ { "cescapes", PRAGMA_CESCAPES }, { "importundefexport", PRAGMA_IMPORTUNDEFEXPORT }, { "pcaspcr", PRAGMA_PCASPCR }, + { "shadow", PRAGMA_SHADOW }, { 0, 0 } }; @@ -53,6 +54,7 @@ { "nocescapes", PRAGMA_CESCAPES }, { "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT }, { "nopcaspcr", PRAGMA_PCASPCR }, + { "noshadow", PRAGMA_SHADOW }, { 0, 0 } };