genSwitch :: CmmExpr -> SwitchTargets -> LlvmM StmtData
genSwitch cond ids = do
    (vc, stmts, top) <- exprToVar cond
    let ty = getVarType vc

    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 | Just l <- switchTargetsDefault ids = blockIdToLlvm l
               | otherwise                          = snd (head labels)

    let s1 = Switch vc defLbl labels
    return $ (stmts `snocOL` s1, top)


-- -----------------------------------------------------------------------------
-- * CmmExpr code generation
--

-- | An expression conversion return data:
--   * LlvmVar: The var holding the result of the expression
--   * LlvmStatements: Any statements needed to evaluate the expression
--   * LlvmCmmDecl: Any global data needed for this expression
genSwitch :: CmmExpr -> SwitchTargets -> LlvmM StmtData
genSwitch cond ids = do
    (vc, stmts, top) <- exprToVar cond
    let ty = getVarType vc

    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 | Just l <- switchTargetsDefault ids = blockIdToLlvm l
               | otherwise                          = snd (head labels)

    let s1 = Switch vc defLbl labels
    return $ (stmts `snocOL` s1, top)


-- -----------------------------------------------------------------------------
-- * CmmExpr code generation
--

-- | An expression conversion return data:
--   * LlvmVar: The var holding the result of the expression
--   * LlvmStatements: Any statements needed to evaluate the expression
--   * LlvmCmmDecl: Any global data needed for this expression
genSwitch cond ids = do
    (vc, stmts, top) <- exprToVar cond
    let ty = getVarType vc

    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 | Just l <- switchTargetsDefault ids = blockIdToLlvm l
               | otherwise                          = snd (head labels)

    let s1 = Switch vc defLbl labels
    return $ (stmts `snocOL` s1, top)


-- -----------------------------------------------------------------------------
-- * CmmExpr code generation
--

-- | An expression conversion return data:
--   * LlvmVar: The var holding the result of the expression
--   * LlvmStatements: Any statements needed to evaluate the expression
--   * LlvmCmmDecl: Any global data needed for this expression