{-# LINE 1 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
{-# LANGUAGE NoMonoLocalBinds #-}
module GHC.Exts.Heap.InfoTable
    ( module GHC.Exts.Heap.InfoTable.Types
    , itblSize
    , peekItbl
    , pokeItbl
    ) where



import Prelude -- See note [Why do we import Prelude here?]
import GHC.Exts.Heap.InfoTable.Types

{-# LINE 17 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
import Foreign

-------------------------------------------------------------------------
-- Profiling specific code
--
-- The functions that follow all rely on PROFILING. They are duplicated in
-- ghc-heap/GHC/Exts/Heap/InfoTableProf.hsc where PROFILING is defined. This
-- allows hsc2hs to generate values for both profiling and non-profiling builds.

-- | Read an InfoTable from the heap into a haskell type.
-- WARNING: This code assumes it is passed a pointer to a "standard" info
-- table. If tables_next_to_code is enabled, it will look 1 byte before the
-- start for the entry field.
peekItbl :: Ptr StgInfoTable -> IO StgInfoTable
peekItbl :: Ptr StgInfoTable -> IO StgInfoTable
peekItbl Ptr StgInfoTable
a0 = do

{-# LINE 36 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  let ptr :: Ptr StgInfoTable
ptr = Ptr StgInfoTable
a0
      entry' :: Maybe a
entry' = Maybe a
forall a. Maybe a
Nothing

{-# LINE 39 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  ptrs'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
{-# LINE 40 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  nptrs'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
{-# LINE 41 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  tipe'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
{-# LINE 42 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}

{-# LINE 43 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  srtlen' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) a0
{-# LINE 44 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}

{-# LINE 47 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  StgInfoTable -> IO StgInfoTable
forall (m :: * -> *) a. Monad m => a -> m a
return StgInfoTable :: Maybe EntryFunPtr
-> HalfWord
-> HalfWord
-> ClosureType
-> HalfWord
-> Maybe ItblCodes
-> StgInfoTable
StgInfoTable
    { entry :: Maybe EntryFunPtr
entry  = Maybe EntryFunPtr
forall a. Maybe a
entry'
    , ptrs :: HalfWord
ptrs   = HalfWord
ptrs'
    , nptrs :: HalfWord
nptrs  = HalfWord
nptrs'
    , tipe :: ClosureType
tipe   = Int -> ClosureType
forall a. Enum a => Int -> a
toEnum (HalfWord -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HalfWord
tipe' :: HalfWord))
    , srtlen :: HalfWord
srtlen = HalfWord
srtlen'
    , code :: Maybe ItblCodes
code   = Maybe ItblCodes
forall a. Maybe a
Nothing
    }

pokeItbl :: Ptr StgInfoTable -> StgInfoTable -> IO ()
pokeItbl :: Ptr StgInfoTable -> StgInfoTable -> IO ()
pokeItbl Ptr StgInfoTable
a0 StgInfoTable
itbl = do

{-# LINE 61 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  ((\Ptr StgInfoTable
hsc_ptr -> Ptr StgInfoTable -> Int -> HalfWord -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr StgInfoTable
hsc_ptr Int
0)) Ptr StgInfoTable
a0 (StgInfoTable -> HalfWord
ptrs StgInfoTable
itbl)
{-# LINE 62 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) a0 (nptrs itbl)
{-# LINE 63 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) a0 (toHalfWord (fromEnum (tipe itbl)))
{-# LINE 64 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}

{-# LINE 65 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  ((\hsc_ptr -> pokeByteOff hsc_ptr 12)) a0 (srtlen itbl)
{-# LINE 66 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}

{-# LINE 69 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}

{-# LINE 70 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  let code_offset = a0 `plusPtr` ((16))
{-# LINE 71 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  case code itbl of
    Nothing -> return ()
    Just (Left xs) -> pokeArray code_offset xs
    Just (Right xs) -> pokeArray code_offset xs

{-# LINE 76 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}
  where
    toHalfWord :: Int -> HalfWord
    toHalfWord :: Int -> HalfWord
toHalfWord Int
i = Int -> HalfWord
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i

-- | Size in bytes of a standard InfoTable
itblSize :: Int
itblSize :: Int
itblSize = ((Int
16))
{-# LINE 83 "libraries/ghc-heap/GHC/Exts/Heap/InfoTable.hsc" #-}