{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
#if defined(darwin_HOST_OS)
{-# OPTIONS_GHC -fno-asm-shortcutting #-}
#endif
module GHC.Llvm.Types where
import GHC.Prelude
import Data.Char
import Numeric
import GHC.Platform
import GHC.Data.FastString
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Types.Unique
import GHC.CmmToAsm.Ppr
import GHC.Float
data LMGlobal = LMGlobal {
LMGlobal -> LlvmVar
getGlobalVar :: LlvmVar,
LMGlobal -> Maybe LlvmStatic
getGlobalValue :: Maybe LlvmStatic
}
type LMString = FastString
type LlvmAlias = (LMString, LlvmType)
data LlvmType
= LMInt Int
| LMFloat
| LMDouble
| LMFloat80
| LMFloat128
| LMPointer LlvmType
| LMArray Int LlvmType
| LMVector Int LlvmType
| LMLabel
| LMVoid
| LMStruct [LlvmType]
| LMStructU [LlvmType]
| LMAlias LlvmAlias
| LMMetadata
| LMFunction LlvmFunctionDecl
deriving (LlvmType -> LlvmType -> Bool
(LlvmType -> LlvmType -> Bool)
-> (LlvmType -> LlvmType -> Bool) -> Eq LlvmType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmType -> LlvmType -> Bool
== :: LlvmType -> LlvmType -> Bool
$c/= :: LlvmType -> LlvmType -> Bool
/= :: LlvmType -> LlvmType -> Bool
Eq)
instance Outputable LlvmType where
ppr :: LlvmType -> SDoc
ppr = LlvmType -> SDoc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType
ppLlvmType :: IsLine doc => LlvmType -> doc
ppLlvmType :: forall doc. IsLine doc => LlvmType -> doc
ppLlvmType LlvmType
t = case LlvmType
t of
LMInt Int
size -> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'i' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> doc
forall doc. IsLine doc => Int -> doc
int Int
size
LlvmType
LMFloat -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"float"
LlvmType
LMDouble -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"double"
LlvmType
LMFloat80 -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"x86_fp80"
LlvmType
LMFloat128 -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"fp128"
LMPointer LlvmType
x -> LlvmType -> doc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType LlvmType
x doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'*'
LMArray Int
nr LlvmType
tp -> 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
nr doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> doc
forall doc. IsLine doc => String -> doc
text String
" x " doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> LlvmType -> doc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType LlvmType
tp doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
']'
LMVector Int
nr LlvmType
tp -> 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
nr doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> doc
forall doc. IsLine doc => String -> doc
text String
" x " doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> LlvmType -> doc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType LlvmType
tp doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'>'
LlvmType
LMLabel -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"label"
LlvmType
LMVoid -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"void"
LMStruct [LlvmType]
tys -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"<{" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> (LlvmType -> doc) -> [LlvmType] -> doc
forall doc a. IsLine doc => (a -> doc) -> [a] -> doc
ppCommaJoin LlvmType -> doc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType [LlvmType]
tys doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> doc
forall doc. IsLine doc => String -> doc
text String
"}>"
LMStructU [LlvmType]
tys -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"{" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> (LlvmType -> doc) -> [LlvmType] -> doc
forall doc a. IsLine doc => (a -> doc) -> [a] -> doc
ppCommaJoin LlvmType -> doc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType [LlvmType]
tys doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> doc
forall doc. IsLine doc => String -> doc
text String
"}"
LlvmType
LMMetadata -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"metadata"
LMAlias (FastString
s,LlvmType
_) -> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'%' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> FastString -> doc
forall doc. IsLine doc => FastString -> doc
ftext FastString
s
LMFunction (LlvmFunctionDecl FastString
_ LlvmLinkageType
_ LlvmCallConvention
_ LlvmType
r LlvmParameterListType
varg [LlvmParameter]
p LMAlign
_)
-> LlvmType -> doc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType LlvmType
r doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> doc
forall doc. IsLine doc => doc
lparen doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> LlvmParameterListType -> [LlvmParameter] -> doc
forall doc.
IsLine doc =>
LlvmParameterListType -> [LlvmParameter] -> doc
ppParams LlvmParameterListType
varg [LlvmParameter]
p doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
rparen
{-# SPECIALIZE ppLlvmType :: LlvmType -> SDoc #-}
{-# SPECIALIZE ppLlvmType :: LlvmType -> HLine #-}
ppParams :: IsLine doc => LlvmParameterListType -> [LlvmParameter] -> doc
ppParams :: forall doc.
IsLine doc =>
LlvmParameterListType -> [LlvmParameter] -> doc
ppParams LlvmParameterListType
varg [LlvmParameter]
p
= let varg' :: doc
varg' = case LlvmParameterListType
varg of
LlvmParameterListType
VarArgs | [LlvmType] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LlvmType]
args -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"..."
| Bool
otherwise -> String -> doc
forall doc. IsLine doc => String -> doc
text String
", ..."
LlvmParameterListType
_otherwise -> String -> doc
forall doc. IsLine doc => String -> doc
text String
""
args :: [LlvmType]
args = (LlvmParameter -> LlvmType) -> [LlvmParameter] -> [LlvmType]
forall a b. (a -> b) -> [a] -> [b]
map LlvmParameter -> LlvmType
forall a b. (a, b) -> a
fst [LlvmParameter]
p
in (LlvmType -> doc) -> [LlvmType] -> doc
forall doc a. IsLine doc => (a -> doc) -> [a] -> doc
ppCommaJoin LlvmType -> doc
forall doc. IsLine doc => LlvmType -> doc
ppLlvmType [LlvmType]
args doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
varg'
{-# SPECIALIZE ppParams :: LlvmParameterListType -> [LlvmParameter] -> SDoc #-}
{-# SPECIALIZE ppParams :: LlvmParameterListType -> [LlvmParameter] -> HLine #-}
type LMSection = Maybe LMString
type LMAlign = Maybe Int
data LMConst = Global
| Constant
| Alias
deriving (LMConst -> LMConst -> Bool
(LMConst -> LMConst -> Bool)
-> (LMConst -> LMConst -> Bool) -> Eq LMConst
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LMConst -> LMConst -> Bool
== :: LMConst -> LMConst -> Bool
$c/= :: LMConst -> LMConst -> Bool
/= :: LMConst -> LMConst -> Bool
Eq)
data LlvmVar
= LMGlobalVar LMString LlvmType LlvmLinkageType LMSection LMAlign LMConst
| LMLocalVar Unique LlvmType
| LMNLocalVar LMString LlvmType
| LMLitVar LlvmLit
deriving (LlvmVar -> LlvmVar -> Bool
(LlvmVar -> LlvmVar -> Bool)
-> (LlvmVar -> LlvmVar -> Bool) -> Eq LlvmVar
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmVar -> LlvmVar -> Bool
== :: LlvmVar -> LlvmVar -> Bool
$c/= :: LlvmVar -> LlvmVar -> Bool
/= :: LlvmVar -> LlvmVar -> Bool
Eq)
data LlvmLit
= LMIntLit Integer LlvmType
| LMFloatLit Double LlvmType
| LMNullLit LlvmType
| LMVectorLit [LlvmLit]
| LMUndefLit LlvmType
deriving (LlvmLit -> LlvmLit -> Bool
(LlvmLit -> LlvmLit -> Bool)
-> (LlvmLit -> LlvmLit -> Bool) -> Eq LlvmLit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmLit -> LlvmLit -> Bool
== :: LlvmLit -> LlvmLit -> Bool
$c/= :: LlvmLit -> LlvmLit -> Bool
/= :: LlvmLit -> LlvmLit -> Bool
Eq)
data LlvmStatic
= LMString
| LMStaticLit LlvmLit
| LMUninitType LlvmType
| LMStaticStr LMString LlvmType
| LMStaticArray [LlvmStatic] LlvmType
| LMStaticStruc [LlvmStatic] LlvmType
| LMStaticStrucU [LlvmStatic] LlvmType
| LMStaticPointer LlvmVar
| LMTrunc LlvmStatic LlvmType
| LMBitc LlvmStatic LlvmType
| LMPtoI LlvmStatic LlvmType
| LMAdd LlvmStatic LlvmStatic
| LMSub LlvmStatic LlvmStatic
garbageLit :: LlvmType -> Maybe LlvmLit
garbageLit :: LlvmType -> Maybe LlvmLit
garbageLit t :: LlvmType
t@(LMInt Int
w) = LlvmLit -> Maybe LlvmLit
forall a. a -> Maybe a
Just (Integer -> LlvmType -> LlvmLit
LMIntLit (Integer
0xbbbbbbbbbbbbbbb0 Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` (Integer
2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Int
w)) LlvmType
t)
garbageLit LlvmType
t
| LlvmType -> Bool
isFloat LlvmType
t = LlvmLit -> Maybe LlvmLit
forall a. a -> Maybe a
Just (Double -> LlvmType -> LlvmLit
LMFloatLit Double
12345678.9 LlvmType
t)
garbageLit t :: LlvmType
t@(LMPointer LlvmType
_) = LlvmLit -> Maybe LlvmLit
forall a. a -> Maybe a
Just (LlvmType -> LlvmLit
LMNullLit LlvmType
t)
garbageLit LlvmType
_ = Maybe LlvmLit
forall a. Maybe a
Nothing
getVarType :: LlvmVar -> LlvmType
getVarType :: LlvmVar -> LlvmType
getVarType (LMGlobalVar FastString
_ LlvmType
y LlvmLinkageType
_ LMSection
_ LMAlign
_ LMConst
_) = LlvmType
y
getVarType (LMLocalVar Unique
_ LlvmType
y ) = LlvmType
y
getVarType (LMNLocalVar FastString
_ LlvmType
y ) = LlvmType
y
getVarType (LMLitVar LlvmLit
l ) = LlvmLit -> LlvmType
getLitType LlvmLit
l
getLitType :: LlvmLit -> LlvmType
getLitType :: LlvmLit -> LlvmType
getLitType (LMIntLit Integer
_ LlvmType
t) = LlvmType
t
getLitType (LMFloatLit Double
_ LlvmType
t) = LlvmType
t
getLitType (LMVectorLit []) = String -> LlvmType
forall a. HasCallStack => String -> a
panic String
"getLitType"
getLitType (LMVectorLit ls :: [LlvmLit]
ls@(LlvmLit
l:[LlvmLit]
_)) = Int -> LlvmType -> LlvmType
LMVector ([LlvmLit] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LlvmLit]
ls) (LlvmLit -> LlvmType
getLitType LlvmLit
l)
getLitType (LMNullLit LlvmType
t) = LlvmType
t
getLitType (LMUndefLit LlvmType
t) = LlvmType
t
getStatType :: LlvmStatic -> LlvmType
getStatType :: LlvmStatic -> LlvmType
getStatType (LMStaticLit LlvmLit
l ) = LlvmLit -> LlvmType
getLitType LlvmLit
l
getStatType (LMUninitType LlvmType
t) = LlvmType
t
getStatType (LMStaticStr FastString
_ LlvmType
t) = LlvmType
t
getStatType (LMStaticArray [LlvmStatic]
_ LlvmType
t) = LlvmType
t
getStatType (LMStaticStruc [LlvmStatic]
_ LlvmType
t) = LlvmType
t
getStatType (LMStaticStrucU [LlvmStatic]
_ LlvmType
t) = LlvmType
t
getStatType (LMStaticPointer LlvmVar
v) = LlvmVar -> LlvmType
getVarType LlvmVar
v
getStatType (LMTrunc LlvmStatic
_ LlvmType
t) = LlvmType
t
getStatType (LMBitc LlvmStatic
_ LlvmType
t) = LlvmType
t
getStatType (LMPtoI LlvmStatic
_ LlvmType
t) = LlvmType
t
getStatType (LMAdd LlvmStatic
t LlvmStatic
_) = LlvmStatic -> LlvmType
getStatType LlvmStatic
t
getStatType (LMSub LlvmStatic
t LlvmStatic
_) = LlvmStatic -> LlvmType
getStatType LlvmStatic
t
getStatType (LMComment FastString
_) = String -> LlvmType
forall a. HasCallStack => String -> a
error String
"Can't call getStatType on LMComment!"
getLink :: LlvmVar -> LlvmLinkageType
getLink :: LlvmVar -> LlvmLinkageType
getLink (LMGlobalVar FastString
_ LlvmType
_ LlvmLinkageType
l LMSection
_ LMAlign
_ LMConst
_) = LlvmLinkageType
l
getLink LlvmVar
_ = LlvmLinkageType
Internal
pLift :: LlvmType -> LlvmType
pLift :: LlvmType -> LlvmType
pLift LlvmType
LMLabel = String -> LlvmType
forall a. HasCallStack => String -> a
error String
"Labels are unliftable"
pLift LlvmType
LMVoid = String -> LlvmType
forall a. HasCallStack => String -> a
error String
"Voids are unliftable"
pLift LlvmType
LMMetadata = String -> LlvmType
forall a. HasCallStack => String -> a
error String
"Metadatas are unliftable"
pLift LlvmType
x = LlvmType -> LlvmType
LMPointer LlvmType
x
pVarLift :: LlvmVar -> LlvmVar
pVarLift :: LlvmVar -> LlvmVar
pVarLift (LMGlobalVar FastString
s LlvmType
t LlvmLinkageType
l LMSection
x LMAlign
a LMConst
c) = FastString
-> LlvmType
-> LlvmLinkageType
-> LMSection
-> LMAlign
-> LMConst
-> LlvmVar
LMGlobalVar FastString
s (LlvmType -> LlvmType
pLift LlvmType
t) LlvmLinkageType
l LMSection
x LMAlign
a LMConst
c
pVarLift (LMLocalVar Unique
s LlvmType
t ) = Unique -> LlvmType -> LlvmVar
LMLocalVar Unique
s (LlvmType -> LlvmType
pLift LlvmType
t)
pVarLift (LMNLocalVar FastString
s LlvmType
t ) = FastString -> LlvmType -> LlvmVar
LMNLocalVar FastString
s (LlvmType -> LlvmType
pLift LlvmType
t)
pVarLift (LMLitVar LlvmLit
_ ) = String -> LlvmVar
forall a. HasCallStack => String -> a
error (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"Can't lower a literal type!"
pLower :: LlvmType -> LlvmType
pLower :: LlvmType -> LlvmType
pLower (LMPointer LlvmType
x) = LlvmType
x
pLower LlvmType
x = String -> SDoc -> LlvmType
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"llvmGen(pLower)"
(SDoc -> LlvmType) -> SDoc -> LlvmType
forall a b. (a -> b) -> a -> b
$ LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
x SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" is a unlowerable type, need a pointer"
pVarLower :: LlvmVar -> LlvmVar
pVarLower :: LlvmVar -> LlvmVar
pVarLower (LMGlobalVar FastString
s LlvmType
t LlvmLinkageType
l LMSection
x LMAlign
a LMConst
c) = FastString
-> LlvmType
-> LlvmLinkageType
-> LMSection
-> LMAlign
-> LMConst
-> LlvmVar
LMGlobalVar FastString
s (LlvmType -> LlvmType
pLower LlvmType
t) LlvmLinkageType
l LMSection
x LMAlign
a LMConst
c
pVarLower (LMLocalVar Unique
s LlvmType
t ) = Unique -> LlvmType -> LlvmVar
LMLocalVar Unique
s (LlvmType -> LlvmType
pLower LlvmType
t)
pVarLower (LMNLocalVar FastString
s LlvmType
t ) = FastString -> LlvmType -> LlvmVar
LMNLocalVar FastString
s (LlvmType -> LlvmType
pLower LlvmType
t)
pVarLower (LMLitVar LlvmLit
_ ) = String -> LlvmVar
forall a. HasCallStack => String -> a
error (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ String
"Can't lower a literal type!"
isInt :: LlvmType -> Bool
isInt :: LlvmType -> Bool
isInt (LMInt Int
_) = Bool
True
isInt LlvmType
_ = Bool
False
isFloat :: LlvmType -> Bool
isFloat :: LlvmType -> Bool
isFloat LlvmType
LMFloat = Bool
True
isFloat LlvmType
LMDouble = Bool
True
isFloat LlvmType
LMFloat80 = Bool
True
isFloat LlvmType
LMFloat128 = Bool
True
isFloat LlvmType
_ = Bool
False
isPointer :: LlvmType -> Bool
isPointer :: LlvmType -> Bool
isPointer (LMPointer LlvmType
_) = Bool
True
isPointer LlvmType
_ = Bool
False
isVector :: LlvmType -> Bool
isVector :: LlvmType -> Bool
isVector (LMVector {}) = Bool
True
isVector LlvmType
_ = Bool
False
isGlobal :: LlvmVar -> Bool
isGlobal :: LlvmVar -> Bool
isGlobal (LMGlobalVar FastString
_ LlvmType
_ LlvmLinkageType
_ LMSection
_ LMAlign
_ LMConst
_) = Bool
True
isGlobal LlvmVar
_ = Bool
False
llvmWidthInBits :: Platform -> LlvmType -> Int
llvmWidthInBits :: Platform -> LlvmType -> Int
llvmWidthInBits Platform
platform = \case
(LMInt Int
n) -> Int
n
(LlvmType
LMFloat) -> Int
32
(LlvmType
LMDouble) -> Int
64
(LlvmType
LMFloat80) -> Int
80
(LlvmType
LMFloat128) -> Int
128
(LMPointer LlvmType
_) -> Platform -> LlvmType -> Int
llvmWidthInBits Platform
platform (Platform -> LlvmType
llvmWord Platform
platform)
(LMArray Int
n LlvmType
t) -> Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* Platform -> LlvmType -> Int
llvmWidthInBits Platform
platform LlvmType
t
(LMVector Int
n LlvmType
ty) -> Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* Platform -> LlvmType -> Int
llvmWidthInBits Platform
platform LlvmType
ty
LlvmType
LMLabel -> Int
0
LlvmType
LMVoid -> Int
0
(LMStruct [LlvmType]
tys) -> [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ (LlvmType -> Int) -> [LlvmType] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Platform -> LlvmType -> Int
llvmWidthInBits Platform
platform) [LlvmType]
tys
(LMStructU [LlvmType]
_) ->
String -> Int
forall a. HasCallStack => String -> a
panic String
"llvmWidthInBits: not implemented for LMStructU"
(LMFunction LlvmFunctionDecl
_) -> Int
0
(LMAlias (FastString
_,LlvmType
t)) -> Platform -> LlvmType -> Int
llvmWidthInBits Platform
platform LlvmType
t
LlvmType
LMMetadata -> String -> Int
forall a. HasCallStack => String -> a
panic String
"llvmWidthInBits: Meta-data has no runtime representation!"
i128, i64, i32, i16, i8, i1, i8Ptr :: LlvmType
i128 :: LlvmType
i128 = Int -> LlvmType
LMInt Int
128
i64 :: LlvmType
i64 = Int -> LlvmType
LMInt Int
64
i32 :: LlvmType
i32 = Int -> LlvmType
LMInt Int
32
i16 :: LlvmType
i16 = Int -> LlvmType
LMInt Int
16
i8 :: LlvmType
i8 = Int -> LlvmType
LMInt Int
8
i1 :: LlvmType
i1 = Int -> LlvmType
LMInt Int
1
i8Ptr :: LlvmType
i8Ptr = LlvmType -> LlvmType
pLift LlvmType
i8
llvmWord, llvmWordPtr :: Platform -> LlvmType
llvmWord :: Platform -> LlvmType
llvmWord Platform
platform = Int -> LlvmType
LMInt (Platform -> Int
platformWordSizeInBytes Platform
platform Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8)
llvmWordPtr :: Platform -> LlvmType
llvmWordPtr Platform
platform = LlvmType -> LlvmType
pLift (Platform -> LlvmType
llvmWord Platform
platform)
data LlvmFunctionDecl = LlvmFunctionDecl {
LlvmFunctionDecl -> FastString
decName :: LMString,
LlvmFunctionDecl -> LlvmLinkageType
funcLinkage :: LlvmLinkageType,
LlvmFunctionDecl -> LlvmCallConvention
funcCc :: LlvmCallConvention,
LlvmFunctionDecl -> LlvmType
decReturnType :: LlvmType,
LlvmFunctionDecl -> LlvmParameterListType
decVarargs :: LlvmParameterListType,
LlvmFunctionDecl -> [LlvmParameter]
decParams :: [LlvmParameter],
LlvmFunctionDecl -> LMAlign
funcAlign :: LMAlign
}
deriving (LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
(LlvmFunctionDecl -> LlvmFunctionDecl -> Bool)
-> (LlvmFunctionDecl -> LlvmFunctionDecl -> Bool)
-> Eq LlvmFunctionDecl
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
== :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
$c/= :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
/= :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
Eq)
type LlvmFunctionDecls = [LlvmFunctionDecl]
type LlvmParameter = (LlvmType, [LlvmParamAttr])
data LlvmParamAttr
= ZeroExt
| SignExt
| InReg
| ByVal
| SRet
| NoAlias
| NoCapture
| Nest
deriving (LlvmParamAttr -> LlvmParamAttr -> Bool
(LlvmParamAttr -> LlvmParamAttr -> Bool)
-> (LlvmParamAttr -> LlvmParamAttr -> Bool) -> Eq LlvmParamAttr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmParamAttr -> LlvmParamAttr -> Bool
== :: LlvmParamAttr -> LlvmParamAttr -> Bool
$c/= :: LlvmParamAttr -> LlvmParamAttr -> Bool
/= :: LlvmParamAttr -> LlvmParamAttr -> Bool
Eq)
instance Outputable LlvmParamAttr where
ppr :: LlvmParamAttr -> SDoc
ppr = LlvmParamAttr -> SDoc
forall doc. IsLine doc => LlvmParamAttr -> doc
ppLlvmParamAttr
ppLlvmParamAttr :: IsLine doc => LlvmParamAttr -> doc
ppLlvmParamAttr :: forall doc. IsLine doc => LlvmParamAttr -> doc
ppLlvmParamAttr LlvmParamAttr
ZeroExt = String -> doc
forall doc. IsLine doc => String -> doc
text String
"zeroext"
ppLlvmParamAttr LlvmParamAttr
SignExt = String -> doc
forall doc. IsLine doc => String -> doc
text String
"signext"
ppLlvmParamAttr LlvmParamAttr
InReg = String -> doc
forall doc. IsLine doc => String -> doc
text String
"inreg"
ppLlvmParamAttr LlvmParamAttr
ByVal = String -> doc
forall doc. IsLine doc => String -> doc
text String
"byval"
ppLlvmParamAttr LlvmParamAttr
SRet = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sret"
ppLlvmParamAttr LlvmParamAttr
NoAlias = String -> doc
forall doc. IsLine doc => String -> doc
text String
"noalias"
ppLlvmParamAttr LlvmParamAttr
NoCapture = String -> doc
forall doc. IsLine doc => String -> doc
text String
"nocapture"
ppLlvmParamAttr LlvmParamAttr
Nest = String -> doc
forall doc. IsLine doc => String -> doc
text String
"nest"
{-# SPECIALIZE ppLlvmParamAttr :: LlvmParamAttr -> SDoc #-}
{-# SPECIALIZE ppLlvmParamAttr :: LlvmParamAttr -> HLine #-}
data LlvmFuncAttr
= AlwaysInline
| InlineHint
| NoInline
| OptSize
| NoReturn
| NoUnwind
| ReadNone
| ReadOnly
| Ssp
| SspReq
| NoRedZone
| NoImplicitFloat
| Naked
deriving (LlvmFuncAttr -> LlvmFuncAttr -> Bool
(LlvmFuncAttr -> LlvmFuncAttr -> Bool)
-> (LlvmFuncAttr -> LlvmFuncAttr -> Bool) -> Eq LlvmFuncAttr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
== :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
$c/= :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
/= :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
Eq)
instance Outputable LlvmFuncAttr where
ppr :: LlvmFuncAttr -> SDoc
ppr = LlvmFuncAttr -> SDoc
forall doc. IsLine doc => LlvmFuncAttr -> doc
ppLlvmFuncAttr
ppLlvmFuncAttr :: IsLine doc => LlvmFuncAttr -> doc
ppLlvmFuncAttr :: forall doc. IsLine doc => LlvmFuncAttr -> doc
ppLlvmFuncAttr LlvmFuncAttr
AlwaysInline = String -> doc
forall doc. IsLine doc => String -> doc
text String
"alwaysinline"
ppLlvmFuncAttr LlvmFuncAttr
InlineHint = String -> doc
forall doc. IsLine doc => String -> doc
text String
"inlinehint"
ppLlvmFuncAttr LlvmFuncAttr
NoInline = String -> doc
forall doc. IsLine doc => String -> doc
text String
"noinline"
ppLlvmFuncAttr LlvmFuncAttr
OptSize = String -> doc
forall doc. IsLine doc => String -> doc
text String
"optsize"
ppLlvmFuncAttr LlvmFuncAttr
NoReturn = String -> doc
forall doc. IsLine doc => String -> doc
text String
"noreturn"
ppLlvmFuncAttr LlvmFuncAttr
NoUnwind = String -> doc
forall doc. IsLine doc => String -> doc
text String
"nounwind"
ppLlvmFuncAttr LlvmFuncAttr
ReadNone = String -> doc
forall doc. IsLine doc => String -> doc
text String
"readnone"
ppLlvmFuncAttr LlvmFuncAttr
ReadOnly = String -> doc
forall doc. IsLine doc => String -> doc
text String
"readonly"
ppLlvmFuncAttr LlvmFuncAttr
Ssp = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ssp"
ppLlvmFuncAttr LlvmFuncAttr
SspReq = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ssqreq"
ppLlvmFuncAttr LlvmFuncAttr
NoRedZone = String -> doc
forall doc. IsLine doc => String -> doc
text String
"noredzone"
ppLlvmFuncAttr LlvmFuncAttr
NoImplicitFloat = String -> doc
forall doc. IsLine doc => String -> doc
text String
"noimplicitfloat"
ppLlvmFuncAttr LlvmFuncAttr
Naked = String -> doc
forall doc. IsLine doc => String -> doc
text String
"naked"
{-# SPECIALIZE ppLlvmFuncAttr :: LlvmFuncAttr -> SDoc #-}
{-# SPECIALIZE ppLlvmFuncAttr :: LlvmFuncAttr -> HLine #-}
data LlvmCallType
= StdCall
| TailCall
deriving (LlvmCallType -> LlvmCallType -> Bool
(LlvmCallType -> LlvmCallType -> Bool)
-> (LlvmCallType -> LlvmCallType -> Bool) -> Eq LlvmCallType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmCallType -> LlvmCallType -> Bool
== :: LlvmCallType -> LlvmCallType -> Bool
$c/= :: LlvmCallType -> LlvmCallType -> Bool
/= :: LlvmCallType -> LlvmCallType -> Bool
Eq,Int -> LlvmCallType -> ShowS
[LlvmCallType] -> ShowS
LlvmCallType -> String
(Int -> LlvmCallType -> ShowS)
-> (LlvmCallType -> String)
-> ([LlvmCallType] -> ShowS)
-> Show LlvmCallType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LlvmCallType -> ShowS
showsPrec :: Int -> LlvmCallType -> ShowS
$cshow :: LlvmCallType -> String
show :: LlvmCallType -> String
$cshowList :: [LlvmCallType] -> ShowS
showList :: [LlvmCallType] -> ShowS
Show)
data LlvmCallConvention
= CC_Ccc
| CC_Fastcc
| CC_Coldcc
| CC_Ghc
| CC_Ncc Int
| CC_X86_Stdcc
deriving (LlvmCallConvention -> LlvmCallConvention -> Bool
(LlvmCallConvention -> LlvmCallConvention -> Bool)
-> (LlvmCallConvention -> LlvmCallConvention -> Bool)
-> Eq LlvmCallConvention
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmCallConvention -> LlvmCallConvention -> Bool
== :: LlvmCallConvention -> LlvmCallConvention -> Bool
$c/= :: LlvmCallConvention -> LlvmCallConvention -> Bool
/= :: LlvmCallConvention -> LlvmCallConvention -> Bool
Eq)
instance Outputable LlvmCallConvention where
ppr :: LlvmCallConvention -> SDoc
ppr = LlvmCallConvention -> SDoc
forall doc. IsLine doc => LlvmCallConvention -> doc
ppLlvmCallConvention
ppLlvmCallConvention :: IsLine doc => LlvmCallConvention -> doc
ppLlvmCallConvention :: forall doc. IsLine doc => LlvmCallConvention -> doc
ppLlvmCallConvention LlvmCallConvention
CC_Ccc = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ccc"
ppLlvmCallConvention LlvmCallConvention
CC_Fastcc = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fastcc"
ppLlvmCallConvention LlvmCallConvention
CC_Coldcc = String -> doc
forall doc. IsLine doc => String -> doc
text String
"coldcc"
ppLlvmCallConvention LlvmCallConvention
CC_Ghc = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ghccc"
ppLlvmCallConvention (CC_Ncc Int
i) = String -> doc
forall doc. IsLine doc => String -> doc
text String
"cc " doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> doc
forall doc. IsLine doc => Int -> doc
int Int
i
ppLlvmCallConvention LlvmCallConvention
CC_X86_Stdcc = String -> doc
forall doc. IsLine doc => String -> doc
text String
"x86_stdcallcc"
{-# SPECIALIZE ppLlvmCallConvention :: LlvmCallConvention -> SDoc #-}
{-# SPECIALIZE ppLlvmCallConvention :: LlvmCallConvention -> HLine #-}
data LlvmParameterListType
= FixedArgs
| VarArgs
deriving (LlvmParameterListType -> LlvmParameterListType -> Bool
(LlvmParameterListType -> LlvmParameterListType -> Bool)
-> (LlvmParameterListType -> LlvmParameterListType -> Bool)
-> Eq LlvmParameterListType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmParameterListType -> LlvmParameterListType -> Bool
== :: LlvmParameterListType -> LlvmParameterListType -> Bool
$c/= :: LlvmParameterListType -> LlvmParameterListType -> Bool
/= :: LlvmParameterListType -> LlvmParameterListType -> Bool
Eq,Int -> LlvmParameterListType -> ShowS
[LlvmParameterListType] -> ShowS
LlvmParameterListType -> String
(Int -> LlvmParameterListType -> ShowS)
-> (LlvmParameterListType -> String)
-> ([LlvmParameterListType] -> ShowS)
-> Show LlvmParameterListType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LlvmParameterListType -> ShowS
showsPrec :: Int -> LlvmParameterListType -> ShowS
$cshow :: LlvmParameterListType -> String
show :: LlvmParameterListType -> String
$cshowList :: [LlvmParameterListType] -> ShowS
showList :: [LlvmParameterListType] -> ShowS
Show)
data LlvmLinkageType
= Internal
| LinkOnce
| Weak
| Appending
| ExternWeak
| ExternallyVisible
| External
| Private
deriving (LlvmLinkageType -> LlvmLinkageType -> Bool
(LlvmLinkageType -> LlvmLinkageType -> Bool)
-> (LlvmLinkageType -> LlvmLinkageType -> Bool)
-> Eq LlvmLinkageType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmLinkageType -> LlvmLinkageType -> Bool
== :: LlvmLinkageType -> LlvmLinkageType -> Bool
$c/= :: LlvmLinkageType -> LlvmLinkageType -> Bool
/= :: LlvmLinkageType -> LlvmLinkageType -> Bool
Eq)
instance Outputable LlvmLinkageType where
ppr :: LlvmLinkageType -> SDoc
ppr = LlvmLinkageType -> SDoc
forall doc. IsLine doc => LlvmLinkageType -> doc
ppLlvmLinkageType
ppLlvmLinkageType :: IsLine doc => LlvmLinkageType -> doc
ppLlvmLinkageType :: forall doc. IsLine doc => LlvmLinkageType -> doc
ppLlvmLinkageType LlvmLinkageType
Internal = String -> doc
forall doc. IsLine doc => String -> doc
text String
"internal"
ppLlvmLinkageType LlvmLinkageType
LinkOnce = String -> doc
forall doc. IsLine doc => String -> doc
text String
"linkonce"
ppLlvmLinkageType LlvmLinkageType
Weak = String -> doc
forall doc. IsLine doc => String -> doc
text String
"weak"
ppLlvmLinkageType LlvmLinkageType
Appending = String -> doc
forall doc. IsLine doc => String -> doc
text String
"appending"
ppLlvmLinkageType LlvmLinkageType
ExternWeak = String -> doc
forall doc. IsLine doc => String -> doc
text String
"extern_weak"
ppLlvmLinkageType LlvmLinkageType
ExternallyVisible = doc
forall doc. IsOutput doc => doc
empty
ppLlvmLinkageType LlvmLinkageType
External = String -> doc
forall doc. IsLine doc => String -> doc
text String
"external"
ppLlvmLinkageType LlvmLinkageType
Private = String -> doc
forall doc. IsLine doc => String -> doc
text String
"private"
{-# SPECIALIZE ppLlvmLinkageType :: LlvmLinkageType -> SDoc #-}
{-# SPECIALIZE ppLlvmLinkageType :: LlvmLinkageType -> HLine #-}
data LlvmMachOp
= LM_MO_Add
| LM_MO_Sub
| LM_MO_Mul
| LM_MO_UDiv
| LM_MO_SDiv
| LM_MO_URem
| LM_MO_SRem
| LM_MO_FAdd
| LM_MO_FSub
| LM_MO_FMul
| LM_MO_FDiv
| LM_MO_FRem
| LM_MO_Shl
| LM_MO_LShr
| LM_MO_AShr
| LM_MO_And
| LM_MO_Or
| LM_MO_Xor
deriving (LlvmMachOp -> LlvmMachOp -> Bool
(LlvmMachOp -> LlvmMachOp -> Bool)
-> (LlvmMachOp -> LlvmMachOp -> Bool) -> Eq LlvmMachOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmMachOp -> LlvmMachOp -> Bool
== :: LlvmMachOp -> LlvmMachOp -> Bool
$c/= :: LlvmMachOp -> LlvmMachOp -> Bool
/= :: LlvmMachOp -> LlvmMachOp -> Bool
Eq)
instance Outputable LlvmMachOp where
ppr :: LlvmMachOp -> SDoc
ppr = LlvmMachOp -> SDoc
forall doc. IsLine doc => LlvmMachOp -> doc
ppLlvmMachOp
ppLlvmMachOp :: IsLine doc => LlvmMachOp -> doc
ppLlvmMachOp :: forall doc. IsLine doc => LlvmMachOp -> doc
ppLlvmMachOp LlvmMachOp
LM_MO_Add = String -> doc
forall doc. IsLine doc => String -> doc
text String
"add"
ppLlvmMachOp LlvmMachOp
LM_MO_Sub = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sub"
ppLlvmMachOp LlvmMachOp
LM_MO_Mul = String -> doc
forall doc. IsLine doc => String -> doc
text String
"mul"
ppLlvmMachOp LlvmMachOp
LM_MO_UDiv = String -> doc
forall doc. IsLine doc => String -> doc
text String
"udiv"
ppLlvmMachOp LlvmMachOp
LM_MO_SDiv = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sdiv"
ppLlvmMachOp LlvmMachOp
LM_MO_URem = String -> doc
forall doc. IsLine doc => String -> doc
text String
"urem"
ppLlvmMachOp LlvmMachOp
LM_MO_SRem = String -> doc
forall doc. IsLine doc => String -> doc
text String
"srem"
ppLlvmMachOp LlvmMachOp
LM_MO_FAdd = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fadd"
ppLlvmMachOp LlvmMachOp
LM_MO_FSub = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fsub"
ppLlvmMachOp LlvmMachOp
LM_MO_FMul = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fmul"
ppLlvmMachOp LlvmMachOp
LM_MO_FDiv = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fdiv"
ppLlvmMachOp LlvmMachOp
LM_MO_FRem = String -> doc
forall doc. IsLine doc => String -> doc
text String
"frem"
ppLlvmMachOp LlvmMachOp
LM_MO_Shl = String -> doc
forall doc. IsLine doc => String -> doc
text String
"shl"
ppLlvmMachOp LlvmMachOp
LM_MO_LShr = String -> doc
forall doc. IsLine doc => String -> doc
text String
"lshr"
ppLlvmMachOp LlvmMachOp
LM_MO_AShr = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ashr"
ppLlvmMachOp LlvmMachOp
LM_MO_And = String -> doc
forall doc. IsLine doc => String -> doc
text String
"and"
ppLlvmMachOp LlvmMachOp
LM_MO_Or = String -> doc
forall doc. IsLine doc => String -> doc
text String
"or"
ppLlvmMachOp LlvmMachOp
LM_MO_Xor = String -> doc
forall doc. IsLine doc => String -> doc
text String
"xor"
{-# SPECIALIZE ppLlvmMachOp :: LlvmMachOp -> SDoc #-}
{-# SPECIALIZE ppLlvmMachOp :: LlvmMachOp -> HLine #-}
data LlvmCmpOp
= LM_CMP_Eq
| LM_CMP_Ne
| LM_CMP_Ugt
| LM_CMP_Uge
| LM_CMP_Ult
| LM_CMP_Ule
| LM_CMP_Sgt
| LM_CMP_Sge
| LM_CMP_Slt
| LM_CMP_Sle
| LM_CMP_Feq
| LM_CMP_Fne
| LM_CMP_Fgt
| LM_CMP_Fge
| LM_CMP_Flt
| LM_CMP_Fle
deriving (LlvmCmpOp -> LlvmCmpOp -> Bool
(LlvmCmpOp -> LlvmCmpOp -> Bool)
-> (LlvmCmpOp -> LlvmCmpOp -> Bool) -> Eq LlvmCmpOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmCmpOp -> LlvmCmpOp -> Bool
== :: LlvmCmpOp -> LlvmCmpOp -> Bool
$c/= :: LlvmCmpOp -> LlvmCmpOp -> Bool
/= :: LlvmCmpOp -> LlvmCmpOp -> Bool
Eq)
instance Outputable LlvmCmpOp where
ppr :: LlvmCmpOp -> SDoc
ppr = LlvmCmpOp -> SDoc
forall doc. IsLine doc => LlvmCmpOp -> doc
ppLlvmCmpOp
ppLlvmCmpOp :: IsLine doc => LlvmCmpOp -> doc
ppLlvmCmpOp :: forall doc. IsLine doc => LlvmCmpOp -> doc
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Eq = String -> doc
forall doc. IsLine doc => String -> doc
text String
"eq"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Ne = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ne"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Ugt = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ugt"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Uge = String -> doc
forall doc. IsLine doc => String -> doc
text String
"uge"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Ult = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ult"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Ule = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ule"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Sgt = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sgt"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Sge = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sge"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Slt = String -> doc
forall doc. IsLine doc => String -> doc
text String
"slt"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Sle = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sle"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Feq = String -> doc
forall doc. IsLine doc => String -> doc
text String
"oeq"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Fne = String -> doc
forall doc. IsLine doc => String -> doc
text String
"une"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Fgt = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ogt"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Fge = String -> doc
forall doc. IsLine doc => String -> doc
text String
"oge"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Flt = String -> doc
forall doc. IsLine doc => String -> doc
text String
"olt"
ppLlvmCmpOp LlvmCmpOp
LM_CMP_Fle = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ole"
{-# SPECIALIZE ppLlvmCmpOp :: LlvmCmpOp -> SDoc #-}
{-# SPECIALIZE ppLlvmCmpOp :: LlvmCmpOp -> HLine #-}
data LlvmCastOp
= LM_Trunc
| LM_Zext
| LM_Sext
| LM_Fptrunc
| LM_Fpext
| LM_Fptoui
| LM_Fptosi
| LM_Uitofp
| LM_Sitofp
| LM_Ptrtoint
| LM_Inttoptr
| LM_Bitcast
deriving (LlvmCastOp -> LlvmCastOp -> Bool
(LlvmCastOp -> LlvmCastOp -> Bool)
-> (LlvmCastOp -> LlvmCastOp -> Bool) -> Eq LlvmCastOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmCastOp -> LlvmCastOp -> Bool
== :: LlvmCastOp -> LlvmCastOp -> Bool
$c/= :: LlvmCastOp -> LlvmCastOp -> Bool
/= :: LlvmCastOp -> LlvmCastOp -> Bool
Eq)
instance Outputable LlvmCastOp where
ppr :: LlvmCastOp -> SDoc
ppr = LlvmCastOp -> SDoc
forall doc. IsLine doc => LlvmCastOp -> doc
ppLlvmCastOp
ppLlvmCastOp :: IsLine doc => LlvmCastOp -> doc
ppLlvmCastOp :: forall doc. IsLine doc => LlvmCastOp -> doc
ppLlvmCastOp LlvmCastOp
LM_Trunc = String -> doc
forall doc. IsLine doc => String -> doc
text String
"trunc"
ppLlvmCastOp LlvmCastOp
LM_Zext = String -> doc
forall doc. IsLine doc => String -> doc
text String
"zext"
ppLlvmCastOp LlvmCastOp
LM_Sext = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sext"
ppLlvmCastOp LlvmCastOp
LM_Fptrunc = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fptrunc"
ppLlvmCastOp LlvmCastOp
LM_Fpext = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fpext"
ppLlvmCastOp LlvmCastOp
LM_Fptoui = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fptoui"
ppLlvmCastOp LlvmCastOp
LM_Fptosi = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fptosi"
ppLlvmCastOp LlvmCastOp
LM_Uitofp = String -> doc
forall doc. IsLine doc => String -> doc
text String
"uitofp"
ppLlvmCastOp LlvmCastOp
LM_Sitofp = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sitofp"
ppLlvmCastOp LlvmCastOp
LM_Ptrtoint = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ptrtoint"
ppLlvmCastOp LlvmCastOp
LM_Inttoptr = String -> doc
forall doc. IsLine doc => String -> doc
text String
"inttoptr"
ppLlvmCastOp LlvmCastOp
LM_Bitcast = String -> doc
forall doc. IsLine doc => String -> doc
text String
"bitcast"
{-# SPECIALIZE ppLlvmCastOp :: LlvmCastOp -> SDoc #-}
{-# SPECIALIZE ppLlvmCastOp :: LlvmCastOp -> HLine #-}
ppDouble :: IsLine doc => Platform -> Double -> doc
ppDouble :: forall doc. IsLine doc => Platform -> Double -> doc
ppDouble Platform
platform Double
d
= let bs :: [Word8]
bs = Double -> [Word8]
doubleToBytes Double
d
hex :: a -> String
hex a
d' = case a -> ShowS
forall a. Integral a => a -> ShowS
showHex a
d' String
"" of
[] -> ShowS
forall a. HasCallStack => String -> a
error String
"ppDouble: too few hex digits for float"
[Char
x] -> [Char
'0',Char
x]
[Char
x,Char
y] -> [Char
x,Char
y]
String
_ -> ShowS
forall a. HasCallStack => String -> a
error String
"ppDouble: too many hex digits for float"
fixEndian :: [String] -> [String]
fixEndian = case Platform -> ByteOrder
platformByteOrder Platform
platform of
ByteOrder
BigEndian -> [String] -> [String]
forall a. a -> a
id
ByteOrder
LittleEndian -> [String] -> [String]
forall a. [a] -> [a]
reverse
str :: String
str = (Char -> Char) -> ShowS
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String] -> [String]
fixEndian ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ (Word8 -> String) -> [Word8] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Word8 -> String
forall {a}. Integral a => a -> String
hex [Word8]
bs
in String -> doc
forall doc. IsLine doc => String -> doc
text String
"0x" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> doc
forall doc. IsLine doc => String -> doc
text String
str
{-# SPECIALIZE ppDouble :: Platform -> Double -> SDoc #-}
{-# SPECIALIZE ppDouble :: Platform -> Double -> HLine #-}
narrowFp :: Double -> Float
{-# NOINLINE narrowFp #-}
narrowFp :: Double -> Float
narrowFp = Double -> Float
double2Float
widenFp :: Float -> Double
{-# NOINLINE widenFp #-}
widenFp :: Float -> Double
widenFp = Float -> Double
float2Double
ppFloat :: IsLine doc => Platform -> Float -> doc
ppFloat :: forall doc. IsLine doc => Platform -> Float -> doc
ppFloat Platform
platform = Platform -> Double -> doc
forall doc. IsLine doc => Platform -> Double -> doc
ppDouble Platform
platform (Double -> doc) -> (Float -> Double) -> Float -> doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Double
widenFp
{-# SPECIALIZE ppFloat :: Platform -> Float -> SDoc #-}
{-# SPECIALIZE ppFloat :: Platform -> Float -> HLine #-}
ppCommaJoin :: IsLine doc => (a -> doc) -> [a] -> doc
ppCommaJoin :: forall doc a. IsLine doc => (a -> doc) -> [a] -> doc
ppCommaJoin a -> doc
ppr [a]
strs = [doc] -> doc
forall doc. IsLine doc => [doc] -> doc
hsep ([doc] -> doc) -> [doc] -> doc
forall a b. (a -> b) -> a -> b
$ doc -> [doc] -> [doc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate doc
forall doc. IsLine doc => doc
comma ((a -> doc) -> [a] -> [doc]
forall a b. (a -> b) -> [a] -> [b]
map a -> doc
ppr [a]
strs)
{-# SPECIALIZE ppCommaJoin :: (a -> SDoc) -> [a] -> SDoc #-}
{-# SPECIALIZE ppCommaJoin :: (a -> HLine) -> [a] -> HLine #-}
ppSpaceJoin :: IsLine doc => (a -> doc) -> [a] -> doc
ppSpaceJoin :: forall doc a. IsLine doc => (a -> doc) -> [a] -> doc
ppSpaceJoin a -> doc
ppr [a]
strs = [doc] -> doc
forall doc. IsLine doc => [doc] -> doc
hsep ((a -> doc) -> [a] -> [doc]
forall a b. (a -> b) -> [a] -> [b]
map a -> doc
ppr [a]
strs)
{-# SPECIALIZE ppSpaceJoin :: (a -> SDoc) -> [a] -> SDoc #-}
{-# SPECIALIZE ppSpaceJoin :: (a -> HLine) -> [a] -> HLine #-}