changeset 53:cb4efc47ce9d

Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
author lost@l-w.ca
date Tue, 05 Apr 2011 21:48:51 -0600
parents 51c840679a0e
children 2077b755b8b4
files lwasm/lwasm.h lwasm/pass1.c lwasm/pragma.c
diffstat 3 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
 };
 
 
--- 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;
--- 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 }
 };