{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module GHC.Llvm.MetaData
( MetaId(..)
, ppMetaId
, MetaExpr(..)
, MetaAnnot(..)
, MetaDecl(..)
, ModuleFlagBehavior(..)
, ModuleFlag(..)
, moduleFlagToMetaExpr
) where
import GHC.Prelude
import GHC.Llvm.Types
import GHC.Utils.Outputable
newtype MetaId = MetaId Int
deriving (MetaId -> MetaId -> Bool
(MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool) -> Eq MetaId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetaId -> MetaId -> Bool
== :: MetaId -> MetaId -> Bool
$c/= :: MetaId -> MetaId -> Bool
/= :: MetaId -> MetaId -> Bool
Eq, Eq MetaId
Eq MetaId =>
(MetaId -> MetaId -> Ordering)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> MetaId)
-> (MetaId -> MetaId -> MetaId)
-> Ord MetaId
MetaId -> MetaId -> Bool
MetaId -> MetaId -> Ordering
MetaId -> MetaId -> MetaId
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
$ccompare :: MetaId -> MetaId -> Ordering
compare :: MetaId -> MetaId -> Ordering
$c< :: MetaId -> MetaId -> Bool
< :: MetaId -> MetaId -> Bool
$c<= :: MetaId -> MetaId -> Bool
<= :: MetaId -> MetaId -> Bool
$c> :: MetaId -> MetaId -> Bool
> :: MetaId -> MetaId -> Bool
$c>= :: MetaId -> MetaId -> Bool
>= :: MetaId -> MetaId -> Bool
$cmax :: MetaId -> MetaId -> MetaId
max :: MetaId -> MetaId -> MetaId
$cmin :: MetaId -> MetaId -> MetaId
min :: MetaId -> MetaId -> MetaId
Ord, Int -> MetaId
MetaId -> Int
MetaId -> [MetaId]
MetaId -> MetaId
MetaId -> MetaId -> [MetaId]
MetaId -> MetaId -> MetaId -> [MetaId]
(MetaId -> MetaId)
-> (MetaId -> MetaId)
-> (Int -> MetaId)
-> (MetaId -> Int)
-> (MetaId -> [MetaId])
-> (MetaId -> MetaId -> [MetaId])
-> (MetaId -> MetaId -> [MetaId])
-> (MetaId -> MetaId -> MetaId -> [MetaId])
-> Enum MetaId
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: MetaId -> MetaId
succ :: MetaId -> MetaId
$cpred :: MetaId -> MetaId
pred :: MetaId -> MetaId
$ctoEnum :: Int -> MetaId
toEnum :: Int -> MetaId
$cfromEnum :: MetaId -> Int
fromEnum :: MetaId -> Int
$cenumFrom :: MetaId -> [MetaId]
enumFrom :: MetaId -> [MetaId]
$cenumFromThen :: MetaId -> MetaId -> [MetaId]
enumFromThen :: MetaId -> MetaId -> [MetaId]
$cenumFromTo :: MetaId -> MetaId -> [MetaId]
enumFromTo :: MetaId -> MetaId -> [MetaId]
$cenumFromThenTo :: MetaId -> MetaId -> MetaId -> [MetaId]
enumFromThenTo :: MetaId -> MetaId -> MetaId -> [MetaId]
Enum)
instance Outputable MetaId where
ppr :: MetaId -> SDoc
ppr = MetaId -> SDoc
forall doc. IsLine doc => MetaId -> doc
ppMetaId
ppMetaId :: IsLine doc => MetaId -> doc
ppMetaId :: forall doc. IsLine doc => MetaId -> doc
ppMetaId (MetaId Int
n) = Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'!' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> doc
forall doc. IsLine doc => Int -> doc
int Int
n
{-# SPECIALIZE ppMetaId :: MetaId -> SDoc #-}
{-# SPECIALIZE ppMetaId :: MetaId -> HLine #-}
data MetaExpr = MetaStr !LMString
| MetaLit !LlvmLit
| MetaNode !MetaId
| MetaVar !LlvmVar
| MetaStruct [MetaExpr]
deriving (MetaExpr -> MetaExpr -> Bool
(MetaExpr -> MetaExpr -> Bool)
-> (MetaExpr -> MetaExpr -> Bool) -> Eq MetaExpr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetaExpr -> MetaExpr -> Bool
== :: MetaExpr -> MetaExpr -> Bool
$c/= :: MetaExpr -> MetaExpr -> Bool
/= :: MetaExpr -> MetaExpr -> Bool
Eq)
data MetaAnnot = MetaAnnot LMString MetaExpr
deriving (MetaAnnot -> MetaAnnot -> Bool
(MetaAnnot -> MetaAnnot -> Bool)
-> (MetaAnnot -> MetaAnnot -> Bool) -> Eq MetaAnnot
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetaAnnot -> MetaAnnot -> Bool
== :: MetaAnnot -> MetaAnnot -> Bool
$c/= :: MetaAnnot -> MetaAnnot -> Bool
/= :: MetaAnnot -> MetaAnnot -> Bool
Eq)
data MetaDecl
= MetaNamed !LMString [MetaId]
| MetaUnnamed !MetaId !MetaExpr
data ModuleFlagBehavior
= MFBError
| MFBWarning
| MFBRequire
| MFBOverride
| MFBAppend
| MFBAppendUnique
| MFBMax
| MFBMin
moduleFlagBehaviorToMetaExpr :: ModuleFlagBehavior -> MetaExpr
moduleFlagBehaviorToMetaExpr :: ModuleFlagBehavior -> MetaExpr
moduleFlagBehaviorToMetaExpr ModuleFlagBehavior
mfb =
LlvmLit -> MetaExpr
MetaLit (LlvmLit -> MetaExpr) -> LlvmLit -> MetaExpr
forall a b. (a -> b) -> a -> b
$ Integer -> LlvmType -> LlvmLit
LMIntLit Integer
n LlvmType
i32
where
n :: Integer
n = case ModuleFlagBehavior
mfb of
ModuleFlagBehavior
MFBError -> Integer
1
ModuleFlagBehavior
MFBWarning -> Integer
2
ModuleFlagBehavior
MFBRequire -> Integer
3
ModuleFlagBehavior
MFBOverride -> Integer
4
ModuleFlagBehavior
MFBAppend -> Integer
5
ModuleFlagBehavior
MFBAppendUnique -> Integer
6
ModuleFlagBehavior
MFBMax -> Integer
7
ModuleFlagBehavior
MFBMin -> Integer
8
data ModuleFlag = ModuleFlag { ModuleFlag -> ModuleFlagBehavior
mfBehavior :: ModuleFlagBehavior
, ModuleFlag -> LMString
mfName :: LMString
, ModuleFlag -> MetaExpr
mfValue :: MetaExpr
}
moduleFlagToMetaExpr :: ModuleFlag -> MetaExpr
moduleFlagToMetaExpr :: ModuleFlag -> MetaExpr
moduleFlagToMetaExpr ModuleFlag
flag = [MetaExpr] -> MetaExpr
MetaStruct
[ ModuleFlagBehavior -> MetaExpr
moduleFlagBehaviorToMetaExpr (ModuleFlag -> ModuleFlagBehavior
mfBehavior ModuleFlag
flag)
, LMString -> MetaExpr
MetaStr (ModuleFlag -> LMString
mfName ModuleFlag
flag)
, ModuleFlag -> MetaExpr
mfValue ModuleFlag
flag
]