aboutsummaryrefslogtreecommitdiff
path: root/compiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler.c b/compiler.c
index ea9f768..c6adf6a 100644
--- a/compiler.c
+++ b/compiler.c
@@ -148,7 +148,12 @@ static struct ref compile_expr(struct ir *ir, struct symtab *symtab, struct node
case OP_NOT: {
struct ref r0 = ref_next_register();
struct ref r1 = compile_expr(ir, symtab, node->child1);
- ir_append(ir, irins_make_01(INS_NOT, r0, r1));
+ const char *afterlbl = gen_label_name();
+ ir_append(ir, irins_make_12(INS_TEST, r1, r1));
+ ir_append(ir, irins_make_01(INS_MOV, r0, ref_imm(0)));
+ ir_append(ir, irins_make_jcc(afterlbl, CCNZ));
+ ir_append(ir, irins_make_01(INS_MOV, r0, ref_imm(1)));
+ ir_append(ir, irins_make_name(INS_LBL, afterlbl));
return r0;
}