X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fghci%2FByteCodeFFI.lhs;h=982cdec29e6b30bf6946c001f07801eb657ca687;hb=84923cc7de2a93c22a2f72daf9ac863959efae13;hp=c5bdc2c61bdcc6b67be8bf1d25b95d3dd68269cd;hpb=ab22f4e6456820c1b5169d75f5975a94e61f54ce;p=ghc-hetmet.git diff --git a/compiler/ghci/ByteCodeFFI.lhs b/compiler/ghci/ByteCodeFFI.lhs index c5bdc2c..982cdec 100644 --- a/compiler/ghci/ByteCodeFFI.lhs +++ b/compiler/ghci/ByteCodeFFI.lhs @@ -5,7 +5,7 @@ ByteCodeGen: Generate machine-code sequences for foreign import \begin{code} -module ByteCodeFFI ( mkMarshalCode, moan64 ) where +module ByteCodeFFI ( mkMarshalCode, moan64, newExec ) where #include "HsVersions.h" @@ -18,10 +18,12 @@ import Panic -- there is ifdeffery below import Control.Exception ( throwDyn ) import Data.Bits ( Bits(..), shiftR, shiftL ) -import Foreign ( newArray, Ptr ) import Data.List ( mapAccumL ) import Data.Word ( Word8, Word32 ) +import Foreign ( Ptr, FunPtr, castPtrToFunPtr, + Storable, sizeOf, pokeArray ) +import Foreign.C ( CUInt ) import System.IO.Unsafe ( unsafePerformIO ) import System.IO ( hPutStrLn, stderr ) -- import Debug.Trace ( trace ) @@ -70,14 +72,23 @@ we don't clear our own (single) arg off the C stack. -} mkMarshalCode :: CCallConv -> (Int, CgRep) -> Int -> [(Int, CgRep)] - -> IO (Ptr Word8) + -> IO (FunPtr ()) mkMarshalCode cconv (r_offW, r_rep) addr_offW arg_offs_n_reps = let bytes = mkMarshalCode_wrk cconv (r_offW, r_rep) addr_offW arg_offs_n_reps - in Foreign.newArray bytes - + in newExec bytes +newExec :: Storable a => [a] -> IO (FunPtr ()) +newExec code + = do ptr <- _allocateExec (fromIntegral $ codeSize undefined code) + pokeArray ptr code + return (castPtrToFunPtr ptr) + where + codeSize :: Storable a => a -> [a] -> Int + codeSize dummy array = sizeOf(dummy) * length array +foreign import ccall unsafe "allocateExec" + _allocateExec :: CUInt -> IO (Ptr a) mkMarshalCode_wrk :: CCallConv -> (Int, CgRep) -> Int -> [(Int, CgRep)] @@ -252,7 +263,7 @@ mkMarshalCode_wrk cconv (r_offW, r_rep) addr_offW arg_offs_n_reps NonPtrArg -> i32 DoubleArg -> f64 FloatArg -> f32 - -- LongArg -> i64 + LongArg -> i64 VoidArg -> [] other -> moan64 "ByteCodeFFI.mkMarshalCode_wrk(x86)" (ppr r_rep)