+
+---------------------------------------------------
+--
+-- Helpers for foreign call arguments
+--
+---------------------------------------------------
+
+loadArgsIntoTemps :: [Unique]
+ -> CmmActuals
+ -> ([Unique], [CmmStmt], CmmActuals)
+loadArgsIntoTemps uniques [] = (uniques, [], [])
+loadArgsIntoTemps uniques ((CmmKinded e hint):args) =
+ (uniques'',
+ new_stmts ++ remaining_stmts,
+ (CmmKinded 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)