-- |
-- Module      : Data.Array.Accelerate.LLVM.Native.Link.Object
-- Copyright   : [2017..2020] The Accelerate Team
-- License     : BSD3
--
-- Maintainer  : Trevor L. McDonell <trevor.mcdonell@gmail.com>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
--

module Data.Array.Accelerate.LLVM.Native.Link.Object
  where

import Data.List
import Data.Word
import Foreign.ForeignPtr
import Foreign.Ptr

import Data.ByteString.Short.Char8                                  ( ShortByteString, unpack )
import Data.Array.Accelerate.Lifetime


-- | The function table is a list of function names together with a pointer in
-- the target address space containing the corresponding executable code.
--
data FunctionTable  = FunctionTable { FunctionTable -> [Function]
functionTable :: [Function] }
type Function       = (ShortByteString, FunPtr ())

instance Show FunctionTable where
  showsPrec :: Int -> FunctionTable -> ShowS
showsPrec Int
_ FunctionTable
f
    = String -> ShowS
showString String
"<<"
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"," [ ShortByteString -> String
unpack ShortByteString
n | (ShortByteString
n,FunPtr ()
_) <- FunctionTable -> [Function]
functionTable FunctionTable
f ])
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
">>"

-- | Object code consists of memory in the target address space.
--
type ObjectCode     = Lifetime [Segment]
data Segment        = Segment {-# UNPACK #-} !Int                 -- size in bytes
                              {-# UNPACK #-} !(ForeignPtr Word8)  -- memory in target address space