@@ -200,7 +200,7 @@ cgDef (SFun name argNames _ expr) = do
200200 case r of
201201 Nothing -> terminate $ Unreachable []
202202 Just r' -> terminate $ Ret (Just r') [])
203− (CGR arch (Name . show $ name))
203+ (CGR arch (show name))
204204 (CGS 0 nextGlobal (Name "begin") [] (map (Just . LocalReference . Name . show) argNames) S.empty)
205205 entryTerm = case bbs of
206206 [] -> Do $ Ret Nothing []
@@ -235,10 +235,13 @@ data CGS = CGS { nextName :: Word
235235 }
236236
237237data CGR = CGR { target :: String
238− , funcName :: Name }
238+ , funcName :: String }
239239
240240type Codegen = RWS CGR CGW CGS
241241
242+getFuncName :: Codegen String
243+getFuncName = asks funcName
244+
242245getGlobalUnName :: Codegen Name
243246getGlobalUnName = do
244247 i <- gets nextGlobalName
@@ -532,7 +535,8 @@ cgChainCase caseValPtr defExp alts = do
532535 newBlock elseName
533536 return result
534537 modify $ \s -> s { lexenv = initEnv }
535− defaultVal <- cgExpr (fromMaybe (SError "Inexhaustive case failure") defExp)
538+ fname <- getFuncName
539+ defaultVal <- cgExpr (fromMaybe (SError $ "Inexhaustive case failure in " ++ fname) defExp)
536540 defaultBlock <- gets currentBlockName
537541 defaultEnv <- gets lexenv
538542 defResult <- case defaultVal of
@@ -560,7 +564,8 @@ finishCase initEnv exitBlockName results = do
560564cgDefaultAlt :: Name -> Name -> Maybe SExp -> Codegen (Maybe (Operand, Name, Env))
561565cgDefaultAlt exitName name exp = do
562566 newBlock name
563− val <- cgExpr (fromMaybe (SError "Inexhaustive case failure") exp)
567+ fname <- getFuncName
568+ val <- cgExpr (fromMaybe (SError $ "Inexhaustive case failure in " ++ fname) exp)
564569 env <- gets lexenv
565570 block <- gets currentBlockName
566571 case val of