changeset 56:55260a178667

Added from f* pseudo ops
author lost
date Sun, 04 Jan 2009 21:43:05 +0000
parents 8e32696380f3
children 035b95a3690f
files src/instab.c src/pseudo.c
diffstat 2 files changed, 127 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/src/instab.c	Sun Jan 04 21:42:54 2009 +0000
+++ b/src/instab.c	Sun Jan 04 21:43:05 2009 +0000
@@ -51,6 +51,14 @@
 extern OPFUNC(pseudo_zmq);
 extern OPFUNC(pseudo_include);
 extern OPFUNC(pseudo_end);
+extern OPFUNC(pseudo_align);
+extern OPFUNC(pseudo_error);
+extern OPFUNC(pseudo_fcc);
+extern OPFUNC(pseudo_fcs);
+extern OPFUNC(pseudo_fcn);
+extern OPFUNC(pseudo_fcb);
+extern OPFUNC(pseudo_fdb);
+extern OPFUNC(pseudo_fqb);
 
 instab_t instab[] =
 {
@@ -307,9 +315,21 @@
 	{ "zmd", 	{ -1, -1, -1, -1 }, pseudo_zmd },
 	{ "zmq", 	{ -1, -1, -1, -1 }, pseudo_zmq },
 
+	{ "fcc",	{ -1, -1, -1, -1 },	pseudo_fcc },
+	{ "fcn",	{ -1, -1, -1, -1 },	pseudo_fcc },
+	{ "fcs",	{ -1, -1, -1, -1 },	pseudo_fcc },
+
+	{ "fcb",	{ -1, -1, -1, -1 },	pseudo_fcb },
+	{ "fdb",	{ -1, -1, -1, -1 },	pseudo_fdb },
+	{ "fqb",	{ -1, -1, -1, -1 },	pseudo_fqb },
+
 	{ "end", 	{ -1, -1, -1, -1 }, pseudo_end },
 
 	{ "include", { -1, -1, -1, -1 }, pseudo_include },
+	
+	{ "align", { -1, -1, -1, -1 },	pseudo_align },
+
+	{ "error",	{ -1, -1, -1, -1},	pseudo_error },
 
 	/* flag end of table */	
 	{ NULL,		{ -0x1, -0x1, -0x1, -0x1 }, insn_inh }
--- a/src/pseudo.c	Sun Jan 04 21:42:54 2009 +0000
+++ b/src/pseudo.c	Sun Jan 04 21:43:05 2009 +0000
@@ -308,29 +308,50 @@
 	}
 }
 
-/*
-void pseudo_align(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_align)
 {
-	int rval, v1;
+	int rval;
+	lwasm_expr_stack_t *s;
 	int cn;
 
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+	if (as -> passnum == 2)
 	{
-		errorp1(ERR_FORWARD);
+		while (as -> addr < l -> symaddr)
+			lwasm_emit(as, l, 0);
+		return;
+	}
+	
+	s = lwasm_evaluate_expr(as, l, *p, NULL);
+	if (!s)
+	{
+		register_error(as, l, 1, "Bad expression");
 		return;
 	}
-	cn = cl -> addr % v1;
-	if (cn)
-	cn = v1 - cn; 
+	if (!lwasm_expr_is_constant(s))
+	{
+		register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
+	}
+	rval = lwasm_expr_get_value(s);
+	lwasm_expr_stack_free(s);
 
-	while (cn)
+	if (rval < 1)
 	{
-		emit(0);
-		cn--;
+		register_error(as, l, 1, "Illegal alignment %d", rval);
+		return;
 	}
+	
+	cn = l -> codeaddr % rval;
+	if (cn)
+		cn = rval - cn; 
+
+	while (cn--)
+	{
+		lwasm_emit(as, l, 0);
+	}
+	l -> symaddr = as -> addr;
 }
-*/
+
 OPFUNC(pseudo_equ)
 {
 	lwasm_expr_stack_t *s;
@@ -433,125 +454,126 @@
 	cl -> numcodebytes = 0;
 //printf("%s\n", "SETDP2");
 }
+*/
 
-void pseudo_fcc(asmstate_t *as, sourceline_t *cl, char **optr)
-{		
-	int cn = 0;
+OPFUNC(pseudo_fcc)
+{
 	int delim = 0;
 				
-	delim = *(*optr)++;
+	delim = **p;
 	if (!delim)
 	{
-		errorp1(ERR_BADOPER);
+		register_error(as, l, 1, "Bad operand");
+		return;
 	}
-	else
+	*p += 1;
+	while (**p && **p != delim)
 	{
-		while (**optr && **optr != delim)
-		{
-			emit(**optr);
-			(*optr)++;
-			cn += 1;
-		}
+		lwasm_emit(as, l, **p);
+		(*p)++;
 	}
-	cl -> len = cn;
+	if (**p)
+		(*p)++;
 }
 		
-void pseudo_fcs(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_fcs)
 {
-	int cn = 0;
 	int delim = 0;
-				
-	delim = *(*optr)++;
+
+	delim = **p;
 	if (!delim)
 	{
-		errorp1(ERR_BADOPER);
+		register_error(as, l, 1, "Bad operand");
+		return;
 	}
-	else
+	*p += 1;
+	while (**p && **p != delim)
 	{
-		while (**optr && **optr != delim)
-		{
-			if (!*((*optr) + 1) || *((*optr) + 1) == delim)
-				emit((**optr) | 0x80);
-			else
-				emit(**optr);
-			(*optr)++;
-			cn += 1;
-		}
+		if (!*((*p) + 1) || *((*p) + 1) == delim)
+			lwasm_emit(as, l, **p | 0x80);
+		else
+			lwasm_emit(as, l, **p);
+		(*p)++;
 	}
-	cl -> len = cn;
+	if (**p)
+		(*p)++;
 }
 
-void pseudo_fcn(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_fcn)
 {		
-	int cn = 0;
 	int delim = 0;
 				
-	delim = *(*optr)++;
+	delim = **p;
 	if (!delim)
 	{
-		errorp1(ERR_BADOPER);
+		register_error(as, l, 1, "Bad operand");
+		return;
 	}
-	else
+	*p += 1;
+	while (**p && **p != delim)
 	{
-		while (**optr && **optr != delim)
-		{
-			emit(**optr);
-			(*optr)++;
-			cn += 1;
-		}
+		lwasm_emit(as, l, **p);
+		(*p)++;
 	}
-	emit(0);
-	cl -> len = cn + 1;
+	if (**p)
+		(*p)++;
+	lwasm_emit(as, l, 0);
 }
-		
-void pseudo_fcb(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_fcb)
 {
-	int rval, v1;
+	int v1;
 	
 fcb_again:
-	rval = eval_expr(as, cl, optr, &v1);
-	if (v1 < -127 || v1 > 0xff)
-		errorp2(ERR_OVERFLOW);
-	emit(v1 & 0xff);
-	if (**optr == ',')
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST | EXPR_BYTE, &v1) < 0)
+		return;
+	
+	lwasm_emit(as, l, v1);
+	if (**p == ',')
 	{
-		(*optr)++;
+		(*p)++;
 		goto fcb_again;
 	}
 }
 
-void pseudo_fdb(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_fdb)
 {			
-	int rval, v1;
+	int v1;
 	
 fdb_again:
-	rval = eval_expr(as, cl, optr, &v1);
-	emit((v1 >> 8) & 0xff);
-	emit(v1 & 0xff);
-	if (**optr == ',')
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
+		return;
+	
+	lwasm_emit(as, l, v1 >> 8);
+	lwasm_emit(as, l, v1 & 0xff);
+	if (**p == ',')
 	{
-		(*optr)++;
+		(*p)++;
 		goto fdb_again;
 	}
 }
 
-void pseudo_fqb(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_fqb)
 {	
-	int rval, v1;
-
+	int v1;
+	
 fqb_again:
-	rval = eval_expr(as, cl, optr, &v1);
-	emit((v1 >> 24) & 0xff);
-	emit((v1 >> 16) & 0xff);
-	emit((v1 >> 8) & 0xff);
-	emit(v1 & 0xff);
-	if (**optr == ',')
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
+		return;
+	
+	lwasm_emit(as, l, v1 >> 24);
+	lwasm_emit(as, l, v1 >> 16);
+	lwasm_emit(as, l, v1 >> 8);
+	lwasm_emit(as, l, v1 & 0xff);
+	if (**p == ',')
 	{
-		(*optr)++;
+		(*p)++;
 		goto fqb_again;
 	}
 }
 
+/*
 // don't need to do anything if we are executing one of these
 void pseudo_endc(asmstate_t *as, sourceline_t *cl, char **optr)
 {
@@ -681,10 +703,10 @@
 		}
 	}
 }
+*/
 
-void pseudo_error(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_error)
 {
-	cl -> user_error = strdup(*optr);
-	errorp1(ERR_USER);
+	register_error(as, l, 1, "User error: %s", *p);
 }
-*/
+