changeset 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 c8c772ef5df9
children 2fe5fd7d65a3
files src/lwasm.h src/symbol.c
diffstat 2 files changed, 39 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/lwasm.h	Thu Jan 08 01:18:40 2009 +0000
+++ b/src/lwasm.h	Thu Jan 08 01:32:49 2009 +0000
@@ -85,19 +85,22 @@
 	// references, and intrasection relocations
 	int relocoff;		// offset into insn where relocation value goes
 	// the incomplete reference expression
-	struct lwasm_expr_strack_t *expr;
+	lwasm_expr_stack_t *expr;
 };
 
 // for keeping track of symbols
-#define	SYMBOL_SET	1	// the symbol was used for "SET"
-#define SYMBOL_NORM	0	// no flags
+#define	SYMBOL_SET		1	// the symbol was used for "SET"
+#define SYMBOL_COMPLEX	2	// register symbol as a complex symbol (from l -> expr)
+#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
+	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
+	sectiontab_t *sect;			// the section the symbol exists in; NULL for none
+	lwasm_expr_stack_t *expr;	// expression for a symbol that is not constant NULL for const
 	lwasm_symbol_ent_t *next;	// next symbol in the table
 	lwasm_symbol_ent_t *prev;	// previous symbol in the table
 };
--- 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);
 	}
 }