codegenLLVM :: [(TT.Name, SDecl)] ->
               String -> -- target triple
               String -> -- target CPU
               Word -> -- Optimization degree
               FilePath -> -- output file name
               OutputType ->
               IO ()
codegenLLVM defs triple cpu optimize file outty = withContext $ \context -> do
  initializeAllTargets
  (target, _) <- failInIO $ lookupTarget Nothing triple
  withTargetOptions $ \options ->
      withTargetMachine target triple cpu S.empty options R.Default CM.Default CGO.Default $ \tm ->
          do layout <- getTargetMachineDataLayout tm
             let ast = codegen (Target triple layout) (map snd defs)
             result <- runErrorT .  MO.withModuleFromAST context ast $ \m ->
                       do let opts = PM.defaultCuratedPassSetSpec
                                     { PM.optLevel = Just optimize
                                     , PM.simplifyLibCalls = Just True
                                     , PM.useInlinerWithThreshold = Just 225
                                     }
                          when (optimize /= 0) $ PM.withPassManager opts $ void . flip PM.runPassManager m
                          outputModule tm file outty m
             case result of
               Right _ -> return ()
               Left msg -> ierror msg
codegenLLVM :: [(TT.Name, SDecl)] ->
               String -> -- target triple
               String -> -- target CPU
               Word -> -- Optimization degree
               FilePath -> -- output file name
               OutputType ->
               IO ()
codegenLLVM defs triple cpu optimize file outty = withContext $ \context -> do
  initializeAllTargets
  (target, _) <- failInIO $ lookupTarget Nothing triple
  withTargetOptions $ \options ->
      withTargetMachine target triple cpu S.empty options R.Default CM.Default CGO.Default $ \tm ->
          do layout <- getTargetMachineDataLayout tm
             let ast = codegen (Target triple layout) (map snd defs)
             result <- runErrorT .  MO.withModuleFromAST context ast $ \m ->
                       do let opts = PM.defaultCuratedPassSetSpec
                                     { PM.optLevel = Just optimize
                                     , PM.simplifyLibCalls = Just True
                                     , PM.useInlinerWithThreshold = Just 225
                                     }
                          when (optimize /= 0) $ PM.withPassManager opts $ void . flip PM.runPassManager m
                          outputModule tm file outty m
             case result of
               Right _ -> return ()
               Left msg -> ierror msg
codegenLLVM defs triple cpu optimize file outty = withContext $ \context -> do
  initializeAllTargets
  (target, _) <- failInIO $ lookupTarget Nothing triple
  withTargetOptions $ \options ->
      withTargetMachine target triple cpu S.empty options R.Default CM.Default CGO.Default $ \tm ->
          do layout <- getTargetMachineDataLayout tm
             let ast = codegen (Target triple layout) (map snd defs)
             result <- runErrorT .  MO.withModuleFromAST context ast $ \m ->
                       do let opts = PM.defaultCuratedPassSetSpec
                                     { PM.optLevel = Just optimize
                                     , PM.simplifyLibCalls = Just True
                                     , PM.useInlinerWithThreshold = Just 225
                                     }
                          when (optimize /= 0) $ PM.withPassManager opts $ void . flip PM.runPassManager m
                          outputModule tm file outty m
             case result of
               Right _ -> return ()
               Left msg -> ierror msg