diff src/symbol.c @ 75:92eb93bffa28

Rejigged symbol system to be able to handle non-constant references
author lost
date Thu, 08 Jan 2009 01:32:49 +0000
parents aaddd47219b4
children a338d496350e
line wrap: on
line diff
--- a/src/symbol.c	Thu Jan 08 01:18:40 2009 +0000
+++ b/src/symbol.c	Thu Jan 08 01:32:49 2009 +0000
@@ -28,6 +28,7 @@
 
 #include "lwasm.h"
 #include "util.h"
+#include "expr.h"
 
 /*
 Note that this function may accept symbols that the expression evaluator doesn't
@@ -41,6 +42,16 @@
 	
 	int scontext = -1;
 	
+	// if the symbol is constant, fall back to simple registration!
+	if (flags & SYMBOL_COMPLEX)
+	{
+		if (lwasm_expr_is_constant(l -> expr))
+		{
+			val = lwasm_expr_get_value(l -> expr);
+			flags &= ~SYMBOL_COMPLEX;
+		}
+	}
+	
 	// first check if the symbol is valid
 	// the following characters are allowed in a symbol:
 	// [a-zA-Z0-9._$?@] and any byte value larger than 0x7F
@@ -85,6 +96,10 @@
 	if (se)
 	{
 		se -> value = val;
+		if (flags & SYMBOL_COMPLEX)
+		{
+			se -> expr = l -> expr;
+		}
 		return;
 	}
 
@@ -105,8 +120,12 @@
 		as -> symtail = se;
 	}
 	se -> value = val;
+	if (flags & SYMBOL_COMPLEX)
+		se -> expr = l -> expr;
 	se -> sym = lwasm_strdup(sym);
 	se -> context = scontext;
+	se -> sect = as -> csect;
+	se -> expr = NULL;
 	se -> flags = flags;
 
 	return 0;
@@ -147,7 +166,11 @@
 	
 	for (se = as -> symhead; se; se = se -> next)
 	{
-		if (se -> value > 0xffff || se -> value < -0x8000)
+		if (se -> expr)
+		{
+			fprintf(lf, "<incompl>");
+		}
+		else if (se -> value > 0xffff || se -> value < -0x8000)
 		{
 			fprintf(lf, "%08X ", se -> value);
 		}
@@ -170,6 +193,11 @@
 		if (se -> context >= 0)
 			fprintf(lf, " (%d)", se -> context);
 		
+		if (se -> sect)
+		{
+			fprintf(lf, " [%s]", se -> sect -> name);
+		}
+		
 		fputc('\n', lf);
 	}
 }