changeset 186:1824cabf25ce

Various enhancements to lwasm
author lost@l-w.ca
date Thu, 22 Dec 2011 18:04:13 -0700
parents cca933d32298
children 4e12d881df85
files lwasm/input.c lwasm/instab.c lwasm/main.c lwasm/pseudo.c
diffstat 4 files changed, 91 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/input.c	Thu Dec 22 18:03:38 2011 -0700
+++ b/lwasm/input.c	Thu Dec 22 18:04:13 2011 -0700
@@ -264,6 +264,8 @@
 	{
 		/* absolute path */
 		debug_message(as, 2, "Open file (st abs) %s", s);
+		if (as -> flags & FLAG_DEPEND)
+			printf("%s\n", s);
 		fp = fopen(s, "rb");
 		if (!fp)
 		{
@@ -279,6 +281,8 @@
 	fp = fopen(p2, "rb");
 	if (fp)
 	{
+		if (as -> flags & FLAG_DEPEND)
+			printf("%s\n", p2);
 		lw_free(p2);
 		return fp;
 	}
@@ -293,12 +297,23 @@
 		fp = fopen(p2, "rb");
 		if (fp)
 		{
+			if (as -> flags & FLAG_DEPEND)
+				printf("%s\n", p2);
 			lw_free(p2);
 			return fp;
 		}
 		lw_free(p2);
 		lw_stringlist_next(as -> include_list);
 	}
+
+	// last ditch output for dependencies
+	if (as -> flags & FLAG_DEPEND)
+	{
+		p = lw_stack_top(as -> file_dir);
+		p2 = make_filename(p ? p : "", s);
+		printf("%s\n", p2);
+		lw_free(p2);
+	}
 	
 	return NULL;
 }
--- a/lwasm/instab.c	Thu Dec 22 18:03:38 2011 -0700
+++ b/lwasm/instab.c	Thu Dec 22 18:04:13 2011 -0700
@@ -312,6 +312,10 @@
 extern RESOLVEFUNC(pseudo_resolve_align);
 extern EMITFUNC(pseudo_emit_align);
 
+extern PARSEFUNC(pseudo_parse_fill);
+extern RESOLVEFUNC(pseudo_resolve_fill);
+extern EMITFUNC(pseudo_emit_fill);
+
 extern PARSEFUNC(pseudo_parse_struct);
 #define pseudo_resolve_struct NULL
 #define pseudo_emit_struct NULL
@@ -613,6 +617,7 @@
 	{ "use",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_include,	pseudo_resolve_include,			pseudo_emit_include,		lwasm_insn_normal},
 	
 	{ "align", 		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_align,		pseudo_resolve_align,			pseudo_emit_align,			lwasm_insn_normal},
+	{ "fill",		{	-1,		-1,		-1,		-1 },	pseudo_parse_fill,		pseudo_resolve_fill,			pseudo_emit_fill,			lwasm_insn_normal},
 
 	{ "error",		{	-1, 	-1, 	-1, 	-1},	pseudo_parse_error,		pseudo_resolve_error,			pseudo_emit_error,			lwasm_insn_normal},
 	{ "warning",	{	-1, 	-1, 	-1, 	-1},	pseudo_parse_warning,	pseudo_resolve_warning,			pseudo_emit_warning,		lwasm_insn_normal},
--- a/lwasm/main.c	Thu Dec 22 18:03:38 2011 -0700
+++ b/lwasm/main.c	Thu Dec 22 18:04:13 2011 -0700
@@ -280,7 +280,7 @@
 
 	if (asmstate.flags & FLAG_DEPEND)
 	{
-		// output dependencies
+		// output dependencies (other than "includebin")
 		char *n;
 		
 		while ((n = lw_stack_pop(asmstate.includelist)))
--- a/lwasm/pseudo.c	Thu Dec 22 18:03:38 2011 -0700
+++ b/lwasm/pseudo.c	Thu Dec 22 18:04:13 2011 -0700
@@ -1448,6 +1448,76 @@
 	}
 }
 
+PARSEFUNC(pseudo_parse_fill)
+{
+	lw_expr_t e, e1;
+	if (!**p)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	e1 = lwasm_parse_expr(as, p);
+	if (**p != ',')
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	(*p)++;
+	e = lwasm_parse_expr(as, p);
+	
+	if (!e)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	lwasm_save_expr(l, 0, e);
+	lwasm_save_expr(l, 1, e1);
+
+	if (!e1)
+	{
+		lwasm_register_error(as, l, "Bad padding");
+		return;
+	}
+}
+
+RESOLVEFUNC(pseudo_resolve_fill)
+{
+	lw_expr_t e;
+	int align;
+
+	e = lwasm_fetch_expr(l, 0);
+	
+	if (lw_expr_istype(e, lw_expr_type_int))
+	{
+		align = lw_expr_intval(e);
+		if (align < 1)
+		{
+			lwasm_register_error(as, l, "Invalid fill length");
+			return;
+		}
+	}
+	
+	if (lw_expr_istype(l -> addr, lw_expr_type_int))
+	{
+		l -> len = align;
+		return;
+	}
+}
+
+EMITFUNC(pseudo_emit_fill)
+{
+	lw_expr_t e;
+	int i;
+	
+	e = lwasm_fetch_expr(l, 1);
+	for (i = 0; i < l -> len; i++)
+	{
+		lwasm_emitexpr(l, e, 1);
+	}
+}
+
 /* string conditional argument parser */
 /*
 argument syntax: