ghc-9.0.2: The GHC API

GHC.Cmm.Switch

Synopsis

# Documentation

A value of type SwitchTargets contains the alternatives for a CmmSwitch value, and knows whether the value is signed, the possible range, an optional default value and a map from values to jump labels.

#### Instances

Instances details
 Source # Instance detailsDefined in GHC.Cmm.Switch Methods Source # Instance detailsDefined in GHC.Cmm.Switch Methods

The smart constructor mkSwitchTargets normalises the map a bit: * No entries outside the range * No entries equal to the default * No default if all elements have explicit values

Returns the list of non-default branches of the SwitchTargets value

Return the default label of the SwitchTargets value

Return the range of the SwitchTargets value

Return whether this is used for a signed value

Changes all labels mentioned in the SwitchTargets value

switchTargetsToTable creates a dense jump table, usable for code generation.

Also returns an offset to add to the value; the list is 0-based on the result of that addition.

The conversion from Integer to Int is a bit of a wart, as the actual scrutinee might be an unsigned word, but it just works, due to wrap-around arithmetic (as verified by the CmmSwitchTest test case).

Groups cases with equal targets, suitable for pretty-printing to a c-like switch statement with fall-through semantics.

The list of all labels occurring in the SwitchTargets value.

Custom equality helper, needed for GHC.Cmm.CommonBlockElim

A SwitchPlan abstractly describes how a Switch statement ought to be implemented. See Note [createSwitchPlan]

#### Instances

Instances details
 Source # Instance detailsDefined in GHC.Cmm.Switch MethodsshowList :: [SwitchPlan] -> ShowS Source #

Does the target support switch out of the box? Then leave this to the target!

This function creates a SwitchPlan from a SwitchTargets value, breaking it down into smaller pieces suitable for code generation.