diff lwasm/pseudo.c @ 351:4dba8c7e242c

conditional pseudo ops added
author lost@starbug
date Sat, 27 Mar 2010 23:37:30 -0600
parents f5666775d76f
children 60568b123281
line wrap: on
line diff
--- a/lwasm/pseudo.c	Sat Mar 27 22:59:15 2010 -0600
+++ b/lwasm/pseudo.c	Sat Mar 27 23:37:30 2010 -0600
@@ -511,6 +511,8 @@
 {
 	lw_expr_t e;
 	
+	l -> len = 0;
+	
 	e = lwasm_parse_expr(as, p);
 	if (!e)
 	{
@@ -527,6 +529,8 @@
 {
 	lw_expr_t e;
 	
+	l -> len = 0;
+	
 	if (!(l -> sym))
 	{
 		lwasm_register_error(as, l, "Missing symbol");
@@ -543,3 +547,363 @@
 	register_symbol(as, l, l -> sym, e, symbol_flag_none);
 	l -> symset = 1;
 }
+
+PARSEFUNC(pseudo_parse_set)
+{
+	lw_expr_t e;
+	
+	l -> len = 0;
+	
+	if (!(l -> sym))
+	{
+		lwasm_register_error(as, l, "Missing symbol");
+		return;
+	}
+	
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	register_symbol(as, l, l -> sym, e, symbol_flag_set);
+	l -> symset = 1;
+}
+
+PARSEFUNC(pseudo_parse_setdp)
+{
+	lw_expr_t e;
+
+	l -> len = 0;
+	
+	if (as -> output_format == OUTPUT_OBJ)
+	{
+		lwasm_register_error(as, l, "SETDP not permitted for object target");
+		return;
+	}
+	
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		lwasm_register_error(as, l, "SETDP must be constant on pass 1");
+		return;
+	}
+	l -> dpval = lw_expr_intval(e) & 0xff;
+}
+
+PARSEFUNC(pseudo_parse_ifp1)
+{
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+	
+	lwasm_register_warning(as, l, "IFP1 if is not supported; ignoring");
+	
+}
+
+PARSEFUNC(pseudo_parse_ifp2)
+{
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+	
+	lwasm_register_warning(as, l, "IFP2 if is not supported; ignoring");
+}
+
+PARSEFUNC(pseudo_parse_ifeq)
+{
+	lw_expr_t e;
+	
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+		return;
+	}
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		lwasm_register_error(as, l, "Conditions must be constant on pass 1");
+		return;
+	}
+	if (lw_expr_intval(e) != 0)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+
+PARSEFUNC(pseudo_parse_ifne)
+{
+	lw_expr_t e;
+	
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+		return;
+	}
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		lwasm_register_error(as, l, "Conditions must be constant on pass 1");
+		return;
+	}
+	if (lw_expr_intval(e) == 0)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+
+
+PARSEFUNC(pseudo_parse_ifgt)
+{
+	lw_expr_t e;
+	
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+		return;
+	}
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		lwasm_register_error(as, l, "Conditions must be constant on pass 1");
+		return;
+	}
+	if (lw_expr_intval(e) <= 0)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+
+PARSEFUNC(pseudo_parse_ifge)
+{
+	lw_expr_t e;
+	
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+		return;
+	}
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		lwasm_register_error(as, l, "Conditions must be constant on pass 1");
+		return;
+	}
+	if (lw_expr_intval(e) < 0)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+
+PARSEFUNC(pseudo_parse_iflt)
+{
+	lw_expr_t e;
+	
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+		return;
+	}
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		lwasm_register_error(as, l, "Conditions must be constant on pass 1");
+		return;
+	}
+	if (lw_expr_intval(e) >= 0)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+
+PARSEFUNC(pseudo_parse_ifle)
+{
+	lw_expr_t e;
+
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	e = lwasm_parse_expr(as, p);
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+		return;
+	}
+	if (!lw_expr_istype(e, lw_expr_type_int))
+	{
+		lwasm_register_error(as, l, "Conditions must be constant on pass 1");
+		return;
+	}
+	if (lw_expr_intval(e) > 0)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+
+PARSEFUNC(pseudo_parse_endc)
+{
+	l -> len = 0;
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount--;
+		if (as -> skipcount < 0)
+			as -> skipcond = 0;
+	}
+}
+
+PARSEFUNC(pseudo_parse_else)
+{
+	l -> len = 0;
+	
+	if (as -> skipmacro)
+		return;
+	
+	if (as -> skipcond)
+	{
+		if (as -> skipcount == 1)
+		{
+			as -> skipcount = 0;
+			as -> skipcond = 0;
+		}
+		return;
+	}
+	as -> skipcond = 1;
+	as -> skipcount = 1;
+}
+
+PARSEFUNC(pseudo_parse_ifdef)
+{
+	char *sym;
+	int i;
+	struct symtabe *s;
+	
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
+		/* do nothing */ ;
+	
+	sym = lw_strndup(*p, i);
+	
+	s = lookup_symbol(as, l, sym, -1, -1);
+	
+	lw_free(sym);
+	
+	if (!s)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+
+PARSEFUNC(pseudo_parse_ifndef)
+{
+	char *sym;
+	int i;
+	struct symtabe *s;
+	
+	l -> len = 0;
+	
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+	for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
+		/* do nothing */ ;
+	
+	sym = lw_strndup(*p, i);
+	
+	s = lookup_symbol(as, l, sym, -1, -1);
+	
+	lw_free(sym);
+
+	if (s)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+}
+