diff lwasm/lwasm.c @ 374:d99322ef6f21

Stage 1: actually do output
author lost@starbug
date Sat, 24 Apr 2010 14:15:18 -0600
parents 9c24d9d485b9
children 3498b2d88376
line wrap: on
line diff
--- a/lwasm/lwasm.c	Thu Apr 22 18:30:30 2010 -0600
+++ b/lwasm/lwasm.c	Sat Apr 24 14:15:18 2010 -0600
@@ -189,6 +189,9 @@
 
 void lwasm_emit(line_t *cl, int byte)
 {
+	if (cl -> outputl < 0)
+		cl -> outputl = 0;
+
 	if (cl -> outputl == cl -> outputbl)
 	{
 		cl -> output = lw_realloc(cl -> output, cl -> outputbl + 8);
@@ -605,6 +608,23 @@
 	// handle external/cross-section/incomplete references here
 	else
 	{
+		if (l -> as -> output_format == OUTPUT_OBJ)
+		{
+			reloctab_t *re;
+			
+			// add "expression" record to section table
+			v = lw_expr_intval(l -> addr) + l -> outputl;
+			re = lw_alloc(sizeof(reloctab_t));
+			re -> next = l -> csect -> reloctab;
+			l -> csect -> reloctab = re;
+			re -> offset = v;
+			re -> size = size;
+			re -> expr = lw_expr_copy(expr);
+			
+			for (v = 0; v < size; v++)
+				lwasm_emit(l, 0);
+			return 0;
+		}
 		lwasm_register_error(l -> as, l, "Expression not fully resolved");
 		return -1;
 	}