diff options
Diffstat (limited to 'compiler/llvmGen/LlvmCodeGen/CodeGen.hs')
-rw-r--r-- | compiler/llvmGen/LlvmCodeGen/CodeGen.hs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/compiler/llvmGen/LlvmCodeGen/CodeGen.hs b/compiler/llvmGen/LlvmCodeGen/CodeGen.hs index c7be2c3194..4f864b6904 100644 --- a/compiler/llvmGen/LlvmCodeGen/CodeGen.hs +++ b/compiler/llvmGen/LlvmCodeGen/CodeGen.hs @@ -18,6 +18,7 @@ import Cmm import CPrim import PprCmm import CmmUtils +import CmmSwitch import Hoopl import DynFlags @@ -824,18 +825,16 @@ For a real example of this, see ./rts/StgStdThunks.cmm -- | Switch branch --- --- N.B. We remove Nothing's from the list of branches, as they are 'undefined'. --- However, they may be defined one day, so we better document this behaviour. -genSwitch :: CmmExpr -> [Maybe BlockId] -> LlvmM StmtData -genSwitch cond maybe_ids = do +genSwitch :: CmmExpr -> SwitchTargets -> LlvmM StmtData +genSwitch cond ids = do (vc, stmts, top) <- exprToVar cond let ty = getVarType vc - let pairs = [ (ix, id) | (ix,Just id) <- zip [0..] maybe_ids ] - let labels = map (\(ix, b) -> (mkIntLit ty ix, blockIdToLlvm b)) pairs + let labels = [ (mkIntLit ty ix, blockIdToLlvm b) + | (ix, b) <- switchTargetsCases ids ] -- out of range is undefined, so let's just branch to first label - let (_, defLbl) = head labels + let defLbl | Just l <- switchTargetsDefault ids = blockIdToLlvm l + | otherwise = snd (head labels) let s1 = Switch vc defLbl labels return $ (stmts `snocOL` s1, top) |