-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexecuteBranch.go
More file actions
35 lines (29 loc) · 810 Bytes
/
executeBranch.go
File metadata and controls
35 lines (29 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package codegen
import (
"git.urbach.dev/cli/q/src/asm"
"git.urbach.dev/cli/q/src/ssa"
"git.urbach.dev/cli/q/src/token"
)
func (f *Function) executeBranch(step *Step, instr *ssa.Branch) {
var op token.Kind
binaryOp, isBinaryOp := instr.Condition.(*ssa.BinaryOp)
if isBinaryOp && binaryOp.Op.IsComparison() {
op = binaryOp.Op
} else {
op = token.NotEqual
f.Assembler.Append(&asm.CompareNumber{
Destination: f.ValueToStep[instr.Condition].Register,
Number: 0,
})
}
f.insertPhiMoves(step)
following := f.Steps[step.Index+1].Value.(*Label)
switch following.Name {
case instr.Then.Label:
f.jumpIfFalse(op, instr.Else.Label)
case instr.Else.Label:
f.jumpIfTrue(op, instr.Then.Label)
default:
panic("branch instruction must be followed by the 'then' or 'else' block")
}
}