module DDC.Driver.Config
( Config (..)
, ConfigPretty (..)
, defaultConfigPretty
, prettyModeOfConfig
, objectPathOfConfig
, exePathOfConfig
, ViaBackend (..)
, RuntimeLinkStrategy (..))
where
import DDC.Build.Builder
import DDC.Core.Simplifier (Simplifier)
import DDC.Core.Pretty
import DDC.Core.Module
import System.FilePath
import Data.Maybe
import qualified DDC.Core.Salt.Runtime as Salt
import qualified DDC.Core.Salt as Salt
data Config
= Config
{
configLogBuild :: Bool
, configDump :: Bool
, configInferTypes :: Bool
, configSimplSalt :: Simplifier Int () Salt.Name
, configViaBackend :: ViaBackend
, configRuntime :: Salt.Config
, configRuntimeLinkStrategy :: RuntimeLinkStrategy
, configBuilder :: Builder
, configPretty :: ConfigPretty
, configSuppressHashImports :: Bool
, configModuleBaseDirectories :: [FilePath]
, configOutputFile :: Maybe FilePath
, configOutputDir :: Maybe FilePath
, configKeepLlvmFiles :: Bool
, configKeepSeaFiles :: Bool
, configKeepAsmFiles :: Bool
, configTaintAvoidTypeChecks :: Bool
}
data ConfigPretty
= ConfigPretty
{ configPrettyUseLetCase :: Bool
, configPrettyVarTypes :: Bool
, configPrettyConTypes :: Bool
, configPrettySuppressImports :: Bool
, configPrettySuppressExports :: Bool
, configPrettySuppressLetTypes :: Bool }
defaultConfigPretty :: ConfigPretty
defaultConfigPretty
= ConfigPretty
{ configPrettyUseLetCase = False
, configPrettyVarTypes = False
, configPrettyConTypes = False
, configPrettySuppressImports = False
, configPrettySuppressExports = False
, configPrettySuppressLetTypes = False }
prettyModeOfConfig
:: (Eq n, Pretty n)
=> ConfigPretty -> PrettyMode (Module a n)
prettyModeOfConfig config
= modeModule
where
modeModule
= PrettyModeModule
{ modeModuleLets = modeLets
, modeModuleSuppressImports = configPrettySuppressImports config
, modeModuleSuppressExports = configPrettySuppressExports config }
modeExp
= PrettyModeExp
{ modeExpLets = modeLets
, modeExpAlt = modeAlt
, modeExpConTypes = configPrettyConTypes config
, modeExpVarTypes = configPrettyVarTypes config
, modeExpUseLetCase = configPrettyUseLetCase config }
modeLets
= PrettyModeLets
{ modeLetsExp = modeExp
, modeLetsSuppressTypes = configPrettySuppressLetTypes config }
modeAlt
= PrettyModeAlt
{ modeAltExp = modeExp }
objectPathOfConfig :: Config -> FilePath -> FilePath
objectPathOfConfig config path
= let outputDir = fromMaybe (takeDirectory path) (configOutputDir config)
outputDirBase = dropExtension (replaceDirectory path outputDir)
in outputDirBase ++ ".o"
exePathOfConfig :: Config -> FilePath -> FilePath
exePathOfConfig config path
= let oPath = objectPathOfConfig config path
exePathDefault = dropExtension oPath
in fromMaybe exePathDefault (configOutputFile config)
data ViaBackend
= ViaC
| ViaLLVM
deriving Show
data RuntimeLinkStrategy
= LinkDefault
| LinkStatic
deriving (Show, Eq)