{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE UndecidableInstances #-}
module GHC.Stg.Syntax (
StgArg(..),
GenStgTopBinding(..), GenStgBinding(..), GenStgExpr(..), GenStgRhs(..),
GenStgAlt(..), AltType(..),
StgPass(..), BinderP, XRhsClosure, XLet, XLetNoEscape,
NoExtFieldSilent, noExtFieldSilent,
OutputablePass,
UpdateFlag(..), isUpdatable,
ConstructorNumber(..),
StgTopBinding, StgBinding, StgExpr, StgRhs, StgAlt,
CgStgTopBinding, CgStgBinding, CgStgExpr, CgStgRhs, CgStgAlt,
TgStgTopBinding, TgStgBinding, TgStgExpr, TgStgRhs, TgStgAlt,
LlStgTopBinding, LlStgBinding, LlStgExpr, LlStgRhs, LlStgAlt,
InStgArg, InStgTopBinding, InStgBinding, InStgExpr, InStgRhs, InStgAlt,
OutStgArg, OutStgTopBinding, OutStgBinding, OutStgExpr, OutStgRhs, OutStgAlt,
StgOp(..),
stgRhsArity, freeVarsOfRhs,
isDllConApp,
stgArgType,
stgCaseBndrInScope,
StgPprOpts(..),
panicStgPprOpts, shortStgPprOpts,
pprStgArg, pprStgExpr, pprStgRhs, pprStgBinding, pprStgAlt,
pprGenStgTopBinding, pprStgTopBinding,
pprGenStgTopBindings, pprStgTopBindings
) where
import GHC.Prelude
import GHC.Core ( AltCon )
import GHC.Types.CostCentre ( CostCentreStack )
import Data.ByteString ( ByteString )
import Data.Data ( Data )
import Data.List ( intersperse )
import GHC.Core.DataCon
import GHC.Types.ForeignCall ( ForeignCall )
import GHC.Types.Id
import GHC.Types.Name ( isDynLinkName )
import GHC.Types.Tickish ( StgTickish )
import GHC.Types.Var.Set
import GHC.Types.Literal ( Literal, literalType )
import GHC.Unit.Module ( Module )
import GHC.Utils.Outputable
import GHC.Platform
import GHC.Core.Ppr( )
import GHC.Builtin.PrimOps ( PrimOp, PrimCall )
import GHC.Core.TyCon ( PrimRep(..), TyCon )
import GHC.Core.Type ( Type )
import GHC.Types.RepType ( typePrimRep1, typePrimRep )
import GHC.Utils.Panic.Plain
data GenStgTopBinding pass
= StgTopLifted (GenStgBinding pass)
| StgTopStringLit Id ByteString
data GenStgBinding pass
= StgNonRec (BinderP pass) (GenStgRhs pass)
| StgRec [(BinderP pass, GenStgRhs pass)]
data StgArg
= StgVarArg Id
| StgLitArg Literal
isDllConApp
:: Platform
-> Bool
-> Module
-> DataCon
-> [StgArg]
-> Bool
isDllConApp :: Platform -> Bool -> Module -> DataCon -> [StgArg] -> Bool
isDllConApp Platform
platform Bool
ext_dyn_refs Module
this_mod DataCon
con [StgArg]
args
| Bool -> Bool
not Bool
ext_dyn_refs = Bool
False
| Platform -> OS
platformOS Platform
platform forall a. Eq a => a -> a -> Bool
== OS
OSMinGW32
= Platform -> Module -> Name -> Bool
isDynLinkName Platform
platform Module
this_mod (DataCon -> Name
dataConName DataCon
con) Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any StgArg -> Bool
is_dll_arg [StgArg]
args
| Bool
otherwise = Bool
False
where
is_dll_arg :: StgArg -> Bool
is_dll_arg :: StgArg -> Bool
is_dll_arg (StgVarArg Id
v) = PrimRep -> Bool
isAddrRep (HasDebugCallStack => UnaryType -> PrimRep
typePrimRep1 (Id -> UnaryType
idType Id
v))
Bool -> Bool -> Bool
&& Platform -> Module -> Name -> Bool
isDynLinkName Platform
platform Module
this_mod (Id -> Name
idName Id
v)
is_dll_arg StgArg
_ = Bool
False
isAddrRep :: PrimRep -> Bool
isAddrRep :: PrimRep -> Bool
isAddrRep PrimRep
AddrRep = Bool
True
isAddrRep PrimRep
LiftedRep = Bool
True
isAddrRep PrimRep
UnliftedRep = Bool
True
isAddrRep PrimRep
_ = Bool
False
stgArgType :: StgArg -> Type
stgArgType :: StgArg -> UnaryType
stgArgType (StgVarArg Id
v) = Id -> UnaryType
idType Id
v
stgArgType (StgLitArg Literal
lit) = Literal -> UnaryType
literalType Literal
lit
stgCaseBndrInScope :: AltType -> Bool -> Bool
stgCaseBndrInScope :: AltType -> Bool -> Bool
stgCaseBndrInScope AltType
alt_ty Bool
unarised =
case AltType
alt_ty of
AlgAlt TyCon
_ -> Bool
True
PrimAlt PrimRep
_ -> Bool
True
MultiValAlt Int
_ -> Bool -> Bool
not Bool
unarised
AltType
PolyAlt -> Bool
True
data GenStgExpr pass
= StgApp
Id
[StgArg]
| StgLit Literal
| StgConApp DataCon
ConstructorNumber
[StgArg]
[Type]
| StgOpApp StgOp
[StgArg]
Type
| StgCase
(GenStgExpr pass)
(BinderP pass)
AltType
[GenStgAlt pass]
| StgLet
(XLet pass)
(GenStgBinding pass)
(GenStgExpr pass)
| StgLetNoEscape
(XLetNoEscape pass)
(GenStgBinding pass)
(GenStgExpr pass)
| StgTick
StgTickish
(GenStgExpr pass)
data GenStgRhs pass
= StgRhsClosure
(XRhsClosure pass)
CostCentreStack
!UpdateFlag
[BinderP pass]
(GenStgExpr pass)
| StgRhsCon
CostCentreStack
DataCon
ConstructorNumber
[StgTickish]
[StgArg]
data NoExtFieldSilent = NoExtFieldSilent
deriving (Typeable NoExtFieldSilent
NoExtFieldSilent -> DataType
NoExtFieldSilent -> Constr
(forall b. Data b => b -> b)
-> NoExtFieldSilent -> NoExtFieldSilent
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> NoExtFieldSilent -> u
forall u. (forall d. Data d => d -> u) -> NoExtFieldSilent -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NoExtFieldSilent -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NoExtFieldSilent -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NoExtFieldSilent
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NoExtFieldSilent -> c NoExtFieldSilent
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NoExtFieldSilent)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NoExtFieldSilent)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> NoExtFieldSilent -> m NoExtFieldSilent
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> NoExtFieldSilent -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> NoExtFieldSilent -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> NoExtFieldSilent -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NoExtFieldSilent -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NoExtFieldSilent -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NoExtFieldSilent -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NoExtFieldSilent -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NoExtFieldSilent -> r
gmapT :: (forall b. Data b => b -> b)
-> NoExtFieldSilent -> NoExtFieldSilent
$cgmapT :: (forall b. Data b => b -> b)
-> NoExtFieldSilent -> NoExtFieldSilent
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NoExtFieldSilent)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NoExtFieldSilent)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NoExtFieldSilent)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NoExtFieldSilent)
dataTypeOf :: NoExtFieldSilent -> DataType
$cdataTypeOf :: NoExtFieldSilent -> DataType
toConstr :: NoExtFieldSilent -> Constr
$ctoConstr :: NoExtFieldSilent -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NoExtFieldSilent
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NoExtFieldSilent
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NoExtFieldSilent -> c NoExtFieldSilent
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NoExtFieldSilent -> c NoExtFieldSilent
Data, NoExtFieldSilent -> NoExtFieldSilent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
$c/= :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
== :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
$c== :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
Eq, Eq NoExtFieldSilent
NoExtFieldSilent -> NoExtFieldSilent -> Bool
NoExtFieldSilent -> NoExtFieldSilent -> Ordering
NoExtFieldSilent -> NoExtFieldSilent -> NoExtFieldSilent
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 :: NoExtFieldSilent -> NoExtFieldSilent -> NoExtFieldSilent
$cmin :: NoExtFieldSilent -> NoExtFieldSilent -> NoExtFieldSilent
max :: NoExtFieldSilent -> NoExtFieldSilent -> NoExtFieldSilent
$cmax :: NoExtFieldSilent -> NoExtFieldSilent -> NoExtFieldSilent
>= :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
$c>= :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
> :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
$c> :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
<= :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
$c<= :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
< :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
$c< :: NoExtFieldSilent -> NoExtFieldSilent -> Bool
compare :: NoExtFieldSilent -> NoExtFieldSilent -> Ordering
$ccompare :: NoExtFieldSilent -> NoExtFieldSilent -> Ordering
Ord)
instance Outputable NoExtFieldSilent where
ppr :: NoExtFieldSilent -> SDoc
ppr NoExtFieldSilent
_ = forall doc. IsOutput doc => doc
empty
noExtFieldSilent :: NoExtFieldSilent
noExtFieldSilent :: NoExtFieldSilent
noExtFieldSilent = NoExtFieldSilent
NoExtFieldSilent
stgRhsArity :: StgRhs -> Int
stgRhsArity :: StgRhs -> Int
stgRhsArity (StgRhsClosure XRhsClosure 'Vanilla
_ CostCentreStack
_ UpdateFlag
_ [BinderP 'Vanilla]
bndrs GenStgExpr 'Vanilla
_)
= forall a. HasCallStack => Bool -> a -> a
assert (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Id -> Bool
isId [BinderP 'Vanilla]
bndrs) forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length [BinderP 'Vanilla]
bndrs
stgRhsArity (StgRhsCon {}) = Int
0
freeVarsOfRhs :: (XRhsClosure pass ~ DIdSet) => GenStgRhs pass -> DIdSet
freeVarsOfRhs :: forall (pass :: StgPass).
(XRhsClosure pass ~ DIdSet) =>
GenStgRhs pass -> DIdSet
freeVarsOfRhs (StgRhsCon CostCentreStack
_ DataCon
_ ConstructorNumber
_ [StgTickish]
_ [StgArg]
args) = [Id] -> DIdSet
mkDVarSet [ Id
id | StgVarArg Id
id <- [StgArg]
args ]
freeVarsOfRhs (StgRhsClosure XRhsClosure pass
fvs CostCentreStack
_ UpdateFlag
_ [BinderP pass]
_ GenStgExpr pass
_) = XRhsClosure pass
fvs
data GenStgAlt pass = GenStgAlt
{ forall (pass :: StgPass). GenStgAlt pass -> AltCon
alt_con :: !AltCon
, forall (pass :: StgPass). GenStgAlt pass -> [BinderP pass]
alt_bndrs :: ![BinderP pass]
, forall (pass :: StgPass). GenStgAlt pass -> GenStgExpr pass
alt_rhs :: !(GenStgExpr pass)
}
data AltType
= PolyAlt
| MultiValAlt Int
| AlgAlt TyCon
| PrimAlt PrimRep
type StgTopBinding = GenStgTopBinding 'Vanilla
type StgBinding = GenStgBinding 'Vanilla
type StgExpr = GenStgExpr 'Vanilla
type StgRhs = GenStgRhs 'Vanilla
type StgAlt = GenStgAlt 'Vanilla
type LlStgTopBinding = GenStgTopBinding 'LiftLams
type LlStgBinding = GenStgBinding 'LiftLams
type LlStgExpr = GenStgExpr 'LiftLams
type LlStgRhs = GenStgRhs 'LiftLams
type LlStgAlt = GenStgAlt 'LiftLams
type CgStgTopBinding = GenStgTopBinding 'CodeGen
type CgStgBinding = GenStgBinding 'CodeGen
type CgStgExpr = GenStgExpr 'CodeGen
type CgStgRhs = GenStgRhs 'CodeGen
type CgStgAlt = GenStgAlt 'CodeGen
type TgStgTopBinding = GenStgTopBinding 'CodeGen
type TgStgBinding = GenStgBinding 'CodeGen
type TgStgExpr = GenStgExpr 'CodeGen
type TgStgRhs = GenStgRhs 'CodeGen
type TgStgAlt = GenStgAlt 'CodeGen
type InStgTopBinding = StgTopBinding
type InStgBinding = StgBinding
type InStgArg = StgArg
type InStgExpr = StgExpr
type InStgRhs = StgRhs
type InStgAlt = StgAlt
type OutStgTopBinding = StgTopBinding
type OutStgBinding = StgBinding
type OutStgArg = StgArg
type OutStgExpr = StgExpr
type OutStgRhs = StgRhs
type OutStgAlt = StgAlt
data ConstructorNumber =
NoNumber | Numbered Int
instance Outputable ConstructorNumber where
ppr :: ConstructorNumber -> SDoc
ppr ConstructorNumber
NoNumber = forall doc. IsOutput doc => doc
empty
ppr (Numbered Int
n) = forall doc. IsLine doc => String -> doc
text String
"#" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr Int
n
data StgPass
= Vanilla
| LiftLams
| InferTaggedBinders
| InferTagged
| CodeGen
type family BinderP (pass :: StgPass)
type instance BinderP 'Vanilla = Id
type instance BinderP 'CodeGen = Id
type instance BinderP 'InferTagged = Id
type family XRhsClosure (pass :: StgPass)
type instance XRhsClosure 'Vanilla = NoExtFieldSilent
type instance XRhsClosure 'InferTagged = NoExtFieldSilent
type instance XRhsClosure 'CodeGen = DIdSet
type family XLet (pass :: StgPass)
type instance XLet 'Vanilla = NoExtFieldSilent
type instance XLet 'InferTagged = NoExtFieldSilent
type instance XLet 'CodeGen = NoExtFieldSilent
type family XLetNoEscape (pass :: StgPass)
type instance XLetNoEscape 'Vanilla = NoExtFieldSilent
type instance XLetNoEscape 'InferTagged = NoExtFieldSilent
type instance XLetNoEscape 'CodeGen = NoExtFieldSilent
data UpdateFlag = ReEntrant | Updatable | SingleEntry
instance Outputable UpdateFlag where
ppr :: UpdateFlag -> SDoc
ppr UpdateFlag
u = forall doc. IsLine doc => Char -> doc
char forall a b. (a -> b) -> a -> b
$ case UpdateFlag
u of
UpdateFlag
ReEntrant -> Char
'r'
UpdateFlag
Updatable -> Char
'u'
UpdateFlag
SingleEntry -> Char
's'
isUpdatable :: UpdateFlag -> Bool
isUpdatable :: UpdateFlag -> Bool
isUpdatable UpdateFlag
ReEntrant = Bool
False
isUpdatable UpdateFlag
SingleEntry = Bool
False
isUpdatable UpdateFlag
Updatable = Bool
True
data StgOp
= StgPrimOp PrimOp
| StgPrimCallOp PrimCall
| StgFCallOp ForeignCall Type
type OutputablePass pass =
( Outputable (XLet pass)
, Outputable (XLetNoEscape pass)
, Outputable (XRhsClosure pass)
, OutputableBndr (BinderP pass)
)
data StgPprOpts = StgPprOpts
{ StgPprOpts -> Bool
stgSccEnabled :: !Bool
}
panicStgPprOpts :: StgPprOpts
panicStgPprOpts :: StgPprOpts
panicStgPprOpts = StgPprOpts
{ stgSccEnabled :: Bool
stgSccEnabled = Bool
True
}
shortStgPprOpts :: StgPprOpts
shortStgPprOpts :: StgPprOpts
shortStgPprOpts = StgPprOpts
{ stgSccEnabled :: Bool
stgSccEnabled = Bool
False
}
pprGenStgTopBinding
:: OutputablePass pass => StgPprOpts -> GenStgTopBinding pass -> SDoc
pprGenStgTopBinding :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgTopBinding pass -> SDoc
pprGenStgTopBinding StgPprOpts
opts GenStgTopBinding pass
b = case GenStgTopBinding pass
b of
StgTopStringLit Id
bndr ByteString
str -> SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => [doc] -> doc
hsep [forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
LetBind Id
bndr, forall doc. IsLine doc => doc
equals]) Int
4 (ByteString -> SDoc
pprHsBytes ByteString
str forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
semi)
StgTopLifted GenStgBinding pass
bind -> forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding StgPprOpts
opts GenStgBinding pass
bind
pprGenStgBinding :: OutputablePass pass => StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding StgPprOpts
opts GenStgBinding pass
b = case GenStgBinding pass
b of
StgNonRec BinderP pass
bndr GenStgRhs pass
rhs -> SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => [doc] -> doc
hsep [forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
LetBind BinderP pass
bndr, forall doc. IsLine doc => doc
equals]) Int
4 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgRhs pass -> SDoc
pprStgRhs StgPprOpts
opts GenStgRhs pass
rhs forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
semi)
StgRec [(BinderP pass, GenStgRhs pass)]
pairs -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"Rec {"
, forall doc. IsDoc doc => [doc] -> doc
vcat (forall a. a -> [a] -> [a]
intersperse SDoc
blankLine (forall a b. (a -> b) -> [a] -> [b]
map (BinderP pass, GenStgRhs pass) -> SDoc
ppr_bind [(BinderP pass, GenStgRhs pass)]
pairs))
, forall doc. IsLine doc => String -> doc
text String
"end Rec }" ]
where
ppr_bind :: (BinderP pass, GenStgRhs pass) -> SDoc
ppr_bind (BinderP pass
bndr, GenStgRhs pass
expr)
= SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => [doc] -> doc
hsep [forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
LetBind BinderP pass
bndr, forall doc. IsLine doc => doc
equals])
Int
4 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgRhs pass -> SDoc
pprStgRhs StgPprOpts
opts GenStgRhs pass
expr forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
semi)
instance OutputablePass pass => Outputable (GenStgBinding pass) where
ppr :: GenStgBinding pass -> SDoc
ppr = forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding StgPprOpts
panicStgPprOpts
pprGenStgTopBindings :: (OutputablePass pass) => StgPprOpts -> [GenStgTopBinding pass] -> SDoc
pprGenStgTopBindings :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> [GenStgTopBinding pass] -> SDoc
pprGenStgTopBindings StgPprOpts
opts [GenStgTopBinding pass]
binds
= forall doc. IsDoc doc => [doc] -> doc
vcat forall a b. (a -> b) -> a -> b
$ forall a. a -> [a] -> [a]
intersperse SDoc
blankLine (forall a b. (a -> b) -> [a] -> [b]
map (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgTopBinding pass -> SDoc
pprGenStgTopBinding StgPprOpts
opts) [GenStgTopBinding pass]
binds)
pprStgBinding :: OutputablePass pass => StgPprOpts -> GenStgBinding pass -> SDoc
pprStgBinding :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprStgBinding = forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding
pprStgTopBinding :: OutputablePass pass => StgPprOpts -> GenStgTopBinding pass -> SDoc
pprStgTopBinding :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgTopBinding pass -> SDoc
pprStgTopBinding = forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgTopBinding pass -> SDoc
pprGenStgTopBinding
pprStgTopBindings :: OutputablePass pass => StgPprOpts -> [GenStgTopBinding pass] -> SDoc
pprStgTopBindings :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> [GenStgTopBinding pass] -> SDoc
pprStgTopBindings = forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> [GenStgTopBinding pass] -> SDoc
pprGenStgTopBindings
pprIdWithRep :: Id -> SDoc
pprIdWithRep :: Id -> SDoc
pprIdWithRep Id
v = forall a. Outputable a => a -> SDoc
ppr Id
v forall doc. IsLine doc => doc -> doc -> doc
<> UnaryType -> SDoc
pprTypeRep (Id -> UnaryType
idType Id
v)
pprTypeRep :: Type -> SDoc
pprTypeRep :: UnaryType -> SDoc
pprTypeRep UnaryType
ty =
forall doc. IsLine doc => (SDocContext -> Bool) -> doc -> doc
ppUnlessOption SDocContext -> Bool
sdocSuppressStgReps forall a b. (a -> b) -> a -> b
$
forall doc. IsLine doc => Char -> doc
char Char
':' forall doc. IsLine doc => doc -> doc -> doc
<> case HasDebugCallStack => UnaryType -> [PrimRep]
typePrimRep UnaryType
ty of
[PrimRep
r] -> forall a. Outputable a => a -> SDoc
ppr PrimRep
r
[PrimRep]
r -> forall a. Outputable a => a -> SDoc
ppr [PrimRep]
r
instance Outputable StgArg where
ppr :: StgArg -> SDoc
ppr = StgArg -> SDoc
pprStgArg
pprStgArg :: StgArg -> SDoc
pprStgArg :: StgArg -> SDoc
pprStgArg (StgVarArg Id
var) = Id -> SDoc
pprIdWithRep Id
var
pprStgArg (StgLitArg Literal
con) = forall a. Outputable a => a -> SDoc
ppr Literal
con forall doc. IsLine doc => doc -> doc -> doc
<> UnaryType -> SDoc
pprTypeRep (Literal -> UnaryType
literalType Literal
con)
instance OutputablePass pass => Outputable (GenStgExpr pass) where
ppr :: GenStgExpr pass -> SDoc
ppr = forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
panicStgPprOpts
pprStgExpr :: OutputablePass pass => StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
e = case GenStgExpr pass
e of
StgLit Literal
lit -> forall a. Outputable a => a -> SDoc
ppr Literal
lit
StgApp Id
func [StgArg]
args
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [StgArg]
args
, Just TagSig
sig <- Id -> Maybe TagSig
idTagSig_maybe Id
func
-> forall a. Outputable a => a -> SDoc
ppr Id
func forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr TagSig
sig
| Bool
otherwise -> SDoc -> Int -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr Id
func) Int
4 (forall a. Outputable a => [a] -> SDoc
interppSP [StgArg]
args)
StgConApp DataCon
con ConstructorNumber
n [StgArg]
args [UnaryType]
_ -> forall doc. IsLine doc => [doc] -> doc
hsep [ forall a. Outputable a => a -> SDoc
ppr DataCon
con, forall a. Outputable a => a -> SDoc
ppr ConstructorNumber
n, forall doc. IsLine doc => doc -> doc
brackets (forall a. Outputable a => [a] -> SDoc
interppSP [StgArg]
args) ]
StgOpApp StgOp
op [StgArg]
args UnaryType
_ -> forall doc. IsLine doc => [doc] -> doc
hsep [ StgOp -> SDoc
pprStgOp StgOp
op, forall doc. IsLine doc => doc -> doc
brackets (forall a. Outputable a => [a] -> SDoc
interppSP [StgArg]
args)]
StgLet XLet pass
ext GenStgBinding pass
bind expr :: GenStgExpr pass
expr@StgLet{} -> forall doc. IsDoc doc => doc -> doc -> doc
($$)
(forall doc. IsLine doc => [doc] -> doc
sep [SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"let" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr XLet pass
ext forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"{")
Int
2 (forall doc. IsLine doc => [doc] -> doc
hsep [forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding StgPprOpts
opts GenStgBinding pass
bind, forall doc. IsLine doc => String -> doc
text String
"} in"])])
(forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
expr)
StgLet XLet pass
ext GenStgBinding pass
bind GenStgExpr pass
expr
-> forall doc. IsLine doc => [doc] -> doc
sep [ SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"let" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr XLet pass
ext forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"{")
Int
2 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding StgPprOpts
opts GenStgBinding pass
bind)
, SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"} in ") Int
2 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
expr)
]
StgLetNoEscape XLetNoEscape pass
ext GenStgBinding pass
bind GenStgExpr pass
expr
-> forall doc. IsLine doc => [doc] -> doc
sep [ SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"let-no-escape" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr XLetNoEscape pass
ext forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"{")
Int
2 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgBinding pass -> SDoc
pprGenStgBinding StgPprOpts
opts GenStgBinding pass
bind)
, SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"} in ") Int
2 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
expr)
]
StgTick StgTickish
_tickish GenStgExpr pass
expr -> forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocSuppressTicks forall a b. (a -> b) -> a -> b
$ \case
Bool
True -> forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
expr
Bool
False -> forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
expr
StgCase GenStgExpr pass
expr BinderP pass
bndr AltType
alt_type [GenStgAlt pass
alt]
-> forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"case"
, Int -> SDoc -> SDoc
nest Int
4 (forall doc. IsLine doc => [doc] -> doc
hsep [ forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
expr
, forall doc. IsOutput doc => doc -> doc
whenPprDebug (SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr AltType
alt_type)
])
, forall doc. IsLine doc => String -> doc
text String
"of"
, forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
CaseBind BinderP pass
bndr
, forall doc. IsLine doc => Char -> doc
char Char
'{'
]
, forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> Bool -> GenStgAlt pass -> SDoc
pprStgAlt StgPprOpts
opts Bool
False GenStgAlt pass
alt
, forall doc. IsLine doc => Char -> doc
char Char
'}'
]
StgCase GenStgExpr pass
expr BinderP pass
bndr AltType
alt_type [GenStgAlt pass]
alts
-> forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"case"
, Int -> SDoc -> SDoc
nest Int
4 (forall doc. IsLine doc => [doc] -> doc
hsep [ forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
expr
, forall doc. IsOutput doc => doc -> doc
whenPprDebug (SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr AltType
alt_type)
])
, forall doc. IsLine doc => String -> doc
text String
"of"
, forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
CaseBind BinderP pass
bndr, forall doc. IsLine doc => Char -> doc
char Char
'{'
]
, Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsDoc doc => [doc] -> doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> Bool -> GenStgAlt pass -> SDoc
pprStgAlt StgPprOpts
opts Bool
True) [GenStgAlt pass]
alts))
, forall doc. IsLine doc => Char -> doc
char Char
'}'
]
pprStgAlt :: OutputablePass pass => StgPprOpts -> Bool -> GenStgAlt pass -> SDoc
pprStgAlt :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> Bool -> GenStgAlt pass -> SDoc
pprStgAlt StgPprOpts
opts Bool
indent GenStgAlt{AltCon
alt_con :: AltCon
alt_con :: forall (pass :: StgPass). GenStgAlt pass -> AltCon
alt_con, [BinderP pass]
alt_bndrs :: [BinderP pass]
alt_bndrs :: forall (pass :: StgPass). GenStgAlt pass -> [BinderP pass]
alt_bndrs, GenStgExpr pass
alt_rhs :: GenStgExpr pass
alt_rhs :: forall (pass :: StgPass). GenStgAlt pass -> GenStgExpr pass
alt_rhs}
| Bool
indent = SDoc -> Int -> SDoc -> SDoc
hang SDoc
altPattern Int
4 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
alt_rhs forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
semi)
| Bool
otherwise = forall doc. IsLine doc => [doc] -> doc
sep [SDoc
altPattern, forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
alt_rhs forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
semi]
where
altPattern :: SDoc
altPattern = forall doc. IsLine doc => [doc] -> doc
hsep [ forall a. Outputable a => a -> SDoc
ppr AltCon
alt_con
, forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
CasePatBind) [BinderP pass]
alt_bndrs)
, forall doc. IsLine doc => String -> doc
text String
"->"
]
pprStgOp :: StgOp -> SDoc
pprStgOp :: StgOp -> SDoc
pprStgOp (StgPrimOp PrimOp
op) = forall a. Outputable a => a -> SDoc
ppr PrimOp
op
pprStgOp (StgPrimCallOp PrimCall
op)= forall a. Outputable a => a -> SDoc
ppr PrimCall
op
pprStgOp (StgFCallOp ForeignCall
op UnaryType
_) = forall a. Outputable a => a -> SDoc
ppr ForeignCall
op
instance Outputable StgOp where
ppr :: StgOp -> SDoc
ppr = StgOp -> SDoc
pprStgOp
instance Outputable AltType where
ppr :: AltType -> SDoc
ppr AltType
PolyAlt = forall doc. IsLine doc => String -> doc
text String
"Polymorphic"
ppr (MultiValAlt Int
n) = forall doc. IsLine doc => String -> doc
text String
"MultiAlt" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Int
n
ppr (AlgAlt TyCon
tc) = forall doc. IsLine doc => String -> doc
text String
"Alg" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr TyCon
tc
ppr (PrimAlt PrimRep
tc) = forall doc. IsLine doc => String -> doc
text String
"Prim" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr PrimRep
tc
pprStgRhs :: OutputablePass pass => StgPprOpts -> GenStgRhs pass -> SDoc
pprStgRhs :: forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgRhs pass -> SDoc
pprStgRhs StgPprOpts
opts GenStgRhs pass
rhs = case GenStgRhs pass
rhs of
StgRhsClosure XRhsClosure pass
ext CostCentreStack
cc UpdateFlag
upd_flag [BinderP pass]
args GenStgExpr pass
body
-> SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => [doc] -> doc
hsep [ if StgPprOpts -> Bool
stgSccEnabled StgPprOpts
opts then forall a. Outputable a => a -> SDoc
ppr CostCentreStack
cc else forall doc. IsOutput doc => doc
empty
, forall doc. IsLine doc => (SDocContext -> Bool) -> doc -> doc
ppUnlessOption SDocContext -> Bool
sdocSuppressStgExts (forall a. Outputable a => a -> SDoc
ppr XRhsClosure pass
ext)
, forall doc. IsLine doc => Char -> doc
char Char
'\\' forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr UpdateFlag
upd_flag, forall doc. IsLine doc => doc -> doc
brackets (forall a. Outputable a => [a] -> SDoc
interppSP [BinderP pass]
args)
])
Int
4 (forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgExpr pass -> SDoc
pprStgExpr StgPprOpts
opts GenStgExpr pass
body)
StgRhsCon CostCentreStack
cc DataCon
con ConstructorNumber
mid [StgTickish]
_ticks [StgArg]
args
-> forall doc. IsLine doc => [doc] -> doc
hcat [ if StgPprOpts -> Bool
stgSccEnabled StgPprOpts
opts then forall a. Outputable a => a -> SDoc
ppr CostCentreStack
cc forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
space else forall doc. IsOutput doc => doc
empty
, case ConstructorNumber
mid of
ConstructorNumber
NoNumber -> forall doc. IsOutput doc => doc
empty
Numbered Int
n -> forall doc. IsLine doc => [doc] -> doc
hcat [forall a. Outputable a => a -> SDoc
ppr Int
n, forall doc. IsLine doc => doc
space]
, forall a. Outputable a => a -> SDoc
ppr DataCon
con, forall doc. IsLine doc => String -> doc
text String
"! ", forall doc. IsLine doc => doc -> doc
brackets (forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map StgArg -> SDoc
pprStgArg [StgArg]
args))]
instance OutputablePass pass => Outputable (GenStgRhs pass) where
ppr :: GenStgRhs pass -> SDoc
ppr = forall (pass :: StgPass).
OutputablePass pass =>
StgPprOpts -> GenStgRhs pass -> SDoc
pprStgRhs StgPprOpts
panicStgPprOpts