X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fghci%2FLinker.lhs;h=475f7074f93bc07059b92459784103846826e96d;hb=979947f545d70c63edb7ca96f6e47008ac90e3bf;hp=e7fb27800cc5218685bd9b3a382179893141f539;hpb=eb6fb4cf7742dbdd10d1fa0702ff85b1c49084d4;p=ghc-hetmet.git diff --git a/ghc/compiler/ghci/Linker.lhs b/ghc/compiler/ghci/Linker.lhs index e7fb278..475f707 100644 --- a/ghc/compiler/ghci/Linker.lhs +++ b/ghc/compiler/ghci/Linker.lhs @@ -6,9 +6,6 @@ \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 () @@ -18,47 +15,56 @@ module Linker ( addDLL -- :: String -> IO (Ptr CChar) ) where +import PrelByteArr +import PrelPack ( packString ) + +import Monad ( when ) + import CTypes ( CChar ) import Foreign ( Ptr, nullPtr ) -import PrelByteArr -import PrelPack (packString) import Panic ( panic ) +import DriverUtil ( prefixUnderscore ) -- --------------------------------------------------------------------------- -- RTS Linker Interface -- --------------------------------------------------------------------------- +lookupSymbol :: String -> IO (Maybe (Ptr a)) lookupSymbol str_in = do -# ifdef LEADING_UNDERSCORE - let str = '_':str_in -# else - let str = str_in -# endif + let str = prefixUnderscore str_in addr <- c_lookupSymbol (packString str) if addr == nullPtr then return Nothing else return (Just addr) +loadObj :: String -> IO () loadObj str = do r <- c_loadObj (packString str) - if (r == 0) - then panic "loadObj: failed" - else return () + when (r == 0) (panic "loadObj: failed") +unloadObj :: String -> IO () unloadObj str = do r <- c_unloadObj (packString str) - if (r == 0) - then panic "unloadObj: failed" - else return () + when (r == 0) (panic "unloadObj: failed") +resolveObjs :: IO Bool resolveObjs = do r <- c_resolveObjs return (r /= 0) -- returns True <=> success +addDLL :: String -> String -> IO (Ptr CChar) addDLL path lib = do maybe_errmsg <- c_addDLL (packString path) (packString lib) return maybe_errmsg + +foreign import "initLinker" unsafe + initLinker :: IO () + +-- --------------------------------------------------------------------------- +-- Foreign declaractions to RTS entry points which does the real work; +-- --------------------------------------------------------------------------- + type PackedString = ByteArray Int foreign import "lookupSymbol" unsafe @@ -73,9 +79,6 @@ foreign import "unloadObj" unsafe foreign import "resolveObjs" unsafe c_resolveObjs :: IO Int -foreign import "initLinker" unsafe - initLinker :: IO () - foreign import "addDLL" unsafe c_addDLL :: PackedString -> PackedString -> IO (Ptr CChar) \end{code}