# HG changeset patch # User lost@l-w.ca # Date 1295737875 25200 # Node ID 6b9991fb39b6c90f33796516693e233491e91719 # Parent a0317b794b7b428652062d6dcaae1e012250aaa7 Brought forward patch to fix bug with complex external references generating invalid relocations in the object file diff -r a0317b794b7b -r 6b9991fb39b6 lwasm/output.c --- 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: diff -r a0317b794b7b -r 6b9991fb39b6 lwlib/lw_expr.c --- 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; +} diff -r a0317b794b7b -r 6b9991fb39b6 lwlib/lw_expr.h --- 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