[project @ 2001-10-24 15:27:53 by simonpj]
[ghc-hetmet.git] / ghc / compiler / ghci / Linker.lhs
index 72d6b89..238d009 100644 (file)
@@ -5,24 +5,29 @@
 
 \begin{code}
 {-# OPTIONS -#include "Linker.h" #-}
+
 module Linker ( 
    initLinker,  -- :: IO ()
    loadObj,      -- :: String -> IO ()
    unloadObj,    -- :: String -> IO ()
    lookupSymbol, -- :: String -> IO (Maybe (Ptr a))
-   resolveObjs,  -- :: IO ()
+   resolveObjs,  -- :: IO Bool
+   addDLL       -- :: String -> IO (Ptr CChar)
   )  where
 
+import CTypes          ( CChar )
 import Foreign         ( Ptr, nullPtr )
 import PrelByteArr
 import PrelPack        (packString)
 import Panic           ( panic )
+import DriverUtil       ( prefixUnderscore )
 
 -- ---------------------------------------------------------------------------
 -- RTS Linker Interface
 -- ---------------------------------------------------------------------------
 
-lookupSymbol str = do
+lookupSymbol str_in = do
+   let str = prefixUnderscore str_in
    addr <- c_lookupSymbol (packString str)
    if addr == nullPtr
        then return Nothing
@@ -42,10 +47,11 @@ unloadObj str = do
 
 resolveObjs = do
    r <- c_resolveObjs
-   if (r == 0)
-       then panic "resolveObjs: failed"
-       else return ()
+   return (r /= 0)  -- returns True <=> success
 
+addDLL path lib = do
+   maybe_errmsg <- c_addDLL (packString path) (packString lib)
+   return maybe_errmsg
 
 type PackedString = ByteArray Int
 
@@ -63,4 +69,7 @@ foreign import "resolveObjs" unsafe
 
 foreign import "initLinker" unsafe
    initLinker :: IO ()
+
+foreign import "addDLL" unsafe 
+   c_addDLL :: PackedString -> PackedString -> IO (Ptr CChar)
 \end{code}