aboutsummaryrefslogtreecommitdiffhomepage
path: root/interp/compiler.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-04-05 22:29:53 +0200
committerRon Evans <[email protected]>2021-04-08 11:40:59 +0200
commit04d12bf2ba85358534d67a4cbe3402a1f25b7437 (patch)
tree3d1d80eaee75aac4686bde332bf8e379fe1a9cf4 /interp/compiler.go
parent0b7957d61249ce4b745f78405e36f07245eb8da3 (diff)
downloadtinygo-04d12bf2ba85358534d67a4cbe3402a1f25b7437.tar.gz
tinygo-04d12bf2ba85358534d67a4cbe3402a1f25b7437.zip
interp: add support for switch statement
A switch statement is not normally emitted by the compiler package, but LLVM function passes may convert a series of if/else pairs to a switch statement. A future change will run function passes in the package compile phase, so the interp package (which is also run after all modules are merged together) will need to deal with these new switch statements.
Diffstat (limited to 'interp/compiler.go')
-rw-r--r--interp/compiler.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/interp/compiler.go b/interp/compiler.go
index e45df8c13..e9bf36c3e 100644
--- a/interp/compiler.go
+++ b/interp/compiler.go
@@ -135,6 +135,15 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function {
default:
panic("unknown number of operands")
}
+ case llvm.Switch:
+ // A switch is an array of (value, label) pairs, of which the
+ // first one indicates the to-switch value and the default
+ // label.
+ numOperands := llvmInst.OperandsCount()
+ for i := 0; i < numOperands; i += 2 {
+ inst.operands = append(inst.operands, r.getValue(llvmInst.Operand(i)))
+ inst.operands = append(inst.operands, literalValue{uint32(blockIndices[llvmInst.Operand(i+1)])})
+ }
case llvm.PHI:
inst.name = llvmInst.Name()
incomingCount := inst.llvmInst.IncomingCount()