changeset 198:6ddc861a07d4

Allow export to import undefined symbols
author lost
date Sun, 22 Mar 2009 18:26:59 +0000
parents 12fb4e8d5236
children 188037f0397c
files lwasm/lwasm.h lwasm/pragma.c lwasm/pseudo.c
diffstat 3 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/lwasm.h	Sun Mar 22 18:01:30 2009 +0000
+++ b/lwasm/lwasm.h	Sun Mar 22 18:26:59 2009 +0000
@@ -187,6 +187,9 @@
 // allow C-style escapes in fcc, fcs, and fcn directives
 #define PRAGMA_CESCAPES			4
 
+// allow "export <undefsym>" to import the symbol
+#define PRAGMA_IMPORTUNDEFEXPORT	8
+
 #ifndef __lwasm_c_seen__
 #define __lwasm_E__ extern
 #else
--- a/lwasm/pragma.c	Sun Mar 22 18:01:30 2009 +0000
+++ b/lwasm/pragma.c	Sun Mar 22 18:26:59 2009 +0000
@@ -109,6 +109,14 @@
 	{
 		as -> pragmas &= ~PRAGMA_CESCAPES;
 	}
+	else if (!strcasecmp(pragma, "importundefexport"))
+	{
+		as -> pragmas |= PRAGMA_IMPORTUNDEFEXPORT;
+	}
+	else if (!strcasecmp(pragma, "noimportundefexport"))
+	{
+		as -> pragmas &= ~PRAGMA_IMPORTUNDEFEXPORT;
+	}
 	else
 	{
 		if (error)
--- a/lwasm/pseudo.c	Sun Mar 22 18:01:30 2009 +0000
+++ b/lwasm/pseudo.c	Sun Mar 22 18:26:59 2009 +0000
@@ -1082,6 +1082,17 @@
 	// the symbol better be defined at this point (pass 2)
 	// local symbols cannot be exported nor can "global" symbols
 	se = lwasm_find_symbol(as, l -> sym, -1);
+	if (!se && (as -> pragmas & PRAGMA_IMPORTUNDEFEXPORT))
+	{
+		// import the symbol
+		if (as -> csect)
+		{
+			register_error(as, l, 1, "Cannot declare external symbols within a section");
+			return;
+		}
+	
+		lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
+	}
 	if (!se)
 	{
 		register_error(as, l, 2, "Exported symbols must be fully defined within a section");