module DDC.Llvm.Pretty.Base
( Config(..)
, Version
, defaultConfig
, configOfVersion
, versionWantsMetadataAsValue
, versionWantsLoadReturnTypes)
where
import Data.List
import Data.Maybe
data Config
= Config
{ configLlvmVersion :: Version
, configWantsMetadataAsValue :: Bool
, configWantsLoadReturnTypes :: Bool }
deriving Show
type Version
= String
defaultConfig :: Config
defaultConfig = configOfVersion Nothing
configOfVersion :: Maybe Version -> Config
configOfVersion mVersion
= let version = fromMaybe "3.8.0" mVersion
in Config
{ configLlvmVersion = version
, configWantsMetadataAsValue
= fromMaybe False $ versionWantsMetadataAsValue version
, configWantsLoadReturnTypes
= fromMaybe True $ versionWantsLoadReturnTypes version }
versionWantsMetadataAsValue :: Version -> Maybe Bool
versionWantsMetadataAsValue v
| isPrefixOf "3.1." v = Just True
| isPrefixOf "3.2." v = Just True
| isPrefixOf "3.3." v = Just True
| isPrefixOf "3.4." v = Just True
| isPrefixOf "3.5." v = Just True
| isPrefixOf "3." v = Just False
| otherwise = Nothing
versionWantsLoadReturnTypes :: Version -> Maybe Bool
versionWantsLoadReturnTypes v
| isPrefixOf "3.1." v = Just False
| isPrefixOf "3.2." v = Just False
| isPrefixOf "3.3." v = Just False
| isPrefixOf "3.4." v = Just False
| isPrefixOf "3.5." v = Just False
| isPrefixOf "3.6." v = Just False
| isPrefixOf "3." v = Just True
| otherwise = Nothing