{-# LANGUAGE CPP, GeneralizedNewtypeDeriving #-}
module Llvm.Types where
#include "HsVersions.h"
import GhcPrelude
import Data.Char
import Data.Int
import Numeric
import DynFlags
import FastString
import Outputable
import Unique
import PprBase
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
/= :: LlvmType -> LlvmType -> Bool
$c/= :: LlvmType -> LlvmType -> Bool
== :: LlvmType -> LlvmType -> Bool
$c== :: LlvmType -> LlvmType -> Bool
Eq)
instance Outputable LlvmType where
ppr :: LlvmType -> SDoc
ppr (LMInt size :: Int
size ) = Char -> SDoc
char 'i' SDoc -> SDoc -> SDoc
<> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
size
ppr (LlvmType
LMFloat ) = String -> SDoc
text "float"
ppr (LlvmType
LMDouble ) = String -> SDoc
text "double"
ppr (LlvmType
LMFloat80 ) = String -> SDoc
text "x86_fp80"
ppr (LlvmType
LMFloat128 ) = String -> SDoc
text "fp128"
ppr (LMPointer x :: LlvmType
x ) = LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
x SDoc -> SDoc -> SDoc
<> Char -> SDoc
char '*'
ppr (LMArray nr :: Int
nr tp :: LlvmType
tp ) = Char -> SDoc
char '[' SDoc -> SDoc -> SDoc
<> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
nr SDoc -> SDoc -> SDoc
<> String -> SDoc
text " x " SDoc -> SDoc -> SDoc
<> LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
tp SDoc -> SDoc -> SDoc
<> Char -> SDoc
char ']'
ppr (LMVector nr :: Int
nr tp :: LlvmType
tp ) = Char -> SDoc
char '<' SDoc -> SDoc -> SDoc
<> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
nr SDoc -> SDoc -> SDoc
<> String -> SDoc
text " x " SDoc -> SDoc -> SDoc
<> LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
tp SDoc -> SDoc -> SDoc
<> Char -> SDoc
char '>'
ppr (LlvmType
LMLabel ) = String -> SDoc
text "label"
ppr (LlvmType
LMVoid ) = String -> SDoc
text "void"
ppr (LMStruct tys :: [LlvmType]
tys ) = String -> SDoc
text "<{" SDoc -> SDoc -> SDoc
<> [LlvmType] -> SDoc
forall a. Outputable a => [a] -> SDoc
ppCommaJoin [LlvmType]
tys SDoc -> SDoc -> SDoc
<> String -> SDoc
text "}>"
ppr (LMStructU tys :: [LlvmType]
tys ) = String -> SDoc
text "{" SDoc -> SDoc -> SDoc
<> [LlvmType] -> SDoc
forall a. Outputable a => [a] -> SDoc
ppCommaJoin [LlvmType]
tys SDoc -> SDoc -> SDoc
<> String -> SDoc
text "}"
ppr (LlvmType
LMMetadata ) = String -> SDoc
text "metadata"
ppr (LMFunction (LlvmFunctionDecl _ _ _ r :: LlvmType
r varg :: LlvmParameterListType
varg p :: [LlvmParameter]
p _))
= LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
r SDoc -> SDoc -> SDoc
<+> SDoc
lparen SDoc -> SDoc -> SDoc
<> LlvmParameterListType -> [LlvmParameter] -> SDoc
ppParams LlvmParameterListType
varg [LlvmParameter]
p SDoc -> SDoc -> SDoc
<> SDoc
rparen
ppr (LMAlias (s :: LMString
s,_)) = Char -> SDoc
char '%' SDoc -> SDoc -> SDoc
<> LMString -> SDoc
ftext LMString
s
ppParams :: LlvmParameterListType -> [LlvmParameter] -> SDoc
ppParams :: LlvmParameterListType -> [LlvmParameter] -> SDoc
ppParams varg :: LlvmParameterListType
varg p :: [LlvmParameter]
p
= let varg' :: PtrString
varg' = case LlvmParameterListType
varg of
VarArgs | [LlvmType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LlvmType]
args -> String -> PtrString
sLit "..."
| Bool
otherwise -> String -> PtrString
sLit ", ..."
_otherwise :: LlvmParameterListType
_otherwise -> String -> PtrString
sLit ""
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] -> SDoc
forall a. Outputable a => [a] -> SDoc
ppCommaJoin [LlvmType]
args SDoc -> SDoc -> SDoc
<> PtrString -> SDoc
ptext PtrString
varg'
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
/= :: LMConst -> LMConst -> Bool
$c/= :: LMConst -> LMConst -> Bool
== :: LMConst -> LMConst -> Bool
$c== :: 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
/= :: LlvmVar -> LlvmVar -> Bool
$c/= :: LlvmVar -> LlvmVar -> Bool
== :: LlvmVar -> LlvmVar -> Bool
$c== :: LlvmVar -> LlvmVar -> Bool
Eq)
instance Outputable LlvmVar where
ppr :: LlvmVar -> SDoc
ppr (LMLitVar x :: LlvmLit
x) = LlvmLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmLit
x
ppr (LlvmVar
x ) = LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (LlvmVar -> LlvmType
getVarType LlvmVar
x) SDoc -> SDoc -> SDoc
<+> LlvmVar -> SDoc
ppName LlvmVar
x
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
/= :: LlvmLit -> LlvmLit -> Bool
$c/= :: LlvmLit -> LlvmLit -> Bool
== :: LlvmLit -> LlvmLit -> Bool
$c== :: LlvmLit -> LlvmLit -> Bool
Eq)
instance Outputable LlvmLit where
ppr :: LlvmLit -> SDoc
ppr l :: LlvmLit
l@(LMVectorLit {}) = LlvmLit -> SDoc
ppLit LlvmLit
l
ppr l :: LlvmLit
l = LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (LlvmLit -> LlvmType
getLitType LlvmLit
l) SDoc -> SDoc -> SDoc
<+> LlvmLit -> SDoc
ppLit LlvmLit
l
data LlvmStatic
= LMString
| LMStaticLit LlvmLit
| LMUninitType LlvmType
| LMStaticStr LMString LlvmType
| LMStaticArray [LlvmStatic] LlvmType
| LMStaticStruc [LlvmStatic] LlvmType
| LMStaticPointer LlvmVar
| LMTrunc LlvmStatic LlvmType
| LMBitc LlvmStatic LlvmType
| LMPtoI LlvmStatic LlvmType
| LMAdd LlvmStatic LlvmStatic
| LMSub LlvmStatic LlvmStatic
instance Outputable LlvmStatic where
ppr :: LlvmStatic -> SDoc
ppr (LMComment s :: LMString
s) = String -> SDoc
text "; " SDoc -> SDoc -> SDoc
<> LMString -> SDoc
ftext LMString
s
ppr (LMStaticLit l :: LlvmLit
l ) = LlvmLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmLit
l
ppr (LMUninitType t :: LlvmType
t) = LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> String -> SDoc
text " undef"
ppr (LMStaticStr s :: LMString
s t :: LlvmType
t) = LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> String -> SDoc
text " c\"" SDoc -> SDoc -> SDoc
<> LMString -> SDoc
ftext LMString
s SDoc -> SDoc -> SDoc
<> String -> SDoc
text "\\00\""
ppr (LMStaticArray d :: [LlvmStatic]
d t :: LlvmType
t) = LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> String -> SDoc
text " [" SDoc -> SDoc -> SDoc
<> [LlvmStatic] -> SDoc
forall a. Outputable a => [a] -> SDoc
ppCommaJoin [LlvmStatic]
d SDoc -> SDoc -> SDoc
<> Char -> SDoc
char ']'
ppr (LMStaticStruc d :: [LlvmStatic]
d t :: LlvmType
t) = LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> String -> SDoc
text "<{" SDoc -> SDoc -> SDoc
<> [LlvmStatic] -> SDoc
forall a. Outputable a => [a] -> SDoc
ppCommaJoin [LlvmStatic]
d SDoc -> SDoc -> SDoc
<> String -> SDoc
text "}>"
ppr (LMStaticPointer v :: LlvmVar
v) = LlvmVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmVar
v
ppr (LMTrunc v :: LlvmStatic
v t :: LlvmType
t)
= LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> String -> SDoc
text " trunc (" SDoc -> SDoc -> SDoc
<> LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
v SDoc -> SDoc -> SDoc
<> String -> SDoc
text " to " SDoc -> SDoc -> SDoc
<> LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> Char -> SDoc
char ')'
ppr (LMBitc v :: LlvmStatic
v t :: LlvmType
t)
= LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> String -> SDoc
text " bitcast (" SDoc -> SDoc -> SDoc
<> LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
v SDoc -> SDoc -> SDoc
<> String -> SDoc
text " to " SDoc -> SDoc -> SDoc
<> LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> Char -> SDoc
char ')'
ppr (LMPtoI v :: LlvmStatic
v t :: LlvmType
t)
= LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> String -> SDoc
text " ptrtoint (" SDoc -> SDoc -> SDoc
<> LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
v SDoc -> SDoc -> SDoc
<> String -> SDoc
text " to " SDoc -> SDoc -> SDoc
<> LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t SDoc -> SDoc -> SDoc
<> Char -> SDoc
char ')'
ppr (LMAdd s1 :: LlvmStatic
s1 s2 :: LlvmStatic
s2)
= LlvmStatic
-> LlvmStatic -> PtrString -> PtrString -> String -> SDoc
pprStaticArith LlvmStatic
s1 LlvmStatic
s2 (String -> PtrString
sLit "add") (String -> PtrString
sLit "fadd") "LMAdd"
ppr (LMSub s1 :: LlvmStatic
s1 s2 :: LlvmStatic
s2)
= LlvmStatic
-> LlvmStatic -> PtrString -> PtrString -> String -> SDoc
pprStaticArith LlvmStatic
s1 LlvmStatic
s2 (String -> PtrString
sLit "sub") (String -> PtrString
sLit "fsub") "LMSub"
pprSpecialStatic :: LlvmStatic -> SDoc
pprSpecialStatic :: LlvmStatic -> SDoc
pprSpecialStatic (LMBitc v :: LlvmStatic
v t :: LlvmType
t) =
LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (LlvmType -> LlvmType
pLower LlvmType
t) SDoc -> SDoc -> SDoc
<> String -> SDoc
text ", bitcast (" SDoc -> SDoc -> SDoc
<> LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
v SDoc -> SDoc -> SDoc
<> String -> SDoc
text " to " SDoc -> SDoc -> SDoc
<> LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
t
SDoc -> SDoc -> SDoc
<> Char -> SDoc
char ')'
pprSpecialStatic stat :: LlvmStatic
stat = LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
stat
pprStaticArith :: LlvmStatic -> LlvmStatic -> PtrString -> PtrString
-> String -> SDoc
pprStaticArith :: LlvmStatic
-> LlvmStatic -> PtrString -> PtrString -> String -> SDoc
pprStaticArith s1 :: LlvmStatic
s1 s2 :: LlvmStatic
s2 int_op :: PtrString
int_op float_op :: PtrString
float_op op_name :: String
op_name =
let ty1 :: LlvmType
ty1 = LlvmStatic -> LlvmType
getStatType LlvmStatic
s1
op :: PtrString
op = if LlvmType -> Bool
isFloat LlvmType
ty1 then PtrString
float_op else PtrString
int_op
in if LlvmType
ty1 LlvmType -> LlvmType -> Bool
forall a. Eq a => a -> a -> Bool
== LlvmStatic -> LlvmType
getStatType LlvmStatic
s2
then LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
ty1 SDoc -> SDoc -> SDoc
<+> PtrString -> SDoc
ptext PtrString
op SDoc -> SDoc -> SDoc
<+> SDoc
lparen SDoc -> SDoc -> SDoc
<> LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
s1 SDoc -> SDoc -> SDoc
<> SDoc
comma SDoc -> SDoc -> SDoc
<> LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
s2 SDoc -> SDoc -> SDoc
<> SDoc
rparen
else (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
String -> SDoc
forall a. HasCallStack => String -> a
error (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ String
op_name String -> String -> String
forall a. [a] -> [a] -> [a]
++ " with different types! s1: "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
s1) String -> String -> String
forall a. [a] -> [a] -> [a]
++ ", s2: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (LlvmStatic -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmStatic
s2)
ppName :: LlvmVar -> SDoc
ppName :: LlvmVar -> SDoc
ppName v :: LlvmVar
v@(LMGlobalVar {}) = Char -> SDoc
char '@' SDoc -> SDoc -> SDoc
<> LlvmVar -> SDoc
ppPlainName LlvmVar
v
ppName v :: LlvmVar
v@(LMLocalVar {}) = Char -> SDoc
char '%' SDoc -> SDoc -> SDoc
<> LlvmVar -> SDoc
ppPlainName LlvmVar
v
ppName v :: LlvmVar
v@(LMNLocalVar {}) = Char -> SDoc
char '%' SDoc -> SDoc -> SDoc
<> LlvmVar -> SDoc
ppPlainName LlvmVar
v
ppName v :: LlvmVar
v@(LMLitVar {}) = LlvmVar -> SDoc
ppPlainName LlvmVar
v
ppPlainName :: LlvmVar -> SDoc
ppPlainName :: LlvmVar -> SDoc
ppPlainName (LMGlobalVar x :: LMString
x _ _ _ _ _) = LMString -> SDoc
ftext LMString
x
ppPlainName (LMLocalVar x :: Unique
x LMLabel ) = String -> SDoc
text (Unique -> String
forall a. Show a => a -> String
show Unique
x)
ppPlainName (LMLocalVar x :: Unique
x _ ) = String -> SDoc
text ('l' Char -> String -> String
forall a. a -> [a] -> [a]
: Unique -> String
forall a. Show a => a -> String
show Unique
x)
ppPlainName (LMNLocalVar x :: LMString
x _ ) = LMString -> SDoc
ftext LMString
x
ppPlainName (LMLitVar x :: LlvmLit
x ) = LlvmLit -> SDoc
ppLit LlvmLit
x
ppLit :: LlvmLit -> SDoc
ppLit :: LlvmLit -> SDoc
ppLit (LMIntLit i :: Integer
i (LMInt 32)) = Int32 -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Integer -> Int32
forall a. Num a => Integer -> a
fromInteger Integer
i :: Int32)
ppLit (LMIntLit i :: Integer
i (LMInt 64)) = Int64 -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Integer -> Int64
forall a. Num a => Integer -> a
fromInteger Integer
i :: Int64)
ppLit (LMIntLit i :: Integer
i _ ) = Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr ((Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
i)::Int)
ppLit (LMFloatLit r :: Double
r LMFloat ) = Float -> SDoc
ppFloat (Float -> SDoc) -> Float -> SDoc
forall a b. (a -> b) -> a -> b
$ Double -> Float
narrowFp Double
r
ppLit (LMFloatLit r :: Double
r LMDouble) = Double -> SDoc
ppDouble Double
r
ppLit f :: LlvmLit
f@(LMFloatLit _ _) = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags (\dflags :: DynFlags
dflags ->
String -> SDoc
forall a. HasCallStack => String -> a
error (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ "Can't print this float literal!" String -> String -> String
forall a. [a] -> [a] -> [a]
++ DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (LlvmLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmLit
f))
ppLit (LMVectorLit ls :: [LlvmLit]
ls ) = Char -> SDoc
char '<' SDoc -> SDoc -> SDoc
<+> [LlvmLit] -> SDoc
forall a. Outputable a => [a] -> SDoc
ppCommaJoin [LlvmLit]
ls SDoc -> SDoc -> SDoc
<+> Char -> SDoc
char '>'
ppLit (LMNullLit _ ) = String -> SDoc
text "null"
ppLit (LMUndefLit t :: LlvmType
t ) = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags DynFlags -> SDoc
f
where f :: DynFlags -> SDoc
f dflags :: DynFlags
dflags
| GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_LlvmFillUndefWithGarbage DynFlags
dflags,
Just lit :: LlvmLit
lit <- LlvmType -> Maybe LlvmLit
garbageLit LlvmType
t = LlvmLit -> SDoc
ppLit LlvmLit
lit
| Bool
otherwise = String -> SDoc
text "undef"
garbageLit :: LlvmType -> Maybe LlvmLit
garbageLit :: LlvmType -> Maybe LlvmLit
garbageLit t :: LlvmType
t@(LMInt w :: Int
w) = LlvmLit -> Maybe LlvmLit
forall a. a -> Maybe a
Just (Integer -> LlvmType -> LlvmLit
LMIntLit (0xbbbbbbbbbbbbbbb0 Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` (2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Int
w)) LlvmType
t)
garbageLit t :: LlvmType
t
| LlvmType -> Bool
isFloat LlvmType
t = LlvmLit -> Maybe LlvmLit
forall a. a -> Maybe a
Just (Double -> LlvmType -> LlvmLit
LMFloatLit 12345678.9 LlvmType
t)
garbageLit t :: LlvmType
t@(LMPointer _) = LlvmLit -> Maybe LlvmLit
forall a. a -> Maybe a
Just (LlvmType -> LlvmLit
LMNullLit LlvmType
t)
garbageLit _ = Maybe LlvmLit
forall a. Maybe a
Nothing
getVarType :: LlvmVar -> LlvmType
getVarType :: LlvmVar -> LlvmType
getVarType (LMGlobalVar _ y :: LlvmType
y _ _ _ _) = LlvmType
y
getVarType (LMLocalVar _ y :: LlvmType
y ) = LlvmType
y
getVarType (LMNLocalVar _ y :: LlvmType
y ) = LlvmType
y
getVarType (LMLitVar l :: LlvmLit
l ) = LlvmLit -> LlvmType
getLitType LlvmLit
l
getLitType :: LlvmLit -> LlvmType
getLitType :: LlvmLit -> LlvmType
getLitType (LMIntLit _ t :: LlvmType
t) = LlvmType
t
getLitType (LMFloatLit _ t :: LlvmType
t) = LlvmType
t
getLitType (LMVectorLit []) = String -> LlvmType
forall a. String -> a
panic "getLitType"
getLitType (LMVectorLit ls :: [LlvmLit]
ls) = Int -> LlvmType -> LlvmType
LMVector ([LlvmLit] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LlvmLit]
ls) (LlvmLit -> LlvmType
getLitType ([LlvmLit] -> LlvmLit
forall a. [a] -> a
head [LlvmLit]
ls))
getLitType (LMNullLit t :: LlvmType
t) = LlvmType
t
getLitType (LMUndefLit t :: LlvmType
t) = LlvmType
t
getStatType :: LlvmStatic -> LlvmType
getStatType :: LlvmStatic -> LlvmType
getStatType (LMStaticLit l :: LlvmLit
l ) = LlvmLit -> LlvmType
getLitType LlvmLit
l
getStatType (LMUninitType t :: LlvmType
t) = LlvmType
t
getStatType (LMStaticStr _ t :: LlvmType
t) = LlvmType
t
getStatType (LMStaticArray _ t :: LlvmType
t) = LlvmType
t
getStatType (LMStaticStruc _ t :: LlvmType
t) = LlvmType
t
getStatType (LMStaticPointer v :: LlvmVar
v) = LlvmVar -> LlvmType
getVarType LlvmVar
v
getStatType (LMTrunc _ t :: LlvmType
t) = LlvmType
t
getStatType (LMBitc _ t :: LlvmType
t) = LlvmType
t
getStatType (LMPtoI _ t :: LlvmType
t) = LlvmType
t
getStatType (LMAdd t :: LlvmStatic
t _) = LlvmStatic -> LlvmType
getStatType LlvmStatic
t
getStatType (LMSub t :: LlvmStatic
t _) = LlvmStatic -> LlvmType
getStatType LlvmStatic
t
getStatType (LMComment _) = String -> LlvmType
forall a. HasCallStack => String -> a
error "Can't call getStatType on LMComment!"
getLink :: LlvmVar -> LlvmLinkageType
getLink :: LlvmVar -> LlvmLinkageType
getLink (LMGlobalVar _ _ l :: LlvmLinkageType
l _ _ _) = LlvmLinkageType
l
getLink _ = LlvmLinkageType
Internal
pLift :: LlvmType -> LlvmType
pLift :: LlvmType -> LlvmType
pLift LMLabel = String -> LlvmType
forall a. HasCallStack => String -> a
error "Labels are unliftable"
pLift LMVoid = String -> LlvmType
forall a. HasCallStack => String -> a
error "Voids are unliftable"
pLift LMMetadata = String -> LlvmType
forall a. HasCallStack => String -> a
error "Metadatas are unliftable"
pLift x :: LlvmType
x = LlvmType -> LlvmType
LMPointer LlvmType
x
pVarLift :: LlvmVar -> LlvmVar
pVarLift :: LlvmVar -> LlvmVar
pVarLift (LMGlobalVar s :: LMString
s t :: LlvmType
t l :: LlvmLinkageType
l x :: LMSection
x a :: LMAlign
a c :: LMConst
c) = LMString
-> LlvmType
-> LlvmLinkageType
-> LMSection
-> LMAlign
-> LMConst
-> LlvmVar
LMGlobalVar LMString
s (LlvmType -> LlvmType
pLift LlvmType
t) LlvmLinkageType
l LMSection
x LMAlign
a LMConst
c
pVarLift (LMLocalVar s :: Unique
s t :: LlvmType
t ) = Unique -> LlvmType -> LlvmVar
LMLocalVar Unique
s (LlvmType -> LlvmType
pLift LlvmType
t)
pVarLift (LMNLocalVar s :: LMString
s t :: LlvmType
t ) = LMString -> LlvmType -> LlvmVar
LMNLocalVar LMString
s (LlvmType -> LlvmType
pLift LlvmType
t)
pVarLift (LMLitVar _ ) = String -> LlvmVar
forall a. HasCallStack => String -> a
error (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ "Can't lower a literal type!"
pLower :: LlvmType -> LlvmType
pLower :: LlvmType -> LlvmType
pLower (LMPointer x :: LlvmType
x) = LlvmType
x
pLower x :: LlvmType
x = String -> SDoc -> LlvmType
forall a. HasCallStack => String -> SDoc -> a
pprPanic "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
<+> String -> SDoc
text " is a unlowerable type, need a pointer"
pVarLower :: LlvmVar -> LlvmVar
pVarLower :: LlvmVar -> LlvmVar
pVarLower (LMGlobalVar s :: LMString
s t :: LlvmType
t l :: LlvmLinkageType
l x :: LMSection
x a :: LMAlign
a c :: LMConst
c) = LMString
-> LlvmType
-> LlvmLinkageType
-> LMSection
-> LMAlign
-> LMConst
-> LlvmVar
LMGlobalVar LMString
s (LlvmType -> LlvmType
pLower LlvmType
t) LlvmLinkageType
l LMSection
x LMAlign
a LMConst
c
pVarLower (LMLocalVar s :: Unique
s t :: LlvmType
t ) = Unique -> LlvmType -> LlvmVar
LMLocalVar Unique
s (LlvmType -> LlvmType
pLower LlvmType
t)
pVarLower (LMNLocalVar s :: LMString
s t :: LlvmType
t ) = LMString -> LlvmType -> LlvmVar
LMNLocalVar LMString
s (LlvmType -> LlvmType
pLower LlvmType
t)
pVarLower (LMLitVar _ ) = String -> LlvmVar
forall a. HasCallStack => String -> a
error (String -> LlvmVar) -> String -> LlvmVar
forall a b. (a -> b) -> a -> b
$ "Can't lower a literal type!"
isInt :: LlvmType -> Bool
isInt :: LlvmType -> Bool
isInt (LMInt _) = Bool
True
isInt _ = Bool
False
isFloat :: LlvmType -> Bool
isFloat :: LlvmType -> Bool
isFloat LMFloat = Bool
True
isFloat LMDouble = Bool
True
isFloat LMFloat80 = Bool
True
isFloat LMFloat128 = Bool
True
isFloat _ = Bool
False
isPointer :: LlvmType -> Bool
isPointer :: LlvmType -> Bool
isPointer (LMPointer _) = Bool
True
isPointer _ = Bool
False
isVector :: LlvmType -> Bool
isVector :: LlvmType -> Bool
isVector (LMVector {}) = Bool
True
isVector _ = Bool
False
isGlobal :: LlvmVar -> Bool
isGlobal :: LlvmVar -> Bool
isGlobal (LMGlobalVar _ _ _ _ _ _) = Bool
True
isGlobal _ = Bool
False
llvmWidthInBits :: DynFlags -> LlvmType -> Int
llvmWidthInBits :: DynFlags -> LlvmType -> Int
llvmWidthInBits _ (LMInt n :: Int
n) = Int
n
llvmWidthInBits _ (LlvmType
LMFloat) = 32
llvmWidthInBits _ (LlvmType
LMDouble) = 64
llvmWidthInBits _ (LlvmType
LMFloat80) = 80
llvmWidthInBits _ (LlvmType
LMFloat128) = 128
llvmWidthInBits dflags :: DynFlags
dflags (LMPointer _) = DynFlags -> LlvmType -> Int
llvmWidthInBits DynFlags
dflags (DynFlags -> LlvmType
llvmWord DynFlags
dflags)
llvmWidthInBits dflags :: DynFlags
dflags (LMArray n :: Int
n t :: LlvmType
t) = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* DynFlags -> LlvmType -> Int
llvmWidthInBits DynFlags
dflags LlvmType
t
llvmWidthInBits dflags :: DynFlags
dflags (LMVector n :: Int
n ty :: LlvmType
ty) = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* DynFlags -> LlvmType -> Int
llvmWidthInBits DynFlags
dflags LlvmType
ty
llvmWidthInBits _ LMLabel = 0
llvmWidthInBits _ LMVoid = 0
llvmWidthInBits dflags :: DynFlags
dflags (LMStruct tys :: [LlvmType]
tys) = [Int] -> Int
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 (DynFlags -> LlvmType -> Int
llvmWidthInBits DynFlags
dflags) [LlvmType]
tys
llvmWidthInBits _ (LMStructU _) =
String -> Int
forall a. String -> a
panic "llvmWidthInBits: not implemented for LMStructU"
llvmWidthInBits _ (LMFunction _) = 0
llvmWidthInBits dflags :: DynFlags
dflags (LMAlias (_,t :: LlvmType
t)) = DynFlags -> LlvmType -> Int
llvmWidthInBits DynFlags
dflags LlvmType
t
llvmWidthInBits _ LMMetadata = String -> Int
forall a. String -> a
panic "llvmWidthInBits: Meta-data has no runtime representation!"
i128, i64, i32, i16, i8, i1, i8Ptr :: LlvmType
i128 :: LlvmType
i128 = Int -> LlvmType
LMInt 128
i64 :: LlvmType
i64 = Int -> LlvmType
LMInt 64
i32 :: LlvmType
i32 = Int -> LlvmType
LMInt 32
i16 :: LlvmType
i16 = Int -> LlvmType
LMInt 16
i8 :: LlvmType
i8 = Int -> LlvmType
LMInt 8
i1 :: LlvmType
i1 = Int -> LlvmType
LMInt 1
i8Ptr :: LlvmType
i8Ptr = LlvmType -> LlvmType
pLift LlvmType
i8
llvmWord, llvmWordPtr :: DynFlags -> LlvmType
llvmWord :: DynFlags -> LlvmType
llvmWord dflags :: DynFlags
dflags = Int -> LlvmType
LMInt (DynFlags -> Int
wORD_SIZE DynFlags
dflags Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8)
llvmWordPtr :: DynFlags -> LlvmType
llvmWordPtr dflags :: DynFlags
dflags = LlvmType -> LlvmType
pLift (DynFlags -> LlvmType
llvmWord DynFlags
dflags)
data LlvmFunctionDecl = LlvmFunctionDecl {
LlvmFunctionDecl -> LMString
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
/= :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
$c/= :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
== :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
$c== :: LlvmFunctionDecl -> LlvmFunctionDecl -> Bool
Eq)
instance Outputable LlvmFunctionDecl where
ppr :: LlvmFunctionDecl -> SDoc
ppr (LlvmFunctionDecl n :: LMString
n l :: LlvmLinkageType
l c :: LlvmCallConvention
c r :: LlvmType
r varg :: LlvmParameterListType
varg p :: [LlvmParameter]
p a :: LMAlign
a)
= let align :: SDoc
align = case LMAlign
a of
Just a' :: Int
a' -> String -> SDoc
text " align " SDoc -> SDoc -> SDoc
<> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
a'
Nothing -> SDoc
empty
in LlvmLinkageType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmLinkageType
l SDoc -> SDoc -> SDoc
<+> LlvmCallConvention -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmCallConvention
c SDoc -> SDoc -> SDoc
<+> LlvmType -> SDoc
forall a. Outputable a => a -> SDoc
ppr LlvmType
r SDoc -> SDoc -> SDoc
<+> Char -> SDoc
char '@' SDoc -> SDoc -> SDoc
<> LMString -> SDoc
ftext LMString
n SDoc -> SDoc -> SDoc
<>
SDoc
lparen SDoc -> SDoc -> SDoc
<> LlvmParameterListType -> [LlvmParameter] -> SDoc
ppParams LlvmParameterListType
varg [LlvmParameter]
p SDoc -> SDoc -> SDoc
<> SDoc
rparen SDoc -> SDoc -> SDoc
<> SDoc
align
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
/= :: LlvmParamAttr -> LlvmParamAttr -> Bool
$c/= :: LlvmParamAttr -> LlvmParamAttr -> Bool
== :: LlvmParamAttr -> LlvmParamAttr -> Bool
$c== :: LlvmParamAttr -> LlvmParamAttr -> Bool
Eq)
instance Outputable LlvmParamAttr where
ppr :: LlvmParamAttr -> SDoc
ppr ZeroExt = String -> SDoc
text "zeroext"
ppr SignExt = String -> SDoc
text "signext"
ppr InReg = String -> SDoc
text "inreg"
ppr ByVal = String -> SDoc
text "byval"
ppr SRet = String -> SDoc
text "sret"
ppr NoAlias = String -> SDoc
text "noalias"
ppr NoCapture = String -> SDoc
text "nocapture"
ppr Nest = String -> SDoc
text "nest"
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
/= :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
$c/= :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
== :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
$c== :: LlvmFuncAttr -> LlvmFuncAttr -> Bool
Eq)
instance Outputable LlvmFuncAttr where
ppr :: LlvmFuncAttr -> SDoc
ppr AlwaysInline = String -> SDoc
text "alwaysinline"
ppr InlineHint = String -> SDoc
text "inlinehint"
ppr NoInline = String -> SDoc
text "noinline"
ppr OptSize = String -> SDoc
text "optsize"
ppr NoReturn = String -> SDoc
text "noreturn"
ppr NoUnwind = String -> SDoc
text "nounwind"
ppr ReadNone = String -> SDoc
text "readnon"
ppr ReadOnly = String -> SDoc
text "readonly"
ppr Ssp = String -> SDoc
text "ssp"
ppr SspReq = String -> SDoc
text "ssqreq"
ppr NoRedZone = String -> SDoc
text "noredzone"
ppr NoImplicitFloat = String -> SDoc
text "noimplicitfloat"
ppr Naked = String -> SDoc
text "naked"
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
/= :: LlvmCallType -> LlvmCallType -> Bool
$c/= :: LlvmCallType -> LlvmCallType -> Bool
== :: LlvmCallType -> LlvmCallType -> Bool
$c== :: LlvmCallType -> LlvmCallType -> Bool
Eq,Int -> LlvmCallType -> String -> String
[LlvmCallType] -> String -> String
LlvmCallType -> String
(Int -> LlvmCallType -> String -> String)
-> (LlvmCallType -> String)
-> ([LlvmCallType] -> String -> String)
-> Show LlvmCallType
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [LlvmCallType] -> String -> String
$cshowList :: [LlvmCallType] -> String -> String
show :: LlvmCallType -> String
$cshow :: LlvmCallType -> String
showsPrec :: Int -> LlvmCallType -> String -> String
$cshowsPrec :: Int -> LlvmCallType -> String -> String
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
/= :: LlvmCallConvention -> LlvmCallConvention -> Bool
$c/= :: LlvmCallConvention -> LlvmCallConvention -> Bool
== :: LlvmCallConvention -> LlvmCallConvention -> Bool
$c== :: LlvmCallConvention -> LlvmCallConvention -> Bool
Eq)
instance Outputable LlvmCallConvention where
ppr :: LlvmCallConvention -> SDoc
ppr CC_Ccc = String -> SDoc
text "ccc"
ppr CC_Fastcc = String -> SDoc
text "fastcc"
ppr CC_Coldcc = String -> SDoc
text "coldcc"
ppr CC_Ghc = String -> SDoc
text "ghccc"
ppr (CC_Ncc i :: Int
i) = String -> SDoc
text "cc " SDoc -> SDoc -> SDoc
<> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
i
ppr CC_X86_Stdcc = String -> SDoc
text "x86_stdcallcc"
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
/= :: LlvmParameterListType -> LlvmParameterListType -> Bool
$c/= :: LlvmParameterListType -> LlvmParameterListType -> Bool
== :: LlvmParameterListType -> LlvmParameterListType -> Bool
$c== :: LlvmParameterListType -> LlvmParameterListType -> Bool
Eq,Int -> LlvmParameterListType -> String -> String
[LlvmParameterListType] -> String -> String
LlvmParameterListType -> String
(Int -> LlvmParameterListType -> String -> String)
-> (LlvmParameterListType -> String)
-> ([LlvmParameterListType] -> String -> String)
-> Show LlvmParameterListType
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [LlvmParameterListType] -> String -> String
$cshowList :: [LlvmParameterListType] -> String -> String
show :: LlvmParameterListType -> String
$cshow :: LlvmParameterListType -> String
showsPrec :: Int -> LlvmParameterListType -> String -> String
$cshowsPrec :: Int -> LlvmParameterListType -> String -> String
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
/= :: LlvmLinkageType -> LlvmLinkageType -> Bool
$c/= :: LlvmLinkageType -> LlvmLinkageType -> Bool
== :: LlvmLinkageType -> LlvmLinkageType -> Bool
$c== :: LlvmLinkageType -> LlvmLinkageType -> Bool
Eq)
instance Outputable LlvmLinkageType where
ppr :: LlvmLinkageType -> SDoc
ppr Internal = String -> SDoc
text "internal"
ppr LinkOnce = String -> SDoc
text "linkonce"
ppr Weak = String -> SDoc
text "weak"
ppr Appending = String -> SDoc
text "appending"
ppr ExternWeak = String -> SDoc
text "extern_weak"
ppr ExternallyVisible = SDoc
empty
ppr External = String -> SDoc
text "external"
ppr Private = String -> SDoc
text "private"
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
/= :: LlvmMachOp -> LlvmMachOp -> Bool
$c/= :: LlvmMachOp -> LlvmMachOp -> Bool
== :: LlvmMachOp -> LlvmMachOp -> Bool
$c== :: LlvmMachOp -> LlvmMachOp -> Bool
Eq)
instance Outputable LlvmMachOp where
ppr :: LlvmMachOp -> SDoc
ppr LM_MO_Add = String -> SDoc
text "add"
ppr LM_MO_Sub = String -> SDoc
text "sub"
ppr LM_MO_Mul = String -> SDoc
text "mul"
ppr LM_MO_UDiv = String -> SDoc
text "udiv"
ppr LM_MO_SDiv = String -> SDoc
text "sdiv"
ppr LM_MO_URem = String -> SDoc
text "urem"
ppr LM_MO_SRem = String -> SDoc
text "srem"
ppr LM_MO_FAdd = String -> SDoc
text "fadd"
ppr LM_MO_FSub = String -> SDoc
text "fsub"
ppr LM_MO_FMul = String -> SDoc
text "fmul"
ppr LM_MO_FDiv = String -> SDoc
text "fdiv"
ppr LM_MO_FRem = String -> SDoc
text "frem"
ppr LM_MO_Shl = String -> SDoc
text "shl"
ppr LM_MO_LShr = String -> SDoc
text "lshr"
ppr LM_MO_AShr = String -> SDoc
text "ashr"
ppr LM_MO_And = String -> SDoc
text "and"
ppr LM_MO_Or = String -> SDoc
text "or"
ppr LM_MO_Xor = String -> SDoc
text "xor"
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
/= :: LlvmCmpOp -> LlvmCmpOp -> Bool
$c/= :: LlvmCmpOp -> LlvmCmpOp -> Bool
== :: LlvmCmpOp -> LlvmCmpOp -> Bool
$c== :: LlvmCmpOp -> LlvmCmpOp -> Bool
Eq)
instance Outputable LlvmCmpOp where
ppr :: LlvmCmpOp -> SDoc
ppr LM_CMP_Eq = String -> SDoc
text "eq"
ppr LM_CMP_Ne = String -> SDoc
text "ne"
ppr LM_CMP_Ugt = String -> SDoc
text "ugt"
ppr LM_CMP_Uge = String -> SDoc
text "uge"
ppr LM_CMP_Ult = String -> SDoc
text "ult"
ppr LM_CMP_Ule = String -> SDoc
text "ule"
ppr LM_CMP_Sgt = String -> SDoc
text "sgt"
ppr LM_CMP_Sge = String -> SDoc
text "sge"
ppr LM_CMP_Slt = String -> SDoc
text "slt"
ppr LM_CMP_Sle = String -> SDoc
text "sle"
ppr LM_CMP_Feq = String -> SDoc
text "oeq"
ppr LM_CMP_Fne = String -> SDoc
text "une"
ppr LM_CMP_Fgt = String -> SDoc
text "ogt"
ppr LM_CMP_Fge = String -> SDoc
text "oge"
ppr LM_CMP_Flt = String -> SDoc
text "olt"
ppr LM_CMP_Fle = String -> SDoc
text "ole"
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
/= :: LlvmCastOp -> LlvmCastOp -> Bool
$c/= :: LlvmCastOp -> LlvmCastOp -> Bool
== :: LlvmCastOp -> LlvmCastOp -> Bool
$c== :: LlvmCastOp -> LlvmCastOp -> Bool
Eq)
instance Outputable LlvmCastOp where
ppr :: LlvmCastOp -> SDoc
ppr LM_Trunc = String -> SDoc
text "trunc"
ppr LM_Zext = String -> SDoc
text "zext"
ppr LM_Sext = String -> SDoc
text "sext"
ppr LM_Fptrunc = String -> SDoc
text "fptrunc"
ppr LM_Fpext = String -> SDoc
text "fpext"
ppr LM_Fptoui = String -> SDoc
text "fptoui"
ppr LM_Fptosi = String -> SDoc
text "fptosi"
ppr LM_Uitofp = String -> SDoc
text "uitofp"
ppr LM_Sitofp = String -> SDoc
text "sitofp"
ppr LM_Ptrtoint = String -> SDoc
text "ptrtoint"
ppr LM_Inttoptr = String -> SDoc
text "inttoptr"
ppr LM_Bitcast = String -> SDoc
text "bitcast"
ppDouble :: Double -> SDoc
ppDouble :: Double -> SDoc
ppDouble d :: Double
d
= let bs :: [Int]
bs = Double -> [Int]
doubleToBytes Double
d
hex :: a -> String
hex d' :: a
d' = case a -> String -> String
forall a. (Integral a, Show a) => a -> String -> String
showHex a
d' "" of
[] -> String -> String
forall a. HasCallStack => String -> a
error "dToStr: too few hex digits for float"
[x :: Char
x] -> ['0',Char
x]
[x :: Char
x,y :: Char
y] -> [Char
x,Char
y]
_ -> String -> String
forall a. HasCallStack => String -> a
error "dToStr: too many hex digits for float"
str :: String
str = (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper (String -> String) -> String -> String
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]
forall a. [a] -> [a]
fixEndian ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ (Int -> String) -> [Int] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Int -> String
forall a. (Integral a, Show a) => a -> String
hex [Int]
bs
in String -> SDoc
text "0x" SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
str
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 :: Float -> SDoc
ppFloat :: Float -> SDoc
ppFloat = Double -> SDoc
ppDouble (Double -> SDoc) -> (Float -> Double) -> Float -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Double
widenFp
fixEndian :: [a] -> [a]
#if defined(WORDS_BIGENDIAN)
fixEndian = id
#else
fixEndian :: [a] -> [a]
fixEndian = [a] -> [a]
forall a. [a] -> [a]
reverse
#endif
ppCommaJoin :: (Outputable a) => [a] -> SDoc
ppCommaJoin :: [a] -> SDoc
ppCommaJoin strs :: [a]
strs = [SDoc] -> SDoc
hsep ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma ((a -> SDoc) -> [a] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map a -> SDoc
forall a. Outputable a => a -> SDoc
ppr [a]
strs)
ppSpaceJoin :: (Outputable a) => [a] -> SDoc
ppSpaceJoin :: [a] -> SDoc
ppSpaceJoin strs :: [a]
strs = [SDoc] -> SDoc
hsep ((a -> SDoc) -> [a] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map a -> SDoc
forall a. Outputable a => a -> SDoc
ppr [a]
strs)