Add {-# OPTIONS_GHC -w #-} and some blurb to all compiler modules
[ghc-hetmet.git] / compiler / codeGen / CgForeignCall.hs
index 48015fa..23b68d8 100644 (file)
@@ -6,6 +6,13 @@
 --
 -----------------------------------------------------------------------------
 
+{-# OPTIONS_GHC -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
+-- for details
+
 module CgForeignCall (
   cgForeignCall,
   emitForeignCall,
@@ -32,16 +39,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 +78,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)
+         (CmmCallee cmm_target cconv) call_args (Just vols) srt CmmMayReturn
   where
       (call_args, cmm_target)
        = case target of
@@ -96,7 +99,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 +110,15 @@ 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
+        -> CmmReturnInfo
        -> Code
-emitForeignCall' safety results target args vols 
+emitForeignCall' safety results target args vols srt ret
   | 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 ret)
     stmtsC caller_load
 
   | otherwise = do
@@ -126,15 +131,20 @@ emitForeignCall' safety results target args vols
     let (caller_save, caller_load) = callerSaveVolatileRegs vols
     emitSaveThreadState
     stmtsC caller_save
-    stmtC (CmmCall (CmmForeignCall suspendThread CCallConv) 
+    -- 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 (CmmCallee suspendThread CCallConv) 
                        [ (id,PtrHint) ]
                        [ (CmmReg (CmmGlobal BaseReg), PtrHint) ] 
-                       )
-    stmtC (CmmCall temp_target results temp_args)
-    stmtC (CmmCall (CmmForeignCall resumeThread CCallConv) 
+                       CmmUnsafe ret)
+    stmtC (CmmCall temp_target results temp_args CmmUnsafe ret)
+    stmtC (CmmCall (CmmCallee resumeThread CCallConv) 
                        [ (new_base, PtrHint) ]
                        [ (CmmReg (CmmLocal id), PtrHint) ]
-                       )
+                       CmmUnsafe ret)
     -- Assign the result to BaseReg: we
     -- might now have a different Capability!
     stmtC (CmmAssign (CmmGlobal BaseReg) (CmmReg (CmmLocal new_base)))
@@ -157,9 +167,9 @@ load_args_into_temps = mapM arg_assign_temp
           tmp <- maybe_assign_temp e
           return (tmp,hint)
        
-load_target_into_temp (CmmForeignCall expr conv) = do 
+load_target_into_temp (CmmCallee expr conv) = do 
   tmp <- maybe_assign_temp expr
-  return (CmmForeignCall tmp conv)
+  return (CmmCallee tmp conv)
 load_target_into_temp other_target =
   return other_target