X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FcodeGen%2FCgForeignCall.hs;h=ce272e9a86e8c94b9265fc2295ea3f7e92c2ca22;hb=c23fe488fc0c4b019a2dc3186106e4654b5f5107;hp=48015fa45a9c960e09201d950ec08509ac3f594e;hpb=207802589da0d23c3f16195f453b24a1e46e322d;p=ghc-hetmet.git diff --git a/compiler/codeGen/CgForeignCall.hs b/compiler/codeGen/CgForeignCall.hs index 48015fa..ce272e9 100644 --- a/compiler/codeGen/CgForeignCall.hs +++ b/compiler/codeGen/CgForeignCall.hs @@ -32,16 +32,11 @@ import CmmUtils import MachOp import SMRep import ForeignCall +import ClosureInfo import Constants import StaticFlags import Outputable -import MachRegs (callerSaveVolatileRegs) - -- HACK: this is part of the NCG so we shouldn't use this, but we need - -- it for now to eliminate the need for saved regs to be in CmmCall. - -- The long term solution is to factor callerSaveVolatileRegs - -- from nativeGen into codeGen - import Control.Monad -- ----------------------------------------------------------------------------- @@ -76,8 +71,9 @@ emitForeignCall emitForeignCall results (CCall (CCallSpec target cconv safety)) args live = do vols <- getVolatileRegs live + srt <- getSRTInfo emitForeignCall' safety results - (CmmForeignCall cmm_target cconv) call_args (Just vols) + (CmmForeignCall cmm_target cconv) call_args (Just vols) srt where (call_args, cmm_target) = case target of @@ -96,7 +92,7 @@ emitForeignCall results (CCall (CCallSpec target cconv safety)) args live -- ToDo: this might not be correct for 64-bit API arg_size rep = max (machRepByteWidth rep) wORD_SIZE -emitForeignCall results (DNCall _) args live +emitForeignCall _ (DNCall _) _ _ = panic "emitForeignCall: DNCall" @@ -107,13 +103,14 @@ emitForeignCall' -> CmmCallTarget -- the op -> [(CmmExpr,MachHint)] -- arguments -> Maybe [GlobalReg] -- live vars, in case we need to save them + -> C_SRT -- the SRT of the calls continuation -> Code -emitForeignCall' safety results target args vols +emitForeignCall' safety results target args vols srt | not (playSafe safety) = do temp_args <- load_args_into_temps args let (caller_save, caller_load) = callerSaveVolatileRegs vols stmtsC caller_save - stmtC (CmmCall target results temp_args) + stmtC (CmmCall target results temp_args CmmUnsafe) stmtsC caller_load | otherwise = do @@ -126,15 +123,20 @@ emitForeignCall' safety results target args vols let (caller_save, caller_load) = callerSaveVolatileRegs vols emitSaveThreadState stmtsC caller_save + -- The CmmUnsafe arguments are only correct because this part + -- of the code hasn't been moved into the CPS pass yet. + -- Once that happens, this function will just emit a (CmmSafe srt) call, + -- and the CPS will will be the one to convert that + -- to this sequence of three CmmUnsafe calls. stmtC (CmmCall (CmmForeignCall suspendThread CCallConv) [ (id,PtrHint) ] [ (CmmReg (CmmGlobal BaseReg), PtrHint) ] - ) - stmtC (CmmCall temp_target results temp_args) + CmmUnsafe) + stmtC (CmmCall temp_target results temp_args CmmUnsafe) stmtC (CmmCall (CmmForeignCall resumeThread CCallConv) [ (new_base, PtrHint) ] [ (CmmReg (CmmLocal id), PtrHint) ] - ) + CmmUnsafe) -- Assign the result to BaseReg: we -- might now have a different Capability! stmtC (CmmAssign (CmmGlobal BaseReg) (CmmReg (CmmLocal new_base)))