changeset 12:6b9991fb39b6

Brought forward patch to fix bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Sat, 22 Jan 2011 16:11:15 -0700
parents a0317b794b7b
children c80e5a063967
files lwasm/output.c lwlib/lw_expr.c lwlib/lw_expr.h
diffstat 3 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/output.c	Sat Jan 22 16:10:42 2011 -0700
+++ b/lwasm/output.c	Sat Jan 22 16:11:15 2011 -0700
@@ -234,6 +234,7 @@
 {
 	int tt;
 	int v;
+	int count = 1;
 	unsigned char buf[16];
 	
 	tt = lw_expr_type(e);
@@ -242,10 +243,12 @@
 	{
 	case lw_expr_type_oper:
 		buf[0] =  0x04;
+		
 		switch (lw_expr_whichop(e))
 		{
 		case lw_expr_oper_plus:
 			buf[1] = 0x01;
+			count = lw_expr_operandcount(e) - 1;
 			break;
 		
 		case lw_expr_oper_minus:
@@ -254,6 +257,7 @@
 		
 		case lw_expr_oper_times:
 			buf[1] = 0x03;
+			count = lw_expr_operandcount(e) - 1;
 			break;
 		
 		case lw_expr_oper_divide:
@@ -299,7 +303,8 @@
 		default:
 			buf[1] = 0xff;
 		}
-		writebytes(buf, 2, 1, of);
+		while (count--)
+			writebytes(buf, 2, 1, of);
 		return 0;
 
 	case lw_expr_type_int:
--- a/lwlib/lw_expr.c	Sat Jan 22 16:10:42 2011 -0700
+++ b/lwlib/lw_expr.c	Sat Jan 22 16:11:15 2011 -0700
@@ -1268,3 +1268,17 @@
 {
 	return e -> value2;
 }
+
+int lw_expr_operandcount(lw_expr_t e)
+{
+	int count = 0;
+	struct lw_expr_opers *o;
+	
+	if (e -> type != lw_expr_type_oper)
+		return 0;
+	
+	for (o = e -> operands; o; o = o -> next)
+		count++;
+	
+	return count;
+}
--- a/lwlib/lw_expr.h	Sat Jan 22 16:10:42 2011 -0700
+++ b/lwlib/lw_expr.h	Sat Jan 22 16:11:15 2011 -0700
@@ -105,6 +105,8 @@
 
 typedef int lw_expr_testfn_t(lw_expr_t e, void *priv);
 
+extern int lw_expr_operandcount(lw_expr_t e);
+
 // run a function on all terms in an expression; if the function
 // returns non-zero for any term, return non-zero, else return
 // zero