module ByteCodeTypes
( CompiledByteCode(..), FFIInfo(..)
, UnlinkedBCO(..), BCOPtr(..), BCONPtr(..)
, ItblEnv, ItblPtr(..)
, CgBreakInfo(..)
, ModBreaks (..), BreakIndex, emptyModBreaks
, CCostCentre
) where
import FastString
import Id
import Name
import NameEnv
import Outputable
import PrimOp
import SizedSeq
import Type
import SrcLoc
import GHCi.BreakArray
import GHCi.RemoteTypes
import GHCi.FFI
import GHCi.InfoTable
import Foreign
import Data.Array
import Data.Array.Base ( UArray(..) )
import Data.ByteString (ByteString)
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import GHC.Stack.CCS
data CompiledByteCode = CompiledByteCode
{ bc_bcos :: [UnlinkedBCO]
, bc_itbls :: ItblEnv
, bc_ffis :: [FFIInfo]
, bc_strs :: [RemotePtr ()]
, bc_breaks :: Maybe ModBreaks
}
newtype FFIInfo = FFIInfo (RemotePtr C_ffi_cif)
deriving Show
instance Outputable CompiledByteCode where
ppr CompiledByteCode{..} = ppr bc_bcos
type ItblEnv = NameEnv (Name, ItblPtr)
newtype ItblPtr = ItblPtr (RemotePtr StgInfoTable) deriving Show
data UnlinkedBCO
= UnlinkedBCO {
unlinkedBCOName :: Name,
unlinkedBCOArity :: Int,
unlinkedBCOInstrs :: UArray Int Word16,
unlinkedBCOBitmap :: UArray Int Word,
unlinkedBCOLits :: (SizedSeq BCONPtr),
unlinkedBCOPtrs :: (SizedSeq BCOPtr)
}
data BCOPtr
= BCOPtrName Name
| BCOPtrPrimOp PrimOp
| BCOPtrBCO UnlinkedBCO
| BCOPtrBreakArray
data BCONPtr
= BCONPtrWord Word
| BCONPtrLbl FastString
| BCONPtrItbl Name
| BCONPtrStr ByteString
data CgBreakInfo
= CgBreakInfo
{ cgb_vars :: [(Id,Word16)]
, cgb_resty :: Type
}
instance Outputable UnlinkedBCO where
ppr (UnlinkedBCO nm _arity _insns _bitmap lits ptrs)
= sep [text "BCO", ppr nm, text "with",
ppr (sizeSS lits), text "lits",
ppr (sizeSS ptrs), text "ptrs" ]
instance Outputable CgBreakInfo where
ppr info = text "CgBreakInfo" <+>
parens (ppr (cgb_vars info) <+>
ppr (cgb_resty info))
type BreakIndex = Int
data CCostCentre
data ModBreaks
= ModBreaks
{ modBreaks_flags :: ForeignRef BreakArray
, modBreaks_locs :: !(Array BreakIndex SrcSpan)
, modBreaks_vars :: !(Array BreakIndex [OccName])
, modBreaks_decls :: !(Array BreakIndex [String])
, modBreaks_ccs :: !(Array BreakIndex (RemotePtr CostCentre))
, modBreaks_breakInfo :: IntMap CgBreakInfo
}
emptyModBreaks :: ModBreaks
emptyModBreaks = ModBreaks
{ modBreaks_flags = error "ModBreaks.modBreaks_array not initialised"
, modBreaks_locs = array (0,1) []
, modBreaks_vars = array (0,1) []
, modBreaks_decls = array (0,1) []
, modBreaks_ccs = array (0,1) []
, modBreaks_breakInfo = IntMap.empty
}