module GHC.Platform.Ways
( Way(..)
, Ways
, hasWay
, addWay
, allowed_combination
, wayGeneralFlags
, wayUnsetGeneralFlags
, wayOptc
, wayOptl
, wayOptP
, wayDesc
, wayRTSOnly
, wayTag
, waysTag
, waysBuildTag
, fullWays
, rtsWays
, hostWays
, hostFullWays
, hostIsProfiled
, hostIsDynamic
, hostIsThreaded
, hostIsDebugged
, hostIsTracing
)
where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Platform
import GHC.Driver.Flags
import qualified Data.Set as Set
import Data.Set (Set)
import Data.List (intersperse)
data Way
= WayCustom String
| WayThreaded
| WayDebug
| WayProf
| WayTracing
| WayDyn
deriving (Eq, Ord, Show)
type Ways = Set Way
hasWay :: Ways -> Way -> Bool
hasWay ws w = Set.member w ws
addWay :: Way -> Ways -> Ways
addWay = Set.insert
allowed_combination :: Ways -> Bool
allowed_combination ways = not disallowed
where
disallowed = or [ hasWay ways x && hasWay ways y
| (x,y) <- couples
]
couples = []
waysTag :: Ways -> String
waysTag = concat . intersperse "_" . map wayTag . Set.toAscList
waysBuildTag :: Ways -> String
waysBuildTag ws = waysTag (Set.filter (not . wayRTSOnly) ws)
wayTag :: Way -> String
wayTag (WayCustom xs) = xs
wayTag WayThreaded = "thr"
wayTag WayDebug = "debug"
wayTag WayDyn = "dyn"
wayTag WayProf = "p"
wayTag WayTracing = "l"
wayRTSOnly :: Way -> Bool
wayRTSOnly (WayCustom {}) = False
wayRTSOnly WayDyn = False
wayRTSOnly WayProf = False
wayRTSOnly WayThreaded = True
wayRTSOnly WayDebug = True
wayRTSOnly WayTracing = True
fullWays :: Ways -> Ways
fullWays ws = Set.filter (not . wayRTSOnly) ws
rtsWays :: Ways -> Ways
rtsWays ws = Set.filter wayRTSOnly ws
wayDesc :: Way -> String
wayDesc (WayCustom xs) = xs
wayDesc WayThreaded = "Threaded"
wayDesc WayDebug = "Debug"
wayDesc WayDyn = "Dynamic"
wayDesc WayProf = "Profiling"
wayDesc WayTracing = "Tracing"
wayGeneralFlags :: Platform -> Way -> [GeneralFlag]
wayGeneralFlags _ (WayCustom {}) = []
wayGeneralFlags _ WayThreaded = []
wayGeneralFlags _ WayDebug = []
wayGeneralFlags _ WayDyn = [Opt_PIC, Opt_ExternalDynamicRefs]
wayGeneralFlags _ WayProf = []
wayGeneralFlags _ WayTracing = []
wayUnsetGeneralFlags :: Platform -> Way -> [GeneralFlag]
wayUnsetGeneralFlags _ (WayCustom {}) = []
wayUnsetGeneralFlags _ WayThreaded = []
wayUnsetGeneralFlags _ WayDebug = []
wayUnsetGeneralFlags _ WayDyn = [Opt_SplitSections]
wayUnsetGeneralFlags _ WayProf = []
wayUnsetGeneralFlags _ WayTracing = []
wayOptc :: Platform -> Way -> [String]
wayOptc _ (WayCustom {}) = []
wayOptc platform WayThreaded = case platformOS platform of
OSOpenBSD -> ["-pthread"]
OSNetBSD -> ["-pthread"]
_ -> []
wayOptc _ WayDebug = []
wayOptc _ WayDyn = []
wayOptc _ WayProf = ["-DPROFILING"]
wayOptc _ WayTracing = ["-DTRACING"]
wayOptl :: Platform -> Way -> [String]
wayOptl _ (WayCustom {}) = []
wayOptl platform WayThreaded =
case platformOS platform of
OSFreeBSD -> ["-pthread", "-Wno-unused-command-line-argument"]
OSOpenBSD -> ["-pthread"]
OSNetBSD -> ["-pthread"]
_ -> []
wayOptl _ WayDebug = []
wayOptl _ WayDyn = []
wayOptl _ WayProf = []
wayOptl _ WayTracing = []
wayOptP :: Platform -> Way -> [String]
wayOptP _ (WayCustom {}) = []
wayOptP _ WayThreaded = []
wayOptP _ WayDebug = []
wayOptP _ WayDyn = []
wayOptP _ WayProf = ["-DPROFILING"]
wayOptP _ WayTracing = ["-DTRACING"]
hostIsProfiled :: Bool
hostIsProfiled = rtsIsProfiled_ /= 0
foreign import ccall unsafe "rts_isProfiled" rtsIsProfiled_ :: Int
hostIsDynamic :: Bool
hostIsDynamic = rtsIsDynamic_ /= 0
foreign import ccall unsafe "rts_isDynamic" rtsIsDynamic_ :: Int
#if MIN_VERSION_GLASGOW_HASKELL(9,1,0,0)
hostIsThreaded :: Bool
hostIsThreaded = rtsIsThreaded_ /= 0
foreign import ccall unsafe "rts_isThreaded" rtsIsThreaded_ :: Int
hostIsDebugged :: Bool
hostIsDebugged = rtsIsDebugged_ /= 0
foreign import ccall unsafe "rts_isDebugged" rtsIsDebugged_ :: Int
hostIsTracing :: Bool
hostIsTracing = rtsIsTracing_ /= 0
foreign import ccall unsafe "rts_isTracing" rtsIsTracing_ :: Int
#else
hostIsThreaded :: Bool
hostIsThreaded = False
hostIsDebugged :: Bool
hostIsDebugged = False
hostIsTracing :: Bool
hostIsTracing = False
#endif
hostWays :: Ways
hostWays = Set.unions
[ if hostIsDynamic then Set.singleton WayDyn else Set.empty
, if hostIsProfiled then Set.singleton WayProf else Set.empty
, if hostIsThreaded then Set.singleton WayThreaded else Set.empty
, if hostIsDebugged then Set.singleton WayDebug else Set.empty
, if hostIsTracing then Set.singleton WayTracing else Set.empty
]
hostFullWays :: Ways
hostFullWays = fullWays hostWays