diff options
author | Nicolas Williams <nico@cryptonector.com> | 2014-07-27 17:33:22 -0500 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2014-07-27 17:48:49 -0500 |
commit | 2e2538ccb85a39bfe6364d2e7a863e04d6ece9c5 (patch) | |
tree | 6c86cfbd14e8b28b374c5e2fbfc3f8d1c36ae1dc /compile.c | |
parent | ae27178352e1bd78bbfed31bc8593e8b01ebd397 (diff) |
Fold constants (fix #504)
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -97,7 +97,7 @@ static block inst_block(inst* i) { return b; } -static int block_is_single(block b) { +int block_is_single(block b) { return b.first && b.first == b.last; } @@ -131,6 +131,10 @@ block gen_noop() { return b; } +int block_is_noop(block b) { + return (b.first == 0 && b.last == 0); +} + block gen_op_simple(opcode op) { assert(opcode_describe(op)->length == 1); return inst_block(inst_new(op)); @@ -144,6 +148,20 @@ block gen_const(jv constant) { return inst_block(i); } +int block_is_const(block b) { + return (block_is_single(b) && b.first->op == LOADK); +} + +jv_kind block_const_kind(block b) { + assert(block_is_const(b)); + return jv_get_kind(b.first->imm.constant); +} + +jv block_const(block b) { + assert(block_is_const(b)); + return jv_copy(b.first->imm.constant); +} + block gen_op_target(opcode op, block target) { assert(opcode_describe(op)->flags & OP_HAS_BRANCH); assert(target.last); |