diff src/parse.c @ 44:2330b88f9600

Added simple output listing
author lost
date Sun, 04 Jan 2009 06:52:18 +0000
parents 9bd584bb6296
children b9856da2674a
line wrap: on
line diff
--- a/src/parse.c	Sun Jan 04 06:16:22 2009 +0000
+++ b/src/parse.c	Sun Jan 04 06:52:18 2009 +0000
@@ -37,7 +37,7 @@
 	char *p, *p2;
 	char *opc;
 	int opnum;
-	char *sym;
+	char *sym = NULL;
 	
 	p = l -> text;
 	
@@ -47,6 +47,9 @@
 		return 0;
 	}
 	
+	// for output generation later
+	l -> codeaddr = as -> addr;
+	
 	if (!isspace(*p) && *p != '*' && *p != ';')
 	{
 		// we have a symbol specified here
@@ -59,12 +62,17 @@
 		sym[p2 - p] = '\0';
 		memcpy(sym, p, p2 - p);
 		
-		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;
+		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
 	{
@@ -84,7 +92,8 @@
 	// if comment or end of line, return
 	if (!*p || *p == '*' || *p == ';')
 	{
-		lwasm_free(l -> sym);
+		if (sym)
+			lwasm_free(l -> sym);
 		return 0;
 	}
 	
@@ -115,7 +124,8 @@
 	{
 		// invalid operation code, throw error
 		register_error(as, l, 1, "Invalid operation code '%s'", opc);
-		lwasm_free(l -> sym);
+		if (sym)
+			lwasm_free(l -> sym);
 		lwasm_free(opc);
 		return -1;
 	}
@@ -124,5 +134,6 @@
 	(instab[opnum].fn)(as, l, &p2, opnum);
 	
 	lwasm_free(opc);
-	lwasm_free(sym);
+	if (sym)
+		lwasm_free(sym);
 }