+{-# OPTIONS -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/Commentary/CodingStyle#Warnings
+-- for details
+
-----------------------------------------------------------------------------
--
-- Cmm utilities.
--
--- (c) The University of Glasgow 2004
+-- (c) The University of Glasgow 2004-2006
--
-----------------------------------------------------------------------------
mkIntCLit, zeroCLit,
mkLblExpr,
+
+ loadArgsIntoTemps, maybeAssignTemp,
) where
#include "HsVersions.h"
-import CLabel ( CLabel )
+import CLabel
import Cmm
import MachOp
import OrdList
import Outputable
+import Unique
---------------------------------------------------
--
mkLblExpr :: CLabel -> CmmExpr
mkLblExpr lbl = CmmLit (CmmLabel lbl)
+
+---------------------------------------------------
+--
+-- Helpers for foreign call arguments
+--
+---------------------------------------------------
+
+loadArgsIntoTemps :: [Unique]
+ -> CmmActuals
+ -> ([Unique], [CmmStmt], CmmActuals)
+loadArgsIntoTemps uniques [] = (uniques, [], [])
+loadArgsIntoTemps uniques ((CmmHinted e hint):args) =
+ (uniques'',
+ new_stmts ++ remaining_stmts,
+ (CmmHinted new_e hint) : remaining_e)
+ where
+ (uniques', new_stmts, new_e) = maybeAssignTemp uniques e
+ (uniques'', remaining_stmts, remaining_e) =
+ loadArgsIntoTemps uniques' args
+
+maybeAssignTemp :: [Unique] -> CmmExpr -> ([Unique], [CmmStmt], CmmExpr)
+maybeAssignTemp uniques e
+ | hasNoGlobalRegs e = (uniques, [], e)
+ | otherwise = (tail uniques, [CmmAssign local e], CmmReg local)
+ where local = CmmLocal (LocalReg (head uniques) (cmmExprRep e) GCKindNonPtr)