[project @ 2001-06-18 21:45:49 by sof]
[ghc-hetmet.git] / ghc / compiler / ghci / Linker.lhs
index 72d6b89..5d16633 100644 (file)
@@ -5,14 +5,20 @@
 
 \begin{code}
 {-# OPTIONS -#include "Linker.h" #-}
+
+-- so that we can see defn of LEADING_UNDERSCORE
+#include "../includes/config.h"
+
 module Linker ( 
    initLinker,  -- :: IO ()
    loadObj,      -- :: String -> IO ()
    unloadObj,    -- :: String -> IO ()
    lookupSymbol, -- :: String -> IO (Maybe (Ptr a))
    resolveObjs,  -- :: IO ()
+   addDLL       -- :: String -> IO (Ptr CChar)
   )  where
 
+import CTypes          ( CChar )
 import Foreign         ( Ptr, nullPtr )
 import PrelByteArr
 import PrelPack        (packString)
@@ -22,7 +28,12 @@ import Panic         ( panic )
 -- RTS Linker Interface
 -- ---------------------------------------------------------------------------
 
-lookupSymbol str = do
+lookupSymbol str_in = do
+#  ifdef LEADING_UNDERSCORE
+   let str = '_':str_in
+#  else
+   let str = str_in
+#  endif
    addr <- c_lookupSymbol (packString str)
    if addr == nullPtr
        then return Nothing
@@ -46,6 +57,9 @@ resolveObjs = do
        then panic "resolveObjs: failed"
        else return ()
 
+addDLL path lib = do
+   maybe_errmsg <- c_addDLL (packString path) (packString lib)
+   return maybe_errmsg
 
 type PackedString = ByteArray Int
 
@@ -63,4 +77,8 @@ foreign import "resolveObjs" unsafe
 
 foreign import "initLinker" unsafe
    initLinker :: IO ()
+
+foreign import "addDLL" unsafe 
+   c_addDLL :: PackedString -> PackedString -> IO (Ptr CChar)
+
 \end{code}