Commit e087ed66 authored by simonmar's avatar simonmar
Browse files

[project @ 2005-08-02 14:03:40 by simonmar]

Add callerSaveVolatileRegs for saving registers around C calls
parent c6c1a5a7
...@@ -33,7 +33,7 @@ module MachRegs ( ...@@ -33,7 +33,7 @@ module MachRegs (
-- * Global registers -- * Global registers
get_GlobalReg_reg_or_addr, get_GlobalReg_reg_or_addr,
callerSaves, callerSaves, callerSaveVolatileRegs,
-- * Machine-dependent register-related stuff -- * Machine-dependent register-related stuff
allocatableRegs, argRegs, allArgRegs, callClobberedRegs, allocatableRegs, argRegs, allArgRegs, callClobberedRegs,
...@@ -342,6 +342,39 @@ get_Regtable_addr_from_offset rep offset ...@@ -342,6 +342,39 @@ get_Regtable_addr_from_offset rep offset
Nothing -> regTableOffset offset Nothing -> regTableOffset offset
Just _ -> CmmRegOff (CmmGlobal BaseReg) offset Just _ -> CmmRegOff (CmmGlobal BaseReg) offset
-- -----------------------------------------------------------------------------
-- caller-save registers
-- Here we generate the sequence of saves/restores required around a
-- foreign call instruction.
callerSaveVolatileRegs :: Maybe [GlobalReg] -> ([CmmStmt], [CmmStmt])
callerSaveVolatileRegs vols = (caller_save, caller_load)
where
caller_save = foldr ($!) [] (map callerSaveGlobalReg regs_to_save)
caller_load = foldr ($!) [] (map callerRestoreGlobalReg regs_to_save)
system_regs = [Sp,SpLim,Hp,HpLim,CurrentTSO,CurrentNursery,
{-SparkHd,SparkTl,SparkBase,SparkLim,-}BaseReg ]
regs_to_save = system_regs ++ vol_list
vol_list = case vols of Nothing -> []; Just regs -> regs
callerSaveGlobalReg reg next
| callerSaves reg =
CmmStore (get_GlobalReg_addr reg)
(CmmReg (CmmGlobal reg)) : next
| otherwise = next
callerRestoreGlobalReg reg next
| callerSaves reg =
CmmAssign (CmmGlobal reg)
(CmmLoad (get_GlobalReg_addr reg) (globalRegRep reg))
: next
| otherwise = next
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- Registers -- Registers
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment