Eliminate IF_ARCH_sparc
[ghc-hetmet.git] / compiler / nativeGen / SPARC / Base.hs
1
2 -- | Bits and pieces on the bottom of the module dependency tree.
3 --      Also import the required constants, so we know what we're using.
4 --      
5 --      In the interests of cross-compilation, we want to free ourselves
6 --      from the autoconf generated modules like main/Constants
7 --
8 module SPARC.Base (
9         wordLength,
10         wordLengthInBits,
11         spillAreaLength,
12         spillSlotSize,
13         extraStackArgsHere,
14         fits13Bits,
15         is32BitInteger,
16         largeOffsetError
17 )
18
19 where
20
21 import qualified Constants
22 import Panic
23
24 import Data.Int
25
26
27 -- On 32 bit SPARC, pointers are 32 bits.
28 wordLength :: Int
29 wordLength = 4
30
31 wordLengthInBits :: Int
32 wordLengthInBits 
33         = wordLength * 8
34
35 -- Size of the available spill area
36 spillAreaLength :: Int
37 spillAreaLength
38         = Constants.rESERVED_C_STACK_BYTES
39
40 -- | We need 8 bytes because our largest registers are 64 bit.
41 spillSlotSize :: Int
42 spillSlotSize = 8
43
44
45 -- | We (allegedly) put the first six C-call arguments in registers;
46 --      where do we start putting the rest of them?
47 extraStackArgsHere :: Int
48 extraStackArgsHere = 23
49
50
51 {-# SPECIALIZE fits13Bits :: Int -> Bool, Integer -> Bool #-}
52 -- | Check whether an offset is representable with 13 bits.
53 fits13Bits :: Integral a => a -> Bool
54 fits13Bits x = x >= -4096 && x < 4096
55
56 -- | Check whether an integer will fit in 32 bits.
57 --      A CmmInt is intended to be truncated to the appropriate 
58 --      number of bits, so here we truncate it to Int64.  This is
59 --      important because e.g. -1 as a CmmInt might be either
60 --      -1 or 18446744073709551615.
61 --
62 is32BitInteger :: Integer -> Bool
63 is32BitInteger i 
64         = i64 <= 0x7fffffff && i64 >= -0x80000000
65         where i64 = fromIntegral i :: Int64
66
67
68 -- | Sadness.
69 largeOffsetError :: Integral a => a -> b
70 largeOffsetError i
71   = panic ("ERROR: SPARC native-code generator cannot handle large offset ("
72                 ++ show i ++ ");\nprobably because of large constant data structures;" ++ 
73                 "\nworkaround: use -fvia-C on this module.\n")
74
75