Fold constants (fix #504)
This commit is contained in:
1 parent
ae27178352
commit
2e2538ccb8
4 files changed
+120
-1
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user