br_table
Branch to one of a list of code blocks depending on a control index. This has nothing to with database tables or
the (table...)
keyword. This instruction pops an i32
value off the stack and uses it as
an index to select a code block to branch too. If the value is 0 then first code block is used, if the value in 1 then
the second one is used.
Syntax
br_table $label1 $labelN
Parameters
$label1
The name of the code block to branch to. You can also use the index of the code block.
There must be at least one label given.
$labelN Optional
There can be any number of code block labels. The first label has index 0, then each one after
is given an increasing index value, the second is index 1, the third has index 2, and so on.
Stack In
i32 |
The index of the code block to branch to. |
Example
block $block_0
block $block_1
block $block_2
local.get $blockIndex
br_table $block_0 $block_1 $block_2
end
end
end