Mercurial > hg-old > index.cgi
diff src/pseudo.c @ 78:121bf4a588ea
Checkpointing deployment of non-constant expression handling
author | lost |
---|---|
date | Sat, 10 Jan 2009 05:00:42 +0000 |
parents | c8c772ef5df9 |
children | d0ce3f5f6797 |
line wrap: on
line diff
--- a/src/pseudo.c Fri Jan 09 04:23:00 2009 +0000 +++ b/src/pseudo.c Sat Jan 10 05:00:42 2009 +0000 @@ -32,8 +32,7 @@ OPFUNC(pseudo_org) { - int rval; - lwasm_expr_stack_t *s; + int v, r; if (as -> csect) { @@ -55,23 +54,13 @@ { register_error(as, l, 1, "No symbol allowed with ORG"); } - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) - { - register_error(as, l, 1, "Bad expression"); + + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) return; - } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - lwasm_expr_stack_free(s); - return; - } - rval = lwasm_expr_get_value(s) & 0xffff; - lwasm_expr_stack_free(s); - l -> codeaddr = rval; + l -> codeaddr = v; l -> addrset = 1; - as -> addr = rval; + as -> addr = v; } /* @@ -134,155 +123,93 @@ OPFUNC(pseudo_rmb) { - int rval; - lwasm_expr_stack_t *s; + int r, v; - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) + if (as -> passnum == 1) { - register_error(as, l, 1, "Bad expression"); + as -> addr += l -> nocodelen; return; } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - lwasm_expr_stack_free(s); + + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) return; - } - rval = lwasm_expr_get_value(s); - lwasm_expr_stack_free(s); - l -> nocodelen = rval; - as -> addr += rval; + l -> nocodelen = v; + as -> addr += v; } OPFUNC(pseudo_rmd) { - int rval; - lwasm_expr_stack_t *s; + int r, v; - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) + if (as -> passnum == 1) { - register_error(as, l, 1, "Bad expression"); + as -> addr += l -> nocodelen; return; } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - lwasm_expr_stack_free(s); + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) return; - } - rval = lwasm_expr_get_value(s) * 2; - lwasm_expr_stack_free(s); - l -> nocodelen = rval; - as -> addr += rval; + v *= 2; + l -> nocodelen = v; + as -> addr += v; } OPFUNC(pseudo_rmq) { - int rval; - lwasm_expr_stack_t *s; + int r, v; - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) + if (as -> passnum == 1) { - register_error(as, l, 1, "Bad expression"); + as -> addr += l -> nocodelen; return; } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - lwasm_expr_stack_free(s); + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) return; - } - rval = lwasm_expr_get_value(s) * 4; - lwasm_expr_stack_free(s); - l -> nocodelen = rval; - as -> addr += rval; + v *= 4; + l -> nocodelen = v; + as -> addr += v; } OPFUNC(pseudo_zmb) { - int rval; - lwasm_expr_stack_t *s; + int r, v; - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) - { - register_error(as, l, 1, "Bad expression"); + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) return; - } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - lwasm_expr_stack_free(s); - return; - } - rval = lwasm_expr_get_value(s); - lwasm_expr_stack_free(s); - while (rval-- > 0) - { + while (v--) lwasm_emit(as, l, 0); - } } OPFUNC(pseudo_zmd) { - int rval; - lwasm_expr_stack_t *s; + int r, v; - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) - { - register_error(as, l, 1, "Bad expression"); + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) return; - } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - lwasm_expr_stack_free(s); - return; - } - rval = lwasm_expr_get_value(s); - lwasm_expr_stack_free(s); - while (rval-- > 0) - { + v *= 2; + while (v--) lwasm_emit(as, l, 0); - lwasm_emit(as, l, 0); - } } OPFUNC(pseudo_zmq) { - int rval; - lwasm_expr_stack_t *s; + int r, v; - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) - { - register_error(as, l, 1, "Bad expression"); + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) return; - } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - lwasm_expr_stack_free(s); - return; - } - rval = lwasm_expr_get_value(s); - lwasm_expr_stack_free(s); - while (rval-- > 0) - { + v *= 4; + while (v--) lwasm_emit(as, l, 0); - lwasm_emit(as, l, 0); - lwasm_emit(as, l, 0); - lwasm_emit(as, l, 0); - } } OPFUNC(pseudo_end) { - int rval; + int r, v; lwasm_expr_stack_t *s; @@ -292,24 +219,17 @@ if (as -> outformat != OUTPUT_DECB) return; - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) + r = lwasm_expr_result2(as, l, p, 0, &v, 0); + if (r != 0) { - register_error(as, l, 1, "Bad expression"); - return; + register_error(as, l, 2, "Bad operand"); } - if (!lwasm_expr_is_constant(s)) - { - register_error(as, l, 2, "Incomplete reference"); - } - rval = lwasm_expr_get_value(s); - lwasm_expr_stack_free(s); - rval = rval & 0xffff; + v = v & 0xffff; if (as -> passnum == 2) { - as -> execaddr = rval; - l -> symaddr = rval; + as -> execaddr = v; + l -> symaddr = v; l -> addrset = 2; } } @@ -317,10 +237,9 @@ OPFUNC(pseudo_align) { - int rval; - lwasm_expr_stack_t *s; int cn; - + int r, v; + if (as -> passnum == 2) { while (as -> addr < l -> symaddr) @@ -328,28 +247,22 @@ return; } - s = lwasm_evaluate_expr(as, l, *p, NULL); - if (!s) + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r != 0) { - register_error(as, l, 1, "Bad expression"); + l -> symaddr = as -> addr; return; } - if (!lwasm_expr_is_constant(s)) + + if (v < 1) { - register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); - } - rval = lwasm_expr_get_value(s); - lwasm_expr_stack_free(s); - - if (rval < 1) - { - register_error(as, l, 1, "Illegal alignment %d", rval); + register_error(as, l, 1, "Illegal alignment %d", v); return; } - cn = l -> codeaddr % rval; + cn = l -> codeaddr % v; if (cn) - cn = rval - cn; + cn = v - cn; while (cn--) { @@ -360,11 +273,7 @@ OPFUNC(pseudo_equ) { - int rval; - - // equ is not needed to be processed on pass 2 - if (as -> passnum != 1) - return; + int r, v; if (l -> sym == NULL) { @@ -372,13 +281,14 @@ return; } - if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &rval) < 0) - rval = 0; + r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); + if (r < 0) + v = 0; - l -> symaddr = rval & 0xFFFF; + l -> symaddr = v & 0xFFFF; l -> addrset = 2; - lwasm_register_symbol(as, l, l -> sym, rval, SYMBOL_NORM); + lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE); } OPFUNC(pseudo_set)