[project @ 2000-11-16 11:39:36 by simonmar]
[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    loadObj,      -- :: String -> IO ()
10    unloadObj,    -- :: String -> IO ()
11    lookupSymbol, -- :: String -> IO (Maybe Addr)
12    resolveObjs,  -- :: IO ()
13   )  where
14
15 import Addr
16 import PrelByteArr
17 import PrelPack         (packString)
18 import Panic            ( panic )
19
20 -- ---------------------------------------------------------------------------
21 -- RTS Linker Interface
22 -- ---------------------------------------------------------------------------
23
24 lookupSymbol str = do
25    addr <- c_lookupSymbol (packString str)
26    if addr == nullAddr
27         then return Nothing
28         else return (Just addr)
29
30 loadObj str = do
31    r <- c_loadObj (packString str)
32    if (r == 0)
33         then panic "loadObj: failed"
34         else return ()
35
36 unloadObj str = do
37    r <- c_unloadObj (packString str)
38    if (r == 0)
39         then panic "unloadObj: failed"
40         else return ()
41
42 resolveObjs = do
43    r <- c_resolveObjs
44    if (r == 0)
45         then panic "resolveObjs: failed"
46         else return ()
47
48
49 type PackedString = ByteArray Int
50
51 foreign import "lookupSymbol" unsafe
52    c_lookupSymbol :: PackedString -> IO Addr
53
54 foreign import "loadObj" unsafe
55    c_loadObj :: PackedString -> IO Int
56
57 foreign import "unloadObj" unsafe
58    c_unloadObj :: PackedString -> IO Int
59
60 foreign import "resolveObjs" unsafe
61    c_resolveObjs :: IO Int
62 \end{code}