diff src/symbol.c @ 143:0ee5f65bccf9

Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
author lost
date Thu, 29 Jan 2009 01:32:11 +0000
parents ea2cfebef5d0
children
line wrap: on
line diff
--- a/src/symbol.c	Wed Jan 28 06:06:05 2009 +0000
+++ b/src/symbol.c	Thu Jan 29 01:32:11 2009 +0000
@@ -138,7 +138,12 @@
 		se -> expr = l -> exprs[0];
 	se -> sym = lwasm_strdup(sym);
 	se -> context = scontext;
-	se -> sect = as -> csect;
+
+	if (!(flags & SYMBOL_EXTERN))
+		se -> sect = as -> csect;
+	else
+		se -> sect = NULL;
+
 	se -> expr = NULL;
 	se -> flags = flags;
 	se -> externalname = NULL;
@@ -149,6 +154,7 @@
 lwasm_symbol_ent_t *lwasm_find_symbol(asmstate_t *as, char *sym, int scontext)
 {
 	lwasm_symbol_ent_t *se;
+	static int st = 0;
 	
 	for (se = as -> symhead; se; se = se -> next)
 	{
@@ -157,6 +163,29 @@
 			return se;
 		}
 	}
+	if (as -> passnum == 2 && st == 0 && scontext == -1 && as -> outformat == OUTPUT_OBJ && as -> pragmas & PRAGMA_UNDEFEXTERN)
+	{
+		// we want undefined symbols to be considered external
+		// we didn't find it on a lookup so register it as external
+		// but we only do so when looking up in global context
+		st = 1;
+		if (lwasm_register_symbol(as, NULL, sym, 0, SYMBOL_EXTERN))
+		{
+			st = 0;
+			return NULL;
+		}
+		st = 0;
+		
+		// find the newly registered symbol and return it
+		for (se = as -> symhead; se; se = se -> next)
+		{
+			if (scontext == se -> context && !strcmp(sym, se -> sym))
+			{
+				return se;
+			}
+		}
+	}
+		
 	return NULL;
 }