72d6b89cb5f06e134d40760776d27c0475541a08
[ghc-hetmet.git] / ghc / compiler / ghci / Linker.lhs
1 %
2 % (c) The University of Glasgow, 2000
3 %
4 \section[Linker]{The In-Memory Object File Linker}
5
6 \begin{code}
7 {-# OPTIONS -#include "Linker.h" #-}
8 module Linker ( 
9    initLinker,   -- :: IO ()
10    loadObj,      -- :: String -> IO ()
11    unloadObj,    -- :: String -> IO ()
12    lookupSymbol, -- :: String -> IO (Maybe (Ptr a))
13    resolveObjs,  -- :: IO ()
14   )  where
15
16 import Foreign          ( Ptr, nullPtr )
17 import PrelByteArr
18 import PrelPack         (packString)
19 import Panic            ( panic )
20
21 -- ---------------------------------------------------------------------------
22 -- RTS Linker Interface
23 -- ---------------------------------------------------------------------------
24
25 lookupSymbol str = do
26    addr <- c_lookupSymbol (packString str)
27    if addr == nullPtr
28         then return Nothing
29         else return (Just addr)
30
31 loadObj str = do
32    r <- c_loadObj (packString str)
33    if (r == 0)
34         then panic "loadObj: failed"
35         else return ()
36
37 unloadObj str = do
38    r <- c_unloadObj (packString str)
39    if (r == 0)
40         then panic "unloadObj: failed"
41         else return ()
42
43 resolveObjs = do
44    r <- c_resolveObjs
45    if (r == 0)
46         then panic "resolveObjs: failed"
47         else return ()
48
49
50 type PackedString = ByteArray Int
51
52 foreign import "lookupSymbol" unsafe
53    c_lookupSymbol :: PackedString -> IO (Ptr a)
54
55 foreign import "loadObj" unsafe
56    c_loadObj :: PackedString -> IO Int
57
58 foreign import "unloadObj" unsafe
59    c_unloadObj :: PackedString -> IO Int
60
61 foreign import "resolveObjs" unsafe
62    c_resolveObjs :: IO Int
63
64 foreign import "initLinker" unsafe
65    initLinker :: IO ()
66 \end{code}