pub struct Switch {
pub scrutinee: LocalValueId,
pub cases: Vec<SwitchArm>,
pub default: Option<LocalBlockId>,
pub default_args: Vec<LocalValueId>,
}Expand description
Multi-way dispatch on an integer scrutinee: the resolved form of a jump table.
BranchInd is the unresolved indirect branch — its successors are
whatever edges an analysis managed to materialize, with no record of which
scrutinee value picks which. handle_jump_tables rewrites it to a Switch
once it recognizes the table and bounds the index, the same way a two-target
resolution already becomes a real CBranch. Keeping the mapping in the
terminator is what lets the decompiler emit a switch rather than a list of
gotos, and — unlike a bare indirect edge — gives each successor an argument
list, so block parameters can cross a dispatch.
default is optional. A table guarded by a preceding bounds check is total
over the values it lists, and inventing an unreachable default block for it
would only give DCE something to remove.
Fields§
§scrutinee: LocalValueIdThe value dispatched on (the table index, after any bias).
cases: Vec<SwitchArm>Arms in table order. Case values are pairwise distinct.
default: Option<LocalBlockId>Where an unlisted scrutinee value goes, when that is representable.
default_args: Vec<LocalValueId>Arguments passed to default’s parameters.