changeset 63:d85ba47b1e8f

Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
author lost
date Mon, 05 Jan 2009 01:17:23 +0000
parents da1337724ecd
children aaddd47219b4
files src/instab.c src/instab.h src/lwasm.h src/parse.c src/pseudo.c src/symbol.c
diffstat 6 files changed, 38 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/instab.c	Mon Jan 05 00:57:37 2009 +0000
+++ b/src/instab.c	Mon Jan 05 01:17:23 2009 +0000
@@ -70,6 +70,8 @@
 extern OPFUNC(pseudo_macro);
 extern OPFUNC(pseudo_endm);
 
+extern OPFUNC(pseudo_set);
+
 instab_t instab[] =
 {
 	{ "abx",	{	0x3a,	-0x1,	-0x1,	-0x1	},	insn_inh },
@@ -314,8 +316,8 @@
 
 	{ "org",	{ -1, -1, -1, -1 },	pseudo_org },
 
-	{ "equ",	{ -1, -1, -1, -1 },	pseudo_equ },
-	{ "=",		{ -1, -1, -1, -1 },	pseudo_equ },
+	{ "equ",	{ -1, -1, -1, -1 },	pseudo_equ,	0,	0,	1 },
+	{ "=",		{ -1, -1, -1, -1 },	pseudo_equ,	0,	0,	1 },
 
 	{ "rmb", 	{ -1, -1, -1, -1 }, pseudo_rmb },
 	{ "rmd", 	{ -1, -1, -1, -1 }, pseudo_rmd },
@@ -354,6 +356,8 @@
 	{ "macro",	{ -1, -1, -1, -1}, 	pseudo_macro,	1,	0 },
 	{ "endm",	{ -1, -1, -1, -1},	pseudo_endm,	1,	1 },	
 
+	{ "set",	{ -1, -1, -1, -1},	pseudo_set,	0,	0,	1 },
+
 	/* flag end of table */	
 	{ NULL,		{ -0x1, -0x1, -0x1, -0x1 }, insn_inh }
 };
--- a/src/instab.h	Mon Jan 05 00:57:37 2009 +0000
+++ b/src/instab.h	Mon Jan 05 01:17:23 2009 +0000
@@ -33,6 +33,7 @@
 	void (*fn)(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum);
 	int iscond;					/* set if this should be dispatched even if skipping a condition/macro */
 	int endm;					/* end of macro? */
+	int setsym;					/* does this set a symbol address? EQU, SET */
 } instab_t;
 
 #define OPFUNC(fn)	void (fn)(asmstate_t *as, lwasm_line_t *l, char **p, int opnum)
--- a/src/lwasm.h	Mon Jan 05 00:57:37 2009 +0000
+++ b/src/lwasm.h	Mon Jan 05 01:17:23 2009 +0000
@@ -71,12 +71,15 @@
 };
 
 // for keeping track of symbols
+#define	SYMBOL_SET	1	// the symbol was used for "SET"
+#define SYMBOL_NORM	0	// no flags
 typedef struct lwasm_symbol_ent_s lwasm_symbol_ent_t;
 struct lwasm_symbol_ent_s
 {
 	char *sym;			// the symbol
 	int context;		// the context number of the symbol (-1 for global)
 	int value;			// the value of the symbol
+	int flags;			// flags for the symbol
 	lwasm_symbol_ent_t *next;	// next symbol in the table
 	lwasm_symbol_ent_t *prev;	// previous symbol in the table
 };
--- a/src/parse.c	Mon Jan 05 00:57:37 2009 +0000
+++ b/src/parse.c	Mon Jan 05 01:17:23 2009 +0000
@@ -66,15 +66,6 @@
 		
 		p = p2;
 		
-		if (as -> passnum == 1)
-		{
-			l -> sym = sym;
-			// have a symbol; now determine if it is valid and register it
-			// at the current address of the line
-			debug_message(1, "Registering symbol '%s' at %04X", sym, as -> addr);
-			if (lwasm_register_symbol(as, l, sym, as -> addr) < 0)
-				l -> sym = NULL;
-		}
 	}
 	else
 	{
@@ -132,6 +123,20 @@
 			goto done_line;
 	}
 	
+	// register symbol if needed
+	if (as -> skipcond == 0 && as -> inmacro == 0 && sym)
+	{
+		l -> sym = sym;
+		if (as -> passnum == 1 && !(instab[opnum].opcode && instab[opnum].setsym))
+		{
+			// have a symbol; now determine if it is valid and register it
+			// at the current address of the line
+			debug_message(1, "Registering symbol '%s' at %04X", sym, as -> addr);
+			if (lwasm_register_symbol(as, l, sym, as -> addr) < 0)
+				l -> sym = NULL;
+		}
+	}
+
 	if (!(instab[opnum].opcode) || !(instab[opnum].fn) && !(as -> skipcond || as -> inmacro))
 	{
 		// invalid operation code, throw error
--- a/src/pseudo.c	Mon Jan 05 00:57:37 2009 +0000
+++ b/src/pseudo.c	Mon Jan 05 01:17:23 2009 +0000
@@ -354,7 +354,6 @@
 
 OPFUNC(pseudo_equ)
 {
-	lwasm_expr_stack_t *s;
 	int rval;
 
 	// equ is not needed to be processed on pass 2	
@@ -367,27 +366,19 @@
 		return;
 	}
 
-	s = lwasm_evaluate_expr(as, l, *p, NULL);
-	
-	if (!s)
-	{
-		register_error(as, l, 1, "Bad expression");
+	if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &rval) < 0)
 		rval = 0;
-	}
-	else
-	{
-		if (!lwasm_expr_is_constant(s))
-			register_error(as, l, 1, "Invalid incomplete reference (pass 1)");
-		rval = lwasm_expr_get_value(s);
-		lwasm_expr_stack_free(s);
-	}
+
 	l -> symaddr = rval & 0xFFFF;
 	l -> addrset = 2;
-	if (strchr(l -> sym, '@') || strchr(l -> sym, '?'))
-		lwasm_set_symbol(as, l -> sym, as -> context, l -> symaddr);
-	else
-		lwasm_set_symbol(as, l -> sym, -1, l -> symaddr);
+	
+	lwasm_register_symbol(as, l, l -> sym, rval);
 }
+
+OPFUNC(pseudo_set)
+{
+}
+
 /*
 void pseudo_set(asmstate_t *as, sourceline_t *cl, char **optr)
 {
--- a/src/symbol.c	Mon Jan 05 00:57:37 2009 +0000
+++ b/src/symbol.c	Mon Jan 05 01:17:23 2009 +0000
@@ -151,6 +151,11 @@
 		else
 			fputc('L', lf);
 		
+		if (se -> flags & SYMBOL_SET)
+			fputc('S', lf);
+		else
+			fputc(' ', lf);
+		
 		fprintf(lf, " %s", se -> sym);
 		
 		if (se -> context >= 0)