changeset 416:1d69ed28f175

Fixed offset problem with emission of incomplete references at start of insn
author lost@l-w.ca
date Tue, 10 Aug 2010 22:00:21 -0600
parents 2d7255509130
children f792faf877bb
files lwasm/lwasm.c
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/lwasm.c	Tue Aug 10 21:59:49 2010 -0600
+++ b/lwasm/lwasm.c	Tue Aug 10 22:00:21 2010 -0600
@@ -624,8 +624,13 @@
 
 int lwasm_emitexpr(line_t *l, lw_expr_t expr, int size)
 {
-	int v;
+	int v = 0;
+	int ol;
 	
+	ol = l -> outputl;
+	if (ol == -1)
+		ol = 0;
+		
 	if (lw_expr_istype(expr, lw_expr_type_int))
 	{
 		v = lw_expr_intval(expr);
@@ -650,7 +655,7 @@
 				re = lw_alloc(sizeof(reloctab_t));
 				re -> next = l -> csect -> reloctab;
 				l -> csect -> reloctab = re;
-				te = lw_expr_build(lw_expr_type_int, l -> outputl);
+				te = lw_expr_build(lw_expr_type_int, ol);
 				re -> offset = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, l -> addr, te);
 				lw_expr_destroy(te);
 				lwasm_reduce_expr(l -> as, re -> offset);
@@ -664,7 +669,7 @@
 				re = lw_alloc(sizeof(reloctab_t));
 				re -> next = l -> csect -> reloctab;
 				l -> csect -> reloctab = re;
-				te = lw_expr_build(lw_expr_type_int, l -> outputl + 2);
+				te = lw_expr_build(lw_expr_type_int, ol + 2);
 				re -> offset = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, l -> addr, te);
 				lw_expr_destroy(te);
 				lwasm_reduce_expr(l -> as, re -> offset);
@@ -677,7 +682,7 @@
 				re = lw_alloc(sizeof(reloctab_t));
 				re -> next = l -> csect -> reloctab;
 				l -> csect -> reloctab = re;
-				te = lw_expr_build(lw_expr_type_int, l -> outputl);
+				te = lw_expr_build(lw_expr_type_int, ol);
 				re -> offset = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, l -> addr, te);
 				lw_expr_destroy(te);
 				lwasm_reduce_expr(l -> as, re -> offset);