(step *Step, instr *ssa.Branch)
| 10 | ) |
| 11 | |
| 12 | func (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: |
no test coverage detected