diff lwasm/pass1.c @ 389:fbb7bfed8076

Added in structure support and fixed up some warts in the listing code (by adding more warts)
author lost@l-w.ca
date Wed, 14 Jul 2010 22:33:55 -0600
parents cf8c92d70eb1
children acaafc70044b
line wrap: on
line diff
--- a/lwasm/pass1.c	Wed Jul 14 20:17:57 2010 -0600
+++ b/lwasm/pass1.c	Wed Jul 14 22:33:55 2010 -0600
@@ -31,6 +31,9 @@
 #include "instab.h"
 #include "input.h"
 
+extern int expand_macro(asmstate_t *as, line_t *l, char **p, char *opc);
+extern int expand_struct(asmstate_t *as, line_t *l, char **p, char *opc);
+
 /*
 pass 1: parse the lines
 
@@ -91,6 +94,10 @@
 		cl -> pragmas = as -> pragmas;
 		cl -> context = as -> context;
 		cl -> ltext = lw_strdup(line);
+		cl -> soff = -1;
+		cl -> dshow = -1;
+		cl -> dsize = 0;
+		cl -> dptr = NULL;
 		as -> cl = cl;
 		if (!as -> line_tail)
 		{
@@ -226,7 +233,7 @@
 			// do nothing
 			if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond))
 				goto linedone;
-        			
+        	
 			if (instab[opnum].opcode == NULL)
 			{
 				cl -> insn = -1;
@@ -236,7 +243,11 @@
 					if (expand_macro(as, cl, &p1, sym) != 0)
 					{
 						// macro expansion failed
-						lwasm_register_error(as, cl, "Bad opcode");
+						if (expand_struct(as, cl, &p1, sym) != 0)
+						{
+							// structure expansion failed
+							lwasm_register_error(as, cl, "Bad opcode");
+						}
 					}
 				}
 			}
@@ -246,13 +257,20 @@
 				// no parse func means operand doesn't matter
 				if (instab[opnum].parse)
 				{
-					cl -> len = -1;
-					// call parse function
-					(instab[opnum].parse)(as, cl, &p1);
+					if (as -> instruct == 0 || instab[opnum].flags & lwasm_insn_struct)
+					{
+						cl -> len = -1;
+						// call parse function
+						(instab[opnum].parse)(as, cl, &p1);
 					
-					if (*p1 && !isspace(*p1))
+						if (*p1 && !isspace(*p1))
+						{
+							// flag bad operand error
+							lwasm_register_error(as, cl, "Bad operand (%s)", p1);
+						}
+					}
+					else if (as -> instruct == 1)
 					{
-						// flag bad operand error
 						lwasm_register_error(as, cl, "Bad operand (%s)", p1);
 					}
 				}