changeset 50:e672232caffe

Added rmb pseudo op
author lost
date Sun, 04 Jan 2009 07:56:55 +0000
parents 21ae0fab469b
children 04868fa52a15
files src/instab.c src/list.c src/pseudo.c
diffstat 3 files changed, 62 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/instab.c	Sun Jan 04 07:37:19 2009 +0000
+++ b/src/instab.c	Sun Jan 04 07:56:55 2009 +0000
@@ -40,7 +40,10 @@
 extern OPFUNC(insn_logicmem);
 extern OPFUNC(insn_tfm);
 extern OPFUNC(insn_indexed);
+
 extern OPFUNC(pseudo_org);
+extern OPFUNC(pseudo_equ);
+extern OPFUNC(pseudo_rmb);
 
 instab_t instab[] =
 {
@@ -286,6 +289,11 @@
 
 	{ "org",	{ -1, -1, -1, -1 },	pseudo_org },
 
+	{ "equ",	{ -1, -1, -1, -1 },	pseudo_equ },
+	{ "=",		{ -1, -1, -1, -1 },	pseudo_equ },
+
+	{ "rmb", 	{ -1, -1, -1, -1 }, pseudo_rmb },
+
 	/* flag end of table */	
 	{ NULL,		{ -0x1, -0x1, -0x1, -0x1 }, insn_inh }
 };
--- a/src/list.c	Sun Jan 04 07:37:19 2009 +0000
+++ b/src/list.c	Sun Jan 04 07:56:55 2009 +0000
@@ -76,14 +76,21 @@
 			fprintf(lf, "     ");
 		}
 		
-		for (c = 0; c < l -> codelen && c < 5; c++)
+		if (l -> addrset == 2)
 		{
-			fprintf(lf, "%02X", l -> bytes[c]);
+			fprintf(lf, "%04X      ", l -> symaddr);
 		}
-		while (c < 5)
+		else
 		{
-			fprintf(lf, "  ");
-			c++;
+			for (c = 0; c < l -> codelen && c < 5; c++)
+			{
+				fprintf(lf, "%02X", l -> bytes[c]);
+			}
+			while (c < 5)
+			{
+				fprintf(lf, "  ");
+				c++;
+			}
 		}
 		fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno);
 		
--- a/src/pseudo.c	Sun Jan 04 07:37:19 2009 +0000
+++ b/src/pseudo.c	Sun Jan 04 07:56:55 2009 +0000
@@ -22,6 +22,7 @@
 */
 
 #include <stdlib.h>
+#include <string.h>
 #include "lwasm.h"
 #include "instab.h"
 #include "expr.h"
@@ -45,9 +46,11 @@
 	if (!lwasm_expr_is_constant(s))
 	{
 		register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
+		lwasm_expr_stack_free(s);
 		return;
 	}
 	rval = lwasm_expr_get_value(s) & 0xffff;
+	lwasm_expr_stack_free(s);
 	l -> codeaddr = rval;
 	l -> addrset = 1;
 	as -> addr = rval;
@@ -77,26 +80,30 @@
 	}
 }
 
-
-void pseudo_rmb(asmstate_t *as, sourceline_t *cl, char **optr)
+*/
+OPFUNC(pseudo_rmb)
 {
-	int rval, v1;
+	int rval;
+	lwasm_expr_stack_t *s;
 	
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+	s = lwasm_evaluate_expr(as, l, *p, NULL);
+	if (!s)
 	{
-		errorp1(ERR_FORWARD);
+		register_error(as, l, 1, "Bad expression");
 		return;
 	}
-	if (v1 < 0)
+	if (!lwasm_expr_is_constant(s))
 	{
-		errorp1(ERR_BADOPER);
+		register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
+		lwasm_expr_stack_free(s);
 		return;
 	}
-	cl -> len = v1;
-	cl -> nocode = 1;
+	rval = lwasm_expr_get_value(s);
+	lwasm_expr_stack_free(s);
+	l -> nocodelen = rval;
+	as -> addr += rval;
 }
-
+/*
 void pseudo_rmd(asmstate_t *as, sourceline_t *cl, char **optr)
 {
 	int rval, v1;
@@ -244,37 +251,40 @@
 		cn--;
 	}
 }
-
-void pseudo_equ(asmstate_t *as, sourceline_t *cl, char **optr)
+*/
+OPFUNC(pseudo_equ)
 {
-	int rval, v1;
+	lwasm_expr_stack_t *s;
+	int rval;
 	
-	if (cl -> hassym == 0)
+	if (l -> sym == NULL)
 	{
-		errorp1(ERR_NOSYM);
+		register_error(as, l, 1, "No symbol specified");
 		return;
 	}
-	rval = eval_expr(as, cl, optr, &v1);
-	// eval_expr returns -1 if there was a forward ref
-	// or -2 if the expr was invalid
-	if (rval == -2)
+
+	s = lwasm_evaluate_expr(as, l, *p, NULL);
+	
+	if (!s)
 	{
-		// carp
-		errorp1(ERR_FORWARD);
+		register_error(as, l, 1, "Bad expression");
+		rval = 0;
 	}
-	if (rval < 0)
+	else
 	{
-		// remove symbol ref
-		cl -> hassym = 0;
-		// mark as a "comment" so it isn't processed next time
-		cl -> opcode = -1;
-		return;
+		if (!lwasm_expr_is_constant(s))
+			register_error(as, l, 1, "Invalid incomplete reference (pass 1)");
+		rval = lwasm_expr_get_value(s);
+		lwasm_expr_stack_free(s);
 	}
-	cl -> code_symloc = v1;
-	cl -> isequ = 1;
-	cl -> symaddr = v1 & 0xFFFF;
+	l -> symaddr = rval & 0xFFFF;
+	l -> addrset = 2;
+	if (strchr(l -> sym, '@') || strchr(l -> sym, '?'))
+		lwasm_set_symbol(as, l -> sym, as -> context, l -> symaddr);
+	else
+		lwasm_set_symbol(as, l -> sym, -1, l -> symaddr);
 }
-
+/*
 void pseudo_set(asmstate_t *as, sourceline_t *cl, char **optr)
 {
 	int rval, v1;