Eliminate IF_ARCH_sparc
[ghc-hetmet.git] / compiler / nativeGen / SPARC / Stack.hs
1
2 module SPARC.Stack (
3         spRel,
4         fpRel,
5         spillSlotToOffset,
6         maxSpillSlots
7 )
8
9 where
10
11 import SPARC.AddrMode
12 import SPARC.Regs
13 import SPARC.Base
14 import SPARC.Imm
15
16 import Outputable
17
18 -- | Get an AddrMode relative to the address in sp.
19 --      This gives us a stack relative addressing mode for volatile
20 --      temporaries and for excess call arguments.  
21 --
22 spRel :: Int            -- ^ stack offset in words, positive or negative
23       -> AddrMode
24
25 spRel n = AddrRegImm sp (ImmInt (n * wordLength))
26
27
28 -- | Get an address relative to the frame pointer.
29 --      This doesn't work work for offsets greater than 13 bits; we just hope for the best
30 --
31 fpRel :: Int -> AddrMode
32 fpRel n
33         = AddrRegImm fp (ImmInt (n * wordLength))
34
35
36 -- | Convert a spill slot number to a *byte* offset, with no sign.
37 --
38 spillSlotToOffset :: Int -> Int
39 spillSlotToOffset slot
40         | slot >= 0 && slot < maxSpillSlots
41         = 64 + spillSlotSize * slot
42
43         | otherwise
44         = pprPanic "spillSlotToOffset:" 
45                       (   text "invalid spill location: " <> int slot
46                       $$  text "maxSpillSlots:          " <> int maxSpillSlots)
47
48
49 -- | The maximum number of spill slots available on the C stack.
50 --      If we use up all of the slots, then we're screwed.
51 --
52 --      Why do we reserve 64 bytes, instead of using the whole thing??
53 --              -- BL 2009/02/15
54 --
55 maxSpillSlots :: Int
56 maxSpillSlots 
57         = ((spillAreaLength - 64) `div` spillSlotSize) - 1
58