Cheng Shao pushed to branch wip/bytecode-serialize-3 at Glasgow Haskell Compiler / GHC
Commits:
-
1362d5a8
by Cheng Shao at 2025-08-10T13:39:51+00:00
-
fdebadb5
by Cheng Shao at 2025-08-10T13:39:56+00:00
10 changed files:
- compiler/GHC/Builtin/PrimOps.hs
- compiler/GHC/ByteCode/Breakpoints.hs
- + compiler/GHC/ByteCode/Serialize.hs
- compiler/GHC/ByteCode/Types.hs
- compiler/GHC/Data/FlatBag.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Types/SptEntry.hs
- compiler/GHC/Types/Tickish.hs
- compiler/GHC/Utils/Binary.hs
- compiler/ghc.cabal.in
Changes:
| ... | ... | @@ -53,6 +53,7 @@ import GHC.Types.Unique ( Unique ) |
| 53 | 53 | |
| 54 | 54 | import GHC.Unit.Types ( Unit )
|
| 55 | 55 | |
| 56 | +import GHC.Utils.Binary
|
|
| 56 | 57 | import GHC.Utils.Outputable
|
| 57 | 58 | import GHC.Utils.Panic
|
| 58 | 59 | |
| ... | ... | @@ -929,3 +930,8 @@ primOpIsReallyInline = \case |
| 929 | 930 | DataToTagSmallOp -> False
|
| 930 | 931 | DataToTagLargeOp -> False
|
| 931 | 932 | p -> not (primOpOutOfLine p)
|
| 933 | + |
|
| 934 | +instance Binary PrimOp where
|
|
| 935 | + get bh = (allThePrimOps !!) <$> get bh
|
|
| 936 | + |
|
| 937 | + put_ bh = put_ bh . primOpTag |
| ... | ... | @@ -44,6 +44,7 @@ import GHC.HsToCore.Breakpoints |
| 44 | 44 | import GHC.Iface.Syntax
|
| 45 | 45 | |
| 46 | 46 | import GHC.Unit.Module (Module)
|
| 47 | +import GHC.Utils.Binary
|
|
| 47 | 48 | import GHC.Utils.Outputable
|
| 48 | 49 | import GHC.Utils.Panic
|
| 49 | 50 | import Data.Array
|
| ... | ... | @@ -297,3 +298,11 @@ instance Outputable CgBreakInfo where |
| 297 | 298 | parens (ppr (cgb_vars info) <+>
|
| 298 | 299 | ppr (cgb_resty info) <+>
|
| 299 | 300 | ppr (cgb_tick_id info))
|
| 301 | + |
|
| 302 | +deriving newtype instance Binary InternalBreakLoc
|
|
| 303 | + |
|
| 304 | +instance Binary InternalBreakpointId where
|
|
| 305 | + get bh = InternalBreakpointId <$> get bh <*> get bh
|
|
| 306 | + |
|
| 307 | + put_ bh InternalBreakpointId {..} =
|
|
| 308 | + put_ bh ibi_info_mod *> put_ bh ibi_info_index |
| 1 | +{-# LANGUAGE MultiWayIf #-}
|
|
| 2 | +{-# LANGUAGE RecordWildCards #-}
|
|
| 3 | +{-# OPTIONS_GHC -Wno-orphans #-}
|
|
| 4 | + |
|
| 5 | +module GHC.ByteCode.Serialize
|
|
| 6 | + ( testBinByteCode,
|
|
| 7 | + )
|
|
| 8 | +where
|
|
| 9 | + |
|
| 10 | +import Control.Monad
|
|
| 11 | +import Data.Binary qualified as Binary
|
|
| 12 | +import Data.ByteString.Lazy qualified as LBS
|
|
| 13 | +import Data.Foldable
|
|
| 14 | +import Data.IORef
|
|
| 15 | +import Data.Proxy
|
|
| 16 | +import Data.Word
|
|
| 17 | +import GHC.ByteCode.Breakpoints
|
|
| 18 | +import GHC.ByteCode.Types
|
|
| 19 | +import GHC.Data.FastString
|
|
| 20 | +import GHC.Driver.Env
|
|
| 21 | +import GHC.Iface.Binary
|
|
| 22 | +import GHC.Prelude
|
|
| 23 | +import GHC.Types.Name
|
|
| 24 | +import GHC.Types.Name.Cache
|
|
| 25 | +import GHC.Types.SrcLoc
|
|
| 26 | +import GHC.Utils.Binary
|
|
| 27 | +import GHC.Utils.Exception
|
|
| 28 | +import GHC.Utils.TmpFs
|
|
| 29 | +import GHCi.Message
|
|
| 30 | +import System.FilePath
|
|
| 31 | + |
|
| 32 | +testBinByteCode :: HscEnv -> CompiledByteCode -> IO CompiledByteCode
|
|
| 33 | +testBinByteCode hsc_env cbc = withSystemTempDirectory "ghc-bbc" $ \tmpdir -> do
|
|
| 34 | + let f = tmpdir </> "ghc-bbc"
|
|
| 35 | + roundtripBinByteCode hsc_env f cbc
|
|
| 36 | + |
|
| 37 | +roundtripBinByteCode ::
|
|
| 38 | + HscEnv -> FilePath -> CompiledByteCode -> IO CompiledByteCode
|
|
| 39 | +roundtripBinByteCode hsc_env f cbc = do
|
|
| 40 | + writeBinByteCode f cbc
|
|
| 41 | + readBinByteCode hsc_env f
|
|
| 42 | + |
|
| 43 | +readBinByteCode :: HscEnv -> FilePath -> IO CompiledByteCode
|
|
| 44 | +readBinByteCode hsc_env f = do
|
|
| 45 | + bh' <- readBinMem f
|
|
| 46 | + bh <- addSerializableNameReader hsc_env bh'
|
|
| 47 | + getWithUserData (hsc_NC hsc_env) bh
|
|
| 48 | + |
|
| 49 | +writeBinByteCode :: FilePath -> CompiledByteCode -> IO ()
|
|
| 50 | +writeBinByteCode f cbc = do
|
|
| 51 | + bh' <- openBinMem (1024 * 1024)
|
|
| 52 | + bh <- addSerializableNameWriter bh'
|
|
| 53 | + putWithUserData QuietBinIFace NormalCompression bh cbc
|
|
| 54 | + writeBinMem bh f
|
|
| 55 | + |
|
| 56 | +instance Binary CompiledByteCode where
|
|
| 57 | + get bh = do
|
|
| 58 | + bc_bcos <- get bh
|
|
| 59 | + bc_itbls_len <- get bh
|
|
| 60 | + bc_itbls <- replicateM bc_itbls_len $ do
|
|
| 61 | + nm <- getViaSerializableName bh
|
|
| 62 | + itbl <- get bh
|
|
| 63 | + pure (nm, itbl)
|
|
| 64 | + bc_strs_len <- get bh
|
|
| 65 | + bc_strs <-
|
|
| 66 | + replicateM bc_strs_len $ (,) <$> getViaSerializableName bh <*> get bh
|
|
| 67 | + bc_breaks <- get bh
|
|
| 68 | + bc_spt_entries <- get bh
|
|
| 69 | + evaluate
|
|
| 70 | + CompiledByteCode
|
|
| 71 | + { bc_bcos,
|
|
| 72 | + bc_itbls,
|
|
| 73 | + bc_strs,
|
|
| 74 | + bc_breaks,
|
|
| 75 | + bc_spt_entries
|
|
| 76 | + }
|
|
| 77 | + |
|
| 78 | + put_ bh CompiledByteCode {..} = do
|
|
| 79 | + put_ bh bc_bcos
|
|
| 80 | + put_ bh $ length bc_itbls
|
|
| 81 | + for_ bc_itbls $ \(nm, itbl) -> do
|
|
| 82 | + putViaSerializableName bh nm
|
|
| 83 | + put_ bh itbl
|
|
| 84 | + put_ bh $ length bc_strs
|
|
| 85 | + for_ bc_strs $ \(nm, str) -> putViaSerializableName bh nm *> put_ bh str
|
|
| 86 | + put_ bh bc_breaks
|
|
| 87 | + put_ bh bc_spt_entries
|
|
| 88 | + |
|
| 89 | +instance Binary InternalModBreaks where
|
|
| 90 | + get bh = InternalModBreaks <$> get bh <*> get bh
|
|
| 91 | + |
|
| 92 | + put_ bh InternalModBreaks {..} =
|
|
| 93 | + put_ bh imodBreaks_breakInfo *> put_ bh imodBreaks_modBreaks
|
|
| 94 | + |
|
| 95 | +instance Binary ModBreaks where
|
|
| 96 | + get bh = ModBreaks <$> get bh <*> get bh <*> get bh <*> get bh <*> get bh
|
|
| 97 | + |
|
| 98 | + put_ bh ModBreaks {..} =
|
|
| 99 | + put_ bh modBreaks_locs
|
|
| 100 | + *> put_ bh modBreaks_vars
|
|
| 101 | + *> put_ bh modBreaks_decls
|
|
| 102 | + *> put_ bh modBreaks_ccs
|
|
| 103 | + *> put_ bh modBreaks_module
|
|
| 104 | + |
|
| 105 | +instance Binary SrcSpan where
|
|
| 106 | + get bh = unBinSrcSpan <$> get bh
|
|
| 107 | + |
|
| 108 | + put_ bh = put_ bh . BinSrcSpan
|
|
| 109 | + |
|
| 110 | +instance Binary CgBreakInfo where
|
|
| 111 | + put_ bh CgBreakInfo {..} =
|
|
| 112 | + put_ bh cgb_tyvars
|
|
| 113 | + *> put_ bh cgb_vars
|
|
| 114 | + *> put_ bh cgb_resty
|
|
| 115 | + *> put_ bh cgb_tick_id
|
|
| 116 | + |
|
| 117 | + get bh = CgBreakInfo <$> get bh <*> get bh <*> get bh <*> get bh
|
|
| 118 | + |
|
| 119 | +instance Binary ConInfoTable where
|
|
| 120 | + get bh = Binary.decode . LBS.fromStrict <$> get bh
|
|
| 121 | + |
|
| 122 | + put_ bh = put_ bh . LBS.toStrict . Binary.encode
|
|
| 123 | + |
|
| 124 | +instance Binary UnlinkedBCO where
|
|
| 125 | + get bh =
|
|
| 126 | + UnlinkedBCO
|
|
| 127 | + <$> getViaSerializableName bh
|
|
| 128 | + <*> get bh
|
|
| 129 | + <*> (Binary.decode . LBS.fromStrict <$> get bh)
|
|
| 130 | + <*> (Binary.decode . LBS.fromStrict <$> get bh)
|
|
| 131 | + <*> get bh
|
|
| 132 | + <*> get bh
|
|
| 133 | + |
|
| 134 | + put_ bh UnlinkedBCO {..} = do
|
|
| 135 | + putViaSerializableName bh unlinkedBCOName
|
|
| 136 | + put_ bh unlinkedBCOArity
|
|
| 137 | + put_ bh $ LBS.toStrict $ Binary.encode unlinkedBCOInstrs
|
|
| 138 | + put_ bh $ LBS.toStrict $ Binary.encode unlinkedBCOBitmap
|
|
| 139 | + put_ bh unlinkedBCOLits
|
|
| 140 | + put_ bh unlinkedBCOPtrs
|
|
| 141 | + |
|
| 142 | +instance Binary BCOPtr where
|
|
| 143 | + get bh = do
|
|
| 144 | + t <- getByte bh
|
|
| 145 | + case t of
|
|
| 146 | + 0 -> BCOPtrName <$> getViaSerializableName bh
|
|
| 147 | + 1 -> BCOPtrPrimOp <$> get bh
|
|
| 148 | + 2 -> BCOPtrBCO <$> get bh
|
|
| 149 | + _ -> BCOPtrBreakArray <$> get bh
|
|
| 150 | + |
|
| 151 | + put_ bh ptr = case ptr of
|
|
| 152 | + BCOPtrName nm -> putByte bh 0 *> putViaSerializableName bh nm
|
|
| 153 | + BCOPtrPrimOp op -> putByte bh 1 *> put_ bh op
|
|
| 154 | + BCOPtrBCO bco -> putByte bh 2 *> put_ bh bco
|
|
| 155 | + BCOPtrBreakArray info_mod -> putByte bh 3 *> put_ bh info_mod
|
|
| 156 | + |
|
| 157 | +instance Binary BCONPtr where
|
|
| 158 | + get bh = do
|
|
| 159 | + t <- getByte bh
|
|
| 160 | + case t of
|
|
| 161 | + 0 -> BCONPtrWord . fromIntegral <$> (get bh :: IO Word64)
|
|
| 162 | + 1 -> BCONPtrLbl <$> get bh
|
|
| 163 | + 2 -> BCONPtrItbl <$> getViaSerializableName bh
|
|
| 164 | + 3 -> BCONPtrAddr <$> getViaSerializableName bh
|
|
| 165 | + 4 -> BCONPtrStr <$> get bh
|
|
| 166 | + 5 -> BCONPtrFS <$> get bh
|
|
| 167 | + 6 -> BCONPtrFFIInfo <$> get bh
|
|
| 168 | + _ -> BCONPtrCostCentre <$> get bh
|
|
| 169 | + |
|
| 170 | + put_ bh ptr = case ptr of
|
|
| 171 | + BCONPtrWord lit -> putByte bh 0 *> put_ bh (fromIntegral lit :: Word64)
|
|
| 172 | + BCONPtrLbl sym -> putByte bh 1 *> put_ bh sym
|
|
| 173 | + BCONPtrItbl nm -> putByte bh 2 *> putViaSerializableName bh nm
|
|
| 174 | + BCONPtrAddr nm -> putByte bh 3 *> putViaSerializableName bh nm
|
|
| 175 | + BCONPtrStr str -> putByte bh 4 *> put_ bh str
|
|
| 176 | + BCONPtrFS fs -> putByte bh 5 *> put_ bh fs
|
|
| 177 | + BCONPtrFFIInfo ffi -> putByte bh 6 *> put_ bh ffi
|
|
| 178 | + BCONPtrCostCentre ibi -> putByte bh 7 *> put_ bh ibi
|
|
| 179 | + |
|
| 180 | +newtype SerializableName = SerializableName {unSerializableName :: Name}
|
|
| 181 | + |
|
| 182 | +getViaSerializableName :: ReadBinHandle -> IO Name
|
|
| 183 | +getViaSerializableName bh = case findUserDataReader Proxy bh of
|
|
| 184 | + BinaryReader f -> unSerializableName <$> f bh
|
|
| 185 | + |
|
| 186 | +putViaSerializableName :: WriteBinHandle -> Name -> IO ()
|
|
| 187 | +putViaSerializableName bh nm = case findUserDataWriter Proxy bh of
|
|
| 188 | + BinaryWriter f -> f bh $ SerializableName nm
|
|
| 189 | + |
|
| 190 | +addSerializableNameWriter :: WriteBinHandle -> IO WriteBinHandle
|
|
| 191 | +addSerializableNameWriter bh' =
|
|
| 192 | + evaluate
|
|
| 193 | + $ flip addWriterToUserData bh'
|
|
| 194 | + $ BinaryWriter
|
|
| 195 | + $ \bh (SerializableName nm) ->
|
|
| 196 | + if
|
|
| 197 | + | isExternalName nm -> do
|
|
| 198 | + putByte bh 0
|
|
| 199 | + put_ bh nm
|
|
| 200 | + | otherwise -> do
|
|
| 201 | + putByte bh 1
|
|
| 202 | + put_ bh
|
|
| 203 | + $ occNameFS (occName nm)
|
|
| 204 | + `appendFS` mkFastString
|
|
| 205 | + (show $ nameUnique nm)
|
|
| 206 | + |
|
| 207 | +addSerializableNameReader :: HscEnv -> ReadBinHandle -> IO ReadBinHandle
|
|
| 208 | +addSerializableNameReader HscEnv {..} bh' = do
|
|
| 209 | + nc <- evaluate hsc_NC
|
|
| 210 | + env_ref <- newIORef emptyOccEnv
|
|
| 211 | + evaluate $ flip addReaderToUserData bh' $ BinaryReader $ \bh -> do
|
|
| 212 | + t <- getByte bh
|
|
| 213 | + case t of
|
|
| 214 | + 0 -> do
|
|
| 215 | + nm <- get bh
|
|
| 216 | + evaluate $ SerializableName nm
|
|
| 217 | + _ -> do
|
|
| 218 | + occ <- mkVarOccFS <$> get bh
|
|
| 219 | + u <- takeUniqFromNameCache nc
|
|
| 220 | + nm' <- evaluate $ mkInternalName u occ noSrcSpan
|
|
| 221 | + fmap SerializableName $ atomicModifyIORef' env_ref $ \env ->
|
|
| 222 | + case lookupOccEnv env occ of
|
|
| 223 | + Just nm -> (env, nm)
|
|
| 224 | + _ -> (extendOccEnv env occ nm', nm') |
| ... | ... | @@ -35,6 +35,7 @@ import GHC.Data.FastString |
| 35 | 35 | import GHC.Data.FlatBag
|
| 36 | 36 | import GHC.Types.Name
|
| 37 | 37 | import GHC.Types.Name.Env
|
| 38 | +import GHC.Utils.Binary
|
|
| 38 | 39 | import GHC.Utils.Outputable
|
| 39 | 40 | import GHC.Builtin.PrimOps
|
| 40 | 41 | import GHC.Types.SptEntry
|
| ... | ... | @@ -296,3 +297,8 @@ instance Outputable UnlinkedBCO where |
| 296 | 297 | ppr (sizeFlatBag lits), text "lits",
|
| 297 | 298 | ppr (sizeFlatBag ptrs), text "ptrs" ]
|
| 298 | 299 | |
| 300 | +instance Binary FFIInfo where
|
|
| 301 | + get bh = FFIInfo <$> get bh <*> get bh
|
|
| 302 | + |
|
| 303 | + put_ bh FFIInfo {..} = put_ bh ffiInfoArgs *> put_ bh ffiInfoRet
|
|
| 304 | + |
| ... | ... | @@ -16,6 +16,8 @@ import GHC.Prelude |
| 16 | 16 | import Control.DeepSeq
|
| 17 | 17 | |
| 18 | 18 | import GHC.Data.SmallArray
|
| 19 | +import GHC.Utils.Binary
|
|
| 20 | +import GHC.Utils.Exception
|
|
| 19 | 21 | |
| 20 | 22 | -- | Store elements in a flattened representation.
|
| 21 | 23 | --
|
| ... | ... | @@ -66,6 +68,13 @@ instance NFData a => NFData (FlatBag a) where |
| 66 | 68 | rnf (TupleFlatBag a b) = rnf a `seq` rnf b
|
| 67 | 69 | rnf (FlatBag arr) = rnfSmallArray arr
|
| 68 | 70 | |
| 71 | +instance (Binary a) => Binary (FlatBag a) where
|
|
| 72 | + get bh = do
|
|
| 73 | + xs <- get bh
|
|
| 74 | + evaluate $ fromList (fromIntegral $ length xs) xs
|
|
| 75 | + |
|
| 76 | + put_ bh = put_ bh . elemsFlatBag
|
|
| 77 | + |
|
| 69 | 78 | -- | Create an empty 'FlatBag'.
|
| 70 | 79 | --
|
| 71 | 80 | -- The empty 'FlatBag' is shared over all instances.
|
| ... | ... | @@ -129,4 +138,3 @@ fromSmallArray s = case sizeofSmallArray s of |
| 129 | 138 | 1 -> UnitFlatBag (indexSmallArray s 0)
|
| 130 | 139 | 2 -> TupleFlatBag (indexSmallArray s 0) (indexSmallArray s 1)
|
| 131 | 140 | _ -> FlatBag s |
| 132 | - |
| ... | ... | @@ -305,6 +305,8 @@ import Data.Bifunctor |
| 305 | 305 | import qualified GHC.Unit.Home.Graph as HUG
|
| 306 | 306 | import GHC.Unit.Home.PackageTable
|
| 307 | 307 | |
| 308 | +import GHC.ByteCode.Serialize
|
|
| 309 | + |
|
| 308 | 310 | {- **********************************************************************
|
| 309 | 311 | %* *
|
| 310 | 312 | Initialisation
|
| ... | ... | @@ -2169,7 +2171,8 @@ generateByteCode :: HscEnv |
| 2169 | 2171 | -> ModLocation
|
| 2170 | 2172 | -> IO (CompiledByteCode, [FilePath])
|
| 2171 | 2173 | generateByteCode hsc_env cgguts mod_location = do
|
| 2172 | - (hasStub, comp_bc) <- hscInteractive hsc_env cgguts mod_location
|
|
| 2174 | + (hasStub, comp_bc') <- hscInteractive hsc_env cgguts mod_location
|
|
| 2175 | + comp_bc <- testBinByteCode hsc_env comp_bc'
|
|
| 2173 | 2176 | compile_for_interpreter hsc_env $ \ i_env -> do
|
| 2174 | 2177 | stub_o <- traverse (compileForeign i_env LangC) hasStub
|
| 2175 | 2178 | foreign_files_o <- traverse (uncurry (compileForeign i_env)) (cgi_foreign_files cgguts)
|
| ... | ... | @@ -3,8 +3,12 @@ module GHC.Types.SptEntry |
| 3 | 3 | )
|
| 4 | 4 | where
|
| 5 | 5 | |
| 6 | -import GHC.Types.Var ( Id )
|
|
| 6 | +import GHC.Builtin.Types
|
|
| 7 | +import GHC.Types.Id
|
|
| 8 | +import GHC.Types.Name
|
|
| 7 | 9 | import GHC.Fingerprint.Type ( Fingerprint )
|
| 10 | +import GHC.Prelude
|
|
| 11 | +import GHC.Utils.Binary
|
|
| 8 | 12 | import GHC.Utils.Outputable
|
| 9 | 13 | |
| 10 | 14 | -- | An entry to be inserted into a module's static pointer table.
|
| ... | ... | @@ -14,3 +18,11 @@ data SptEntry = SptEntry Id Fingerprint |
| 14 | 18 | instance Outputable SptEntry where
|
| 15 | 19 | ppr (SptEntry id fpr) = ppr id <> colon <+> ppr fpr
|
| 16 | 20 | |
| 21 | +instance Binary SptEntry where
|
|
| 22 | + get bh = do
|
|
| 23 | + nm <- get bh
|
|
| 24 | + fp <- get bh
|
|
| 25 | + pure $ SptEntry (mkVanillaGlobal nm anyTy) fp
|
|
| 26 | + |
|
| 27 | + put_ bh (SptEntry nm fp) =
|
|
| 28 | + put_ bh (getName nm) *> put_ bh fp |
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | {-# LANGUAGE StandaloneDeriving #-}
|
| 5 | 5 | {-# LANGUAGE FlexibleContexts #-}
|
| 6 | 6 | {-# LANGUAGE FlexibleInstances #-}
|
| 7 | +{-# LANGUAGE RecordWildCards #-}
|
|
| 7 | 8 | |
| 8 | 9 | module GHC.Types.Tickish (
|
| 9 | 10 | GenTickish(..),
|
| ... | ... | @@ -44,6 +45,7 @@ import GHC.Utils.Panic |
| 44 | 45 | import Language.Haskell.Syntax.Extension ( NoExtField )
|
| 45 | 46 | |
| 46 | 47 | import Data.Data
|
| 48 | +import GHC.Utils.Binary
|
|
| 47 | 49 | import GHC.Utils.Outputable (Outputable (ppr), text, (<+>))
|
| 48 | 50 | |
| 49 | 51 | {- *********************************************************************
|
| ... | ... | @@ -202,6 +204,11 @@ instance NFData BreakpointId where |
| 202 | 204 | rnf BreakpointId{bi_tick_mod, bi_tick_index} =
|
| 203 | 205 | rnf bi_tick_mod `seq` rnf bi_tick_index
|
| 204 | 206 | |
| 207 | +instance Binary BreakpointId where
|
|
| 208 | + get bh = BreakpointId <$> get bh <*> get bh
|
|
| 209 | + |
|
| 210 | + put_ bh BreakpointId {..} = put_ bh bi_tick_mod *> put_ bh bi_tick_index
|
|
| 211 | + |
|
| 205 | 212 | --------------------------------------------------------------------------------
|
| 206 | 213 | |
| 207 | 214 | -- | A "counting tick" (where tickishCounts is True) is one that
|
| ... | ... | @@ -125,6 +125,7 @@ import Language.Haskell.Syntax.ImpExp.IsBoot (IsBootInterface(..)) |
| 125 | 125 | import {-# SOURCE #-} GHC.Types.Name (Name)
|
| 126 | 126 | import GHC.Data.FastString
|
| 127 | 127 | import GHC.Data.TrieMap
|
| 128 | +import GHC.Utils.Exception
|
|
| 128 | 129 | import GHC.Utils.Panic.Plain
|
| 129 | 130 | import GHC.Types.Unique.FM
|
| 130 | 131 | import GHC.Data.FastMutInt
|
| ... | ... | @@ -133,6 +134,7 @@ import GHC.Types.SrcLoc |
| 133 | 134 | import GHC.Types.Unique
|
| 134 | 135 | import qualified GHC.Data.Strict as Strict
|
| 135 | 136 | import GHC.Utils.Outputable( JoinPointHood(..) )
|
| 137 | +import GHCi.FFI
|
|
| 136 | 138 | |
| 137 | 139 | import Control.DeepSeq
|
| 138 | 140 | import Control.Monad ( when, (<$!>), unless, forM_, void )
|
| ... | ... | @@ -929,6 +931,12 @@ instance Binary Char where |
| 929 | 931 | put_ bh c = put_ bh (fromIntegral (ord c) :: Word32)
|
| 930 | 932 | get bh = do x <- get bh; return $! (chr (fromIntegral (x :: Word32)))
|
| 931 | 933 | |
| 934 | +instance Binary Word where
|
|
| 935 | + put_ bh i = put_ bh (fromIntegral i :: Word64)
|
|
| 936 | + get bh = do
|
|
| 937 | + x <- get bh
|
|
| 938 | + return $! (fromIntegral (x :: Word64))
|
|
| 939 | + |
|
| 932 | 940 | instance Binary Int where
|
| 933 | 941 | put_ bh i = put_ bh (fromIntegral i :: Int64)
|
| 934 | 942 | get bh = do
|
| ... | ... | @@ -2163,3 +2171,35 @@ instance Binary a => Binary (FingerprintWithValue a) where |
| 2163 | 2171 | instance NFData a => NFData (FingerprintWithValue a) where
|
| 2164 | 2172 | rnf (FingerprintWithValue fp mflags)
|
| 2165 | 2173 | = rnf fp `seq` rnf mflags `seq` ()
|
| 2174 | + |
|
| 2175 | +instance Binary FFIType where
|
|
| 2176 | + get bh = do
|
|
| 2177 | + t <- getByte bh
|
|
| 2178 | + evaluate $ case t of
|
|
| 2179 | + 0 -> FFIVoid
|
|
| 2180 | + 1 -> FFIPointer
|
|
| 2181 | + 2 -> FFIFloat
|
|
| 2182 | + 3 -> FFIDouble
|
|
| 2183 | + 4 -> FFISInt8
|
|
| 2184 | + 5 -> FFISInt16
|
|
| 2185 | + 6 -> FFISInt32
|
|
| 2186 | + 7 -> FFISInt64
|
|
| 2187 | + 8 -> FFIUInt8
|
|
| 2188 | + 9 -> FFIUInt16
|
|
| 2189 | + 10 -> FFIUInt32
|
|
| 2190 | + 11 -> FFIUInt64
|
|
| 2191 | + _ -> panic "Binary FFIType: invalid byte"
|
|
| 2192 | + |
|
| 2193 | + put_ bh t = putByte bh $ case t of
|
|
| 2194 | + FFIVoid -> 0
|
|
| 2195 | + FFIPointer -> 1
|
|
| 2196 | + FFIFloat -> 2
|
|
| 2197 | + FFIDouble -> 3
|
|
| 2198 | + FFISInt8 -> 4
|
|
| 2199 | + FFISInt16 -> 5
|
|
| 2200 | + FFISInt32 -> 6
|
|
| 2201 | + FFISInt64 -> 7
|
|
| 2202 | + FFIUInt8 -> 8
|
|
| 2203 | + FFIUInt16 -> 9
|
|
| 2204 | + FFIUInt32 -> 10
|
|
| 2205 | + FFIUInt64 -> 11 |
| ... | ... | @@ -228,6 +228,7 @@ Library |
| 228 | 228 | GHC.ByteCode.InfoTable
|
| 229 | 229 | GHC.ByteCode.Instr
|
| 230 | 230 | GHC.ByteCode.Linker
|
| 231 | + GHC.ByteCode.Serialize
|
|
| 231 | 232 | GHC.ByteCode.Types
|
| 232 | 233 | GHC.Cmm
|
| 233 | 234 | GHC.Cmm.BlockId
|