changeset 190:563adfccb645

Added 'sym=expr' opcode handling
author lost
date Sun, 22 Mar 2009 16:08:20 +0000
parents 1936ea52b83e
children 29ba546ceea0
files ChangeLog lwasm/lwasm.h lwasm/parse.c lwasm/pseudo.c lwasm/symbol.c
diffstat 5 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Mar 22 06:52:06 2009 +0000
+++ b/ChangeLog	Sun Mar 22 16:08:20 2009 +0000
@@ -20,6 +20,8 @@
 [+] added LWEX0 (LWOS simple binary) target to LWLINK
 [+] added ability to extract files in LWAR
 [+] added ability to "replace" members in LWAR
+[+] added support for "sym=expr" in the opcode field; this will define a
+    global symbol (non-section) if it resolves to a constant
 [b] arranged for output files for lwasm/lwlink to be removed if the assembly
     or linking fails
 [ ] DECB output of LWLINK now collapses contiguous output blocks into single
--- a/lwasm/lwasm.h	Sun Mar 22 06:52:06 2009 +0000
+++ b/lwasm/lwasm.h	Sun Mar 22 16:08:20 2009 +0000
@@ -108,6 +108,7 @@
 	int symaddr;		// set if this instruction sets a symbol addr with EQU or the like
 	int badop;			// bad operation - ignore it
 	int context;		// the symbol context for this line
+	int forceglobal;	// force a "global" symbol definition if constant
 	
 	// the following are used for obj format - for external references, inter-section
 	// references, and intrasection relocations
@@ -125,6 +126,7 @@
 #define SYMBOL_FORCE	4	// force resetting the symbol value if it already exists on pass 2
 #define SYMBOL_NORM		0	// no flags
 #define SYMBOL_EXTERN	8	// the symbol is an external reference
+#define SYMBOL_GLOBAL	16	// force global if non-complex symbol
 typedef struct lwasm_symbol_ent_s lwasm_symbol_ent_t;
 struct lwasm_symbol_ent_s
 {
--- a/lwasm/parse.c	Sun Mar 22 06:52:06 2009 +0000
+++ b/lwasm/parse.c	Sun Mar 22 16:08:20 2009 +0000
@@ -111,6 +111,25 @@
 	memcpy(opc, p, p2 - p);
 	opc[p2 - p] = '\0';
 
+	l -> forceglobal = 0;
+	// if the opcode contains an =, treat it as "symbol = expr"
+	if (!sym && strchr(opc, '='))
+	{
+		for (p2 = opc; *p2 && *p2 != '='; p2++)
+			/* do nothing */ ;
+		sym = lwasm_alloc((p2 - opc) + 1);
+		memcpy(sym, opc, p2 - opc);
+		sym[p2 - opc] = '\0';
+		l -> sym = sym;
+		
+		p2 = p + (p2 - opc) + 1;
+//		p2++;
+		opc[0] = '=';
+		opc[1] = '\0';
+		debug_message(2, "Found opcode = with symbol %s and operand %s", sym, p2);
+		l -> forceglobal = 1;
+	}
+	
 	debug_message(2, "Found operation code: '%s'", opc);
 
 	// skip intervening whitespace if present
--- a/lwasm/pseudo.c	Sun Mar 22 06:52:06 2009 +0000
+++ b/lwasm/pseudo.c	Sun Mar 22 16:08:20 2009 +0000
@@ -294,7 +294,7 @@
 	
 	// note: we need to do this because the symbol might have resolved
 	// to a constant!
-	lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE);
+	lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE | (l -> forceglobal ? SYMBOL_GLOBAL : SYMBOL_NORM));
 }
 
 OPFUNC(pseudo_set)
--- a/lwasm/symbol.c	Sun Mar 22 06:52:06 2009 +0000
+++ b/lwasm/symbol.c	Sun Mar 22 16:08:20 2009 +0000
@@ -139,7 +139,7 @@
 	se -> sym = lwasm_strdup(sym);
 	se -> context = scontext;
 
-	if (!(flags & SYMBOL_EXTERN))
+	if (!(flags & SYMBOL_EXTERN) && ((flags & SYMBOL_COMPLEX) || !(flags & SYMBOL_GLOBAL)))
 		se -> sect = as -> csect;
 	else
 		se -> sect = NULL;