MCPcopy Create free account
hub / github.com/akyoto/q / executeBranch

Method executeBranch

src/codegen/executeBranch.go:12–55  ·  view source on GitHub ↗
(step *Step, instr *ssa.Branch)

Source from the content-addressed store, hash-verified

10)
11
12func (f *Function) executeBranch(step *Step, instr *ssa.Branch) {
13 var (
14 op token.Kind
15 unsigned bool
16 conditionStep = f.ValueToStep[instr.Condition]
17 )
18
19 if conditionStep.Register != -1 {
20 op = token.NotEqual
21 operand := f.resolveOperand(conditionStep, step.Live)
22
23 f.Assembler.Append(&asm.CompareNumber{
24 Destination: operand,
25 Number: 0,
26 })
27 } else {
28 switch condition := instr.Condition.(type) {
29 case *ssa.BinaryOp:
30 if condition.Op.IsComparison() {
31 op = condition.Op
32 unsigned = types.IsUnsigned(condition.Left.Type()) || types.IsUnsigned(condition.Right.Type())
33 } else {
34 panic("condition using a binary operation not assigned to a register")
35 }
36 case *ssa.Cas:
37 op = token.Equal
38 operand := f.ValueToStep[condition.Arguments[1]].Register
39
40 if f.build.Arch == config.X86 {
41 operand = x86.R0
42 }
43
44 f.Assembler.Append(&asm.CompareNumber{
45 Destination: operand,
46 Number: condition.Arguments[1].(*ssa.Int).Int,
47 })
48 }
49 }
50
51 f.insertPhiMoves(step)
52 following := f.Steps[step.Index+1].Value.(*Label)
53 condition := tokenToCondition(op, unsigned)
54
55 switch following.Name {
56 case instr.Then.Label:
57 f.jumpIfFalse(condition, instr.Else.Label)
58 case instr.Else.Label:

Callers 1

executeMethod · 0.95

Calls 8

insertPhiMovesMethod · 0.95
jumpIfFalseMethod · 0.95
jumpIfTrueMethod · 0.95
IsUnsignedFunction · 0.92
tokenToConditionFunction · 0.85
IsComparisonMethod · 0.80
TypeMethod · 0.65
AppendMethod · 0.45

Tested by

no test coverage detected