Skip to content

Commit

Permalink
Fix if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Yey007 committed May 16, 2024
1 parent 96c6da7 commit 931c477
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docs/html/*
build_dir/
bin/*
!bin/.gitkeep
demo/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
![CI Status](https://github.com/ethanuppal/cs3110_compiler/actions/workflows/ci.yaml/badge.svg)

> "x86 is simple trust me bro"
> Last updated: 2024-05-15 18:33:04.077638
> Last updated: 2024-05-15 22:27:21.599048
```
$ ./main -h
Expand Down
4 changes: 2 additions & 2 deletions lib/backend/asm_emit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ let emit_bb text cfg regalloc bb =
match op with
| Variable var ->
Asm.Section.add text (Cmp (emit_var regalloc var, Intermediate 0));
Asm.Section.add text (Je (Label (Basic_block.label_for false_bb)));
Asm.Section.add text (Jmp (Label (Basic_block.label_for true_bb)))
Asm.Section.add text (Je (Label (Basic_block.label_for true_bb)));
Asm.Section.add text (Jmp (Label (Basic_block.label_for false_bb)))
| Constant _ -> failwith "failure")

let emit_preamble ~text =
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/if.x86istmb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
func main() {
let x = 0
let y = 2
let z = x
let w = z + y

if (w == 2) {
print 2
}
if (w == 1) {
print 1
}
if (w == 0) {
print 0
}
}

0 comments on commit 931c477

Please sign in to comment.