module DDC.Build.Pipeline.Llvm
( PipeLlvm(..)
, pipeLlvm)
where
import DDC.Build.Pipeline.Error
import DDC.Build.Pipeline.Sink
import DDC.Build.Builder
import DDC.Llvm.Pretty ()
import DDC.Base.Pretty
import Control.Monad
import qualified DDC.Llvm.Syntax as Llvm
import System.Directory
data PipeLlvm
= PipeLlvmPrint Sink
| PipeLlvmCompile
{ pipeBuilder :: Builder
, pipeFileLlvm :: FilePath
, pipeFileAsm :: FilePath
, pipeFileObject :: FilePath
, pipeFileExe :: Maybe FilePath
, pipeKeepLlvmFiles :: Bool
, pipeKeepAsmFiles :: Bool }
deriving (Show)
pipeLlvm
:: Llvm.Module
-> PipeLlvm
-> IO [Error]
pipeLlvm !mm !pp
= case pp of
PipeLlvmPrint !sink
->
pipeSink (renderIndent $ ppr mm) sink
PipeLlvmCompile
!builder !llPath !sPath !oPath !mExePath
!keepLlvmFiles !keepAsmFiles
->
do
let llSrc = renderIndent $ ppr mm
writeFile llPath llSrc
buildLlc builder llPath sPath
buildAs builder sPath oPath
(case mExePath of
Nothing
-> return ()
Just exePath
-> do buildLdExe builder oPath exePath
return ())
when (not keepLlvmFiles)
$ removeFile llPath
when (not keepAsmFiles)
$ removeFile sPath
return []