summaryrefslogtreecommitdiff
path: root/libraries/ghci/GHCi/ResolvedBCO.hs
blob: 9234210418a986970740d416c6b05a9e9f2f3b95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{-# LANGUAGE RecordWildCards, DeriveGeneric, GeneralizedNewtypeDeriving #-}
module GHCi.ResolvedBCO
  ( ResolvedBCO(..)
  , ResolvedBCOPtr(..)
  ) where

import SizedSeq
import GHCi.RemoteTypes

import Data.Array.Unboxed
import Data.Binary
import GHC.Generics

-- -----------------------------------------------------------------------------
-- ResolvedBCO

-- A ResolvedBCO is one in which all the Name references have been
-- resolved to actual addresses or RemoteHValues.

data ResolvedBCO
   = ResolvedBCO {
        resolvedBCOArity  :: Int,
        resolvedBCOInstrs :: UArray Int Word16,         -- insns
        resolvedBCOBitmap :: UArray Int Word,           -- bitmap
        resolvedBCOLits   :: UArray Int Word,           -- non-ptrs
        resolvedBCOPtrs   :: (SizedSeq ResolvedBCOPtr)  -- ptrs
   }
   deriving (Generic, Show)

instance Binary ResolvedBCO

data ResolvedBCOPtr
  = ResolvedBCORef Int
      -- ^ reference to the Nth BCO in the current set
  | ResolvedBCOPtr HValueRef
      -- ^ reference to a previously created BCO
  | ResolvedBCOStaticPtr RemotePtr
      -- ^ reference to a static ptr
  | ResolvedBCOPtrBCO ResolvedBCO
      -- ^ a nested BCO
  | ResolvedBCOPtrLocal HValue
      -- ^ something local, cannot be serialized
  deriving (Generic, Show)

-- Manual Binary instance is needed because we cannot serialize
-- ResolvedBCOPtrLocal.  This will go away once we have support for
-- remote breakpoints.
instance Binary ResolvedBCOPtr where
  put (ResolvedBCORef a) = putWord8 0 >> put a
  put (ResolvedBCOPtr a) = putWord8 1 >> put a
  put (ResolvedBCOStaticPtr a) = putWord8 2 >> put a
  put (ResolvedBCOPtrBCO a) = putWord8 3 >> put a
  put (ResolvedBCOPtrLocal _) =
    error "Cannot serialize a local pointer.  Use -fno-external-interpreter?"

  get = do
    w <- getWord8
    case w of
      0 -> ResolvedBCORef <$> get
      1 -> ResolvedBCOPtr <$> get
      2 -> ResolvedBCOStaticPtr <$> get
      _ -> ResolvedBCOPtrBCO <$> get