module GHC.Driver.Ways
( Way(..)
, hasWay
, allowed_combination
, wayGeneralFlags
, wayUnsetGeneralFlags
, wayOptc
, wayOptl
, wayOptP
, wayDesc
, wayRTSOnly
, wayTag
, waysTag
, waysBuildTag
, hostFullWays
, hostIsProfiled
, hostIsDynamic
)
where
import GHC.Prelude
import GHC.Platform
import GHC.Driver.Flags
import qualified Data.Set as Set
import Data.Set (Set)
import Data.List (intersperse)
import System.IO.Unsafe ( unsafeDupablePerformIO )
data Way
= WayCustom String
| WayThreaded
| WayDebug
| WayProf
| WayEventLog
| WayDyn
deriving (Way -> Way -> Bool
(Way -> Way -> Bool) -> (Way -> Way -> Bool) -> Eq Way
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Way -> Way -> Bool
$c/= :: Way -> Way -> Bool
== :: Way -> Way -> Bool
$c== :: Way -> Way -> Bool
Eq, Eq Way
Eq Way
-> (Way -> Way -> Ordering)
-> (Way -> Way -> Bool)
-> (Way -> Way -> Bool)
-> (Way -> Way -> Bool)
-> (Way -> Way -> Bool)
-> (Way -> Way -> Way)
-> (Way -> Way -> Way)
-> Ord Way
Way -> Way -> Bool
Way -> Way -> Ordering
Way -> Way -> Way
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Way -> Way -> Way
$cmin :: Way -> Way -> Way
max :: Way -> Way -> Way
$cmax :: Way -> Way -> Way
>= :: Way -> Way -> Bool
$c>= :: Way -> Way -> Bool
> :: Way -> Way -> Bool
$c> :: Way -> Way -> Bool
<= :: Way -> Way -> Bool
$c<= :: Way -> Way -> Bool
< :: Way -> Way -> Bool
$c< :: Way -> Way -> Bool
compare :: Way -> Way -> Ordering
$ccompare :: Way -> Way -> Ordering
Ord, Int -> Way -> ShowS
[Way] -> ShowS
Way -> String
(Int -> Way -> ShowS)
-> (Way -> String) -> ([Way] -> ShowS) -> Show Way
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Way] -> ShowS
$cshowList :: [Way] -> ShowS
show :: Way -> String
$cshow :: Way -> String
showsPrec :: Int -> Way -> ShowS
$cshowsPrec :: Int -> Way -> ShowS
Show)
hasWay :: Set Way -> Way -> Bool
hasWay :: Set Way -> Way -> Bool
hasWay Set Way
ws Way
w = Way -> Set Way -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member Way
w Set Way
ws
allowed_combination :: Set Way -> Bool
allowed_combination :: Set Way -> Bool
allowed_combination Set Way
ways = Bool -> Bool
not Bool
disallowed
where
disallowed :: Bool
disallowed = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [ Set Way -> Way -> Bool
hasWay Set Way
ways Way
x Bool -> Bool -> Bool
&& Set Way -> Way -> Bool
hasWay Set Way
ways Way
y
| (Way
x,Way
y) <- [(Way, Way)]
forall {a}. [a]
couples
]
couples :: [a]
couples = []
waysTag :: Set Way -> String
waysTag :: Set Way -> String
waysTag = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String) -> (Set Way -> [String]) -> Set Way -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
"_" ([String] -> [String])
-> (Set Way -> [String]) -> Set Way -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Way -> String) -> [Way] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Way -> String
wayTag ([Way] -> [String]) -> (Set Way -> [Way]) -> Set Way -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set Way -> [Way]
forall a. Set a -> [a]
Set.toAscList
waysBuildTag :: Set Way -> String
waysBuildTag :: Set Way -> String
waysBuildTag Set Way
ws = Set Way -> String
waysTag ((Way -> Bool) -> Set Way -> Set Way
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (Bool -> Bool
not (Bool -> Bool) -> (Way -> Bool) -> Way -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Way -> Bool
wayRTSOnly) Set Way
ws)
wayTag :: Way -> String
wayTag :: Way -> String
wayTag (WayCustom String
xs) = String
xs
wayTag Way
WayThreaded = String
"thr"
wayTag Way
WayDebug = String
"debug"
wayTag Way
WayDyn = String
"dyn"
wayTag Way
WayProf = String
"p"
wayTag Way
WayEventLog = String
"l"
wayRTSOnly :: Way -> Bool
wayRTSOnly :: Way -> Bool
wayRTSOnly (WayCustom {}) = Bool
False
wayRTSOnly Way
WayDyn = Bool
False
wayRTSOnly Way
WayProf = Bool
False
wayRTSOnly Way
WayThreaded = Bool
True
wayRTSOnly Way
WayDebug = Bool
True
wayRTSOnly Way
WayEventLog = Bool
True
wayDesc :: Way -> String
wayDesc :: Way -> String
wayDesc (WayCustom String
xs) = String
xs
wayDesc Way
WayThreaded = String
"Threaded"
wayDesc Way
WayDebug = String
"Debug"
wayDesc Way
WayDyn = String
"Dynamic"
wayDesc Way
WayProf = String
"Profiling"
wayDesc Way
WayEventLog = String
"RTS Event Logging"
wayGeneralFlags :: Platform -> Way -> [GeneralFlag]
wayGeneralFlags :: Platform -> Way -> [GeneralFlag]
wayGeneralFlags Platform
_ (WayCustom {}) = []
wayGeneralFlags Platform
_ Way
WayThreaded = []
wayGeneralFlags Platform
_ Way
WayDebug = []
wayGeneralFlags Platform
_ Way
WayDyn = [GeneralFlag
Opt_PIC, GeneralFlag
Opt_ExternalDynamicRefs]
wayGeneralFlags Platform
_ Way
WayProf = []
wayGeneralFlags Platform
_ Way
WayEventLog = []
wayUnsetGeneralFlags :: Platform -> Way -> [GeneralFlag]
wayUnsetGeneralFlags :: Platform -> Way -> [GeneralFlag]
wayUnsetGeneralFlags Platform
_ (WayCustom {}) = []
wayUnsetGeneralFlags Platform
_ Way
WayThreaded = []
wayUnsetGeneralFlags Platform
_ Way
WayDebug = []
wayUnsetGeneralFlags Platform
_ Way
WayDyn = [GeneralFlag
Opt_SplitSections]
wayUnsetGeneralFlags Platform
_ Way
WayProf = []
wayUnsetGeneralFlags Platform
_ Way
WayEventLog = []
wayOptc :: Platform -> Way -> [String]
wayOptc :: Platform -> Way -> [String]
wayOptc Platform
_ (WayCustom {}) = []
wayOptc Platform
platform Way
WayThreaded = case Platform -> OS
platformOS Platform
platform of
OS
OSOpenBSD -> [String
"-pthread"]
OS
OSNetBSD -> [String
"-pthread"]
OS
_ -> []
wayOptc Platform
_ Way
WayDebug = []
wayOptc Platform
_ Way
WayDyn = []
wayOptc Platform
_ Way
WayProf = [String
"-DPROFILING"]
wayOptc Platform
_ Way
WayEventLog = [String
"-DTRACING"]
wayOptl :: Platform -> Way -> [String]
wayOptl :: Platform -> Way -> [String]
wayOptl Platform
_ (WayCustom {}) = []
wayOptl Platform
platform Way
WayThreaded =
case Platform -> OS
platformOS Platform
platform of
OS
OSFreeBSD -> [String
"-pthread", String
"-Wno-unused-command-line-argument"]
OS
OSOpenBSD -> [String
"-pthread"]
OS
OSNetBSD -> [String
"-pthread"]
OS
_ -> []
wayOptl Platform
_ Way
WayDebug = []
wayOptl Platform
_ Way
WayDyn = []
wayOptl Platform
_ Way
WayProf = []
wayOptl Platform
_ Way
WayEventLog = []
wayOptP :: Platform -> Way -> [String]
wayOptP :: Platform -> Way -> [String]
wayOptP Platform
_ (WayCustom {}) = []
wayOptP Platform
_ Way
WayThreaded = []
wayOptP Platform
_ Way
WayDebug = []
wayOptP Platform
_ Way
WayDyn = []
wayOptP Platform
_ Way
WayProf = [String
"-DPROFILING"]
wayOptP Platform
_ Way
WayEventLog = [String
"-DTRACING"]
hostIsProfiled :: Bool
hostIsProfiled :: Bool
hostIsProfiled = IO Int -> Int
forall a. IO a -> a
unsafeDupablePerformIO IO Int
rtsIsProfiledIO Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0
foreign import ccall unsafe "rts_isProfiled" rtsIsProfiledIO :: IO Int
hostIsDynamic :: Bool
hostIsDynamic :: Bool
hostIsDynamic = IO Int -> Int
forall a. IO a -> a
unsafeDupablePerformIO IO Int
rtsIsDynamicIO Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0
foreign import ccall unsafe "rts_isDynamic" rtsIsDynamicIO :: IO Int
hostFullWays :: Set Way
hostFullWays :: Set Way
hostFullWays = [Set Way] -> Set Way
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
[ if Bool
hostIsDynamic then Way -> Set Way
forall a. a -> Set a
Set.singleton Way
WayDyn else Set Way
forall a. Set a
Set.empty
, if Bool
hostIsProfiled then Way -> Set Way
forall a. a -> Set a
Set.singleton Way
WayProf else Set Way
forall a. Set a
Set.empty
]