diff src/pseudo.c @ 52:b9856da2674a

Added file inclusion
author lost
date Sun, 04 Jan 2009 20:16:38 +0000
parents e672232caffe
children 493cb8ea50a0
line wrap: on
line diff
--- a/src/pseudo.c	Sun Jan 04 20:14:54 2009 +0000
+++ b/src/pseudo.c	Sun Jan 04 20:16:38 2009 +0000
@@ -26,12 +26,24 @@
 #include "lwasm.h"
 #include "instab.h"
 #include "expr.h"
+#include "util.h"
 
+extern int lwasm_read_file(asmstate_t *as, const char *filename);
 
 OPFUNC(pseudo_org)
 {
 	int rval;
 	lwasm_expr_stack_t *s;
+
+	if (as -> passnum != 1)
+	{
+		// org is not needed to be processed on pass 2
+		// this will prevent phasing errors for forward references that
+		// resolve on the second pass
+		// we saved the org address in l -> codeaddr on pass 1
+		as -> addr = l -> codeaddr;
+		return;
+	}
 	
 	if (l -> sym)
 	{
@@ -57,30 +69,63 @@
 }
 
 /*
-void pseudo_include(asmstate_t *as, sourceline_t *cl, char **optr)
+The operand for include is a string optionally enclosed in "
+*/
+OPFUNC(pseudo_include)
 {
 	int v1;
+	char *fn;
 
+	// only include files on pass 1
+	// but make sure local include context is right
+	// for the next line...
 	if (as -> passnum != 1)
+	{
+		as -> context += 1;
 		return;
-	while (**optr && isspace(**optr))
-		(*optr)++;
-	if (!**optr)
+	}
+
+	while (**p && isspace(**p))
+		(*p)++;
+
+	if (!**p)
 	{
-		register_error(as, cl, ERR_BADFN);
+		register_error(as, l, 1, "Bad file name");
 		return;
 	}
-	for (v1 = 0; *((*optr)+v1) && !isspace(*((*optr)+v1)); v1++)
-		;
+
+	if (**p == '"')
+	{
+		// search for ending "
+		(*p)++;
+		for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++)
+			/* do nothing */ ;
+		if (*((*p)+v1) != '"')
+		{
+			register_error(as, l, 1, "Bad file name");
+			return;
+		}
+	}
+	else
 	{
-		char *fn = malloc(v1 + 1);
-		strncpy(fn, *optr, v1);
-		fn[v1] = '\0';
-		lwasm_read_file(as, fn);
+		// search for a space type character
+		for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++)
+			;
 	}
+
+	fn = lwasm_alloc(v1 + 1);
+	memcpy(fn, *p, v1);
+	fn[v1] = '\0';
+
+	// end local label context on include	
+	as -> context += 1;
+	if (lwasm_read_file(as, fn) < 0)
+	{
+		register_error(as, l, 1, "File include error (%s)", fn);
+	}
+	lwasm_free(fn);
 }
 
-*/
 OPFUNC(pseudo_rmb)
 {
 	int rval;
@@ -256,7 +301,11 @@
 {
 	lwasm_expr_stack_t *s;
 	int rval;
-	
+
+	// equ is not needed to be processed on pass 2	
+	if (as -> passnum != 1)
+		return;
+
 	if (l -> sym == NULL)
 	{
 		register_error(as, l, 1, "No symbol specified");