comparison src/insn_rel.c @ 59:89657cb3fdf8

Moved insn_rel.c to simplified expression evaluation
author lost
date Mon, 05 Jan 2009 00:40:58 +0000
parents 538e15927776
children a338d496350e
comparison
equal deleted inserted replaced
58:b1d81800bc91 59:89657cb3fdf8
30 #include "lwasm.h" 30 #include "lwasm.h"
31 #include "instab.h" 31 #include "instab.h"
32 32
33 OPFUNC(insn_rel8) 33 OPFUNC(insn_rel8)
34 { 34 {
35 lwasm_expr_stack_t *s;
36 int v; 35 int v;
37 36
38 lwasm_emitop(as, l, instab[opnum].ops[0]); 37 lwasm_emitop(as, l, instab[opnum].ops[0]);
39 38
40 s = lwasm_evaluate_expr(as, l, *p, NULL); 39 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0)
41 if (!s)
42 { 40 {
43 register_error(as, l, 1, "Bad operand"); 41 v = 0;
44 lwasm_emitop(as, l, 0);
45 return;
46 } 42 }
47 if (lwasm_expr_is_constant(s))
48 register_error(as, l, 2, "Incomplete reference");
49 v = lwasm_expr_get_value(s);
50 v -= as -> addr + 1; 43 v -= as -> addr + 1;
51 if (v < -128 || v > 127) 44 if (v < -128 || v > 127)
52 register_error(as, l, 2, "Byte overflow"); 45 register_error(as, l, 2, "Byte overflow");
53 lwasm_emit(as, l, v & 0xff); 46 lwasm_emit(as, l, v & 0xff);
54
55 lwasm_expr_stack_free(s);
56 } 47 }
57 48
58 OPFUNC(insn_rel16) 49 OPFUNC(insn_rel16)
59 { 50 {
60 lwasm_expr_stack_t *s;
61 int v; 51 int v;
62 52
63 lwasm_emitop(as, l, instab[opnum].ops[0]); 53 lwasm_emitop(as, l, instab[opnum].ops[0]);
64 54
65 s = lwasm_evaluate_expr(as, l, *p, NULL); 55 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0)
66 if (!s) 56 v = 0;
67 {
68 register_error(as, l, 1, "Bad operand");
69 lwasm_emitop(as, l, 0);
70 return;
71 }
72 if (lwasm_expr_is_constant(s))
73 register_error(as, l, 2, "Incomplete reference");
74 v = lwasm_expr_get_value(s);
75 v -= as -> addr + 2; 57 v -= as -> addr + 2;
76 lwasm_emit(as, l, (v >> 8) & 0xff); 58 lwasm_emit(as, l, (v >> 8) & 0xff);
77 lwasm_emit(as, l, v & 0xff); 59 lwasm_emit(as, l, v & 0xff);
78
79 lwasm_expr_stack_free(s);
80 } 60 }