@@ -196,7 +196,7 @@ cgDef (SFun name argNames _ expr) = do
196196 (CGS 0 nextGlobal (Name "begin") [] (map (Just . LocalReference . Name . show) argNames) S.empty)
197197 entryTerm = case bbs of
198198 [] -> Do $ Ret Nothing []
199− (BasicBlock n _ _):_ -> Do $ Br n []
199+ BasicBlock n _ _:_ -> Do $ Br n []
200200 tell globals
201201 put nextGlobal'
202202 return . GlobalDefinition $ functionDefaults
@@ -208,10 +208,10 @@ cgDef (SFun name argNames _ expr) = do
208208 Parameter (PointerType valueType (AddrSpace 0)) (Name (show argName)) []
209209 , False)
210210 , G.basicBlocks =
211− [ BasicBlock (Name "entry")
212− (map (\(n, t) -> n := Alloca t Nothing 0 []) allocas)
213− entryTerm
214− ] ++ bbs
211+ BasicBlock (Name "entry")
212+ (map (\(n, t) -> n := Alloca t Nothing 0 []) allocas)
213+ entryTerm
214+ : bbs
215215 }
216216
217217type CGW = ([(Name, Type)], [BasicBlock], [Definition])
@@ -301,12 +301,10 @@ replaceElt 0 val (x:xs) = val:xs
301301replaceElt n val (x:xs) = x : replaceElt (n-1) val xs
302302
303303alloc' :: Operand -> Codegen Operand
304−alloc' size = do
305− inst $ simpleCall "GC_malloc" [size]
304+alloc' size = inst $ simpleCall "GC_malloc" [size]
306305
307306allocAtomic :: Operand -> Codegen Operand
308−allocAtomic size = do
309− inst $ simpleCall "GC_malloc_atomic" [size]
307+allocAtomic size = inst $ simpleCall "GC_malloc_atomic" [size]
310308
311309alloc :: Type -> Codegen Operand
312310alloc ty = do
@@ -335,15 +333,15 @@ cgExpr (SApp tailcall fname args) = do
335333 Nothing -> return Nothing
336334 Just argVals -> do
337335 fn <- var (Glob fname)
338− Just <$> (inst $
339− Call { isTailCall = tailcall
340− , callingConvention = CC.Fast
341− , returnAttributes = []
342− , function = Right . ConstantOperand . C.GlobalReference . Name $ show fname
343− , arguments = map (\v -> (v, [])) argVals
344− , functionAttributes = []
345− , metadata = []
346− })
336+ Just <$> inst
337+ Call { isTailCall = tailcall
338+ , callingConvention = CC.Fast
339+ , returnAttributes = []
340+ , function = Right . ConstantOperand . C.GlobalReference . Name $ show fname
341+ , arguments = map (\v -> (v, [])) argVals
342+ , functionAttributes = []
343+ , metadata = []
344+ }
347345cgExpr (SLet _ varExpr bodyExpr) = do
348346 val <- cgExpr varExpr
349347 binds [val] $ cgExpr bodyExpr
@@ -364,7 +362,7 @@ cgExpr (SCon tag name args) = do
364362 , ConstantOperand (C.Int 32 1)
365363 , ConstantOperand (C.Int 32 i)] []
366364 inst' $ Store False ptr arg Nothing 0 []
367− Just <$> (inst $ BitCast con (PointerType valueType (AddrSpace 0)) [])
365+ Just <$> inst (BitCast con (PointerType valueType (AddrSpace 0)) [])
368366cgExpr (SCase inspect alts) = do
369367 val <- var inspect
370368 case val of
@@ -397,7 +395,7 @@ cgExpr (SChkCase inspect alts) = do
397395 Just caseVal -> do
398396 terminate $ Br endBBN []
399397 newBlock endBBN
400− Just <$> (inst $ Phi (PointerType valueType (AddrSpace 0))
398+ Just <$> inst (Phi (PointerType valueType (AddrSpace 0))
401399 [(val, originBlock), (val, notNullBBN), (caseVal, caseExitBlock)] [])
402400cgExpr (SProj conVar idx) = do
403401 val <- var conVar
@@ -409,7 +407,7 @@ cgExpr (SProj conVar idx) = do
409407 , ConstantOperand (C.Int 32 1)
410408 , ConstantOperand (C.Int 32 (fromIntegral idx))
411409 ] []
412− Just <$> (inst $ Load False ptr Nothing 0 [])
410+ Just <$> inst (Load False ptr Nothing 0 [])
413411cgExpr (SConst c) = Just <$> cgConst c
414412cgExpr (SForeign LANG_C rty fname args) = do
415413 func <- ensureCDecl fname rty (map fst args)
@@ -422,14 +420,14 @@ cgExpr (SForeign LANG_C rty fname args) = do
422420 Nothing -> return Nothing
423421 Just argVals' -> do
424422 argUVals <- mapM (uncurry unbox) argVals'
425− result <- inst $ Call { isTailCall = False
426− , callingConvention = CC.C
427− , returnAttributes = []
428− , function = Right func
429− , arguments = map (\v -> (v, [])) argUVals
430− , functionAttributes = []
431− , metadata = []
432− }
423+ result <- inst Call { isTailCall = False
424+ , callingConvention = CC.C
425+ , returnAttributes = []
426+ , function = Right func
427+ , arguments = map (\v -> (v, [])) argUVals
428+ , functionAttributes = []
429+ , metadata = []
430+ }
433431 Just <$> box rty result
434432cgExpr (SOp fn args) = do
435433 argVals <- mapM var args
@@ -442,14 +440,14 @@ cgExpr (SError msg) = do -- TODO: Print message
442440 (cgConst' (TT.Str (msg ++ "\n")))
443441 inst' $ simpleCall "putStr" [ConstantOperand $ C.GetElementPtr True str [ C.Int 32 0
444442 , C.Int 32 0]]
445− inst' $ Call { isTailCall = True
446− , callingConvention = CC.C
447− , returnAttributes = []
448− , function = Right . ConstantOperand . C.GlobalReference . Name $ "llvm.trap"
449− , arguments = []
450− , functionAttributes = [A.NoReturn]
451− , metadata = []
452− }
443+ inst' Call { isTailCall = True
444+ , callingConvention = CC.C
445+ , returnAttributes = []
446+ , function = Right . ConstantOperand . C.GlobalReference . Name $ "llvm.trap"
447+ , arguments = []
448+ , functionAttributes = [A.NoReturn]
449+ , metadata = []
450+ }
453451 return Nothing
454452
455453cgCase :: Operand -> [SAlt] -> Codegen (Maybe Operand)
@@ -464,10 +462,10 @@ cgCase val alts =
464462 constAlts = filter isConstCase alts
465463 conAlts = filter isConCase alts
466464
467− isConstCase (SConstCase _ _) = True
465+ isConstCase (SConstCase {}) = True
468466 isConstCase _ = False
469467
470− isConCase (SConCase _ _ _ _ _) = True
468+ isConCase (SConCase {}) = True
471469 isConCase _ = False
472470
473471 isDefCase (SDefaultCase _) = True
@@ -510,7 +508,7 @@ cgConCase con defExp alts = do
510508 initEnv <- gets lexenv
511509 defResult <- cgDefaultAlt exitBlockName defBlockName defExp
512510 results <- forM namedAlts $ \(name, SConCase _ _ _ argns exp) ->
513− cgAlt initEnv exitBlockName name (Just (con, (map show argns))) exp
511+ cgAlt initEnv exitBlockName name (Just (con, map show argns)) exp
514512 finishCase initEnv exitBlockName (defResult:results)
515513
516514cgChainCase :: Operand -> Maybe SExp -> [SAlt] -> Codegen (Maybe Operand)
@@ -564,7 +562,7 @@ finishCase initEnv exitBlockName results = do
564562 xs -> do
565563 newBlock exitBlockName
566564 mergeEnvs $ map (\(_, altBlock, altEnv) -> (altBlock, altEnv)) xs
567− Just <$> (inst $ Phi (PointerType valueType (AddrSpace 0))
565+ Just <$> inst (Phi (PointerType valueType (AddrSpace 0))
568566 (map (\(altVal, altBlock, _) -> (altVal, altBlock)) xs) [])
569567
570568
@@ -594,7 +592,7 @@ cgAlt initEnv exitBlockName name destr exp = do
594592 do ptr <- inst $ GetElementPtr True con [ ConstantOperand (C.Int 32 0)
595593 , ConstantOperand (C.Int 32 1)
596594 , ConstantOperand (C.Int 32 i)] []
597− Just <$> (ninst argName $ Load False ptr Nothing 0 [])
595+ Just <$> ninst argName (Load False ptr Nothing 0 [])
598596 altVal <- binds locals $ cgExpr exp
599597 altEnv <- gets lexenv
600598 altBlock <- gets currentBlockName
@@ -619,7 +617,7 @@ mergeEnvs es = do
619617 | all (== v) (map fst vs) -> return v
620618 | otherwise ->
621619 let valid = map (\(a, b) -> (fromJust a, b)) . filter (isJust . fst) $ vs in
622− Just <$> (inst $ Phi (PointerType valueType (AddrSpace 0)) valid [])
620+ Just <$> inst (Phi (PointerType valueType (AddrSpace 0)) valid [])
623621 modify $ \s -> s { lexenv = env }
624622
625623nameAlt :: Name -> SAlt -> Codegen Name
@@ -764,7 +762,7 @@ cgOp (LIntStr ity) [x] = do
764762
765763cgOp LStrConcat [x,y] = cgStrCat x y
766764cgOp prim args = ierror $ "Unimplemented primitive: [" ++ show prim ++ "]("
767− ++ (intersperse ',' $ take (length args) ['a'..]) ++ ")"
765+ ++ intersperse ',' (take (length args) ['a'..]) ++ ")"
768766
769767cgStrCat :: Operand -> Operand -> Codegen Operand
770768cgStrCat x y = do