Eliminate IF_ARCH_sparc
[ghc-hetmet.git] / compiler / nativeGen / SPARC / Imm.hs
1
2 module SPARC.Imm (
3         -- immediate values
4         Imm(..),
5         strImmLit,
6         litToImm
7 )
8
9 where
10
11 import OldCmm
12 import CLabel
13 import BlockId
14
15 import Pretty
16 import Panic
17
18 -- | An immediate value.
19 --      Not all of these are directly representable by the machine. 
20 --      Things like ImmLit are slurped out and put in a data segment instead.
21 --
22 data Imm
23         = ImmInt        Int
24
25         -- Sigh.
26         | ImmInteger    Integer     
27
28         -- AbstractC Label (with baggage)
29         | ImmCLbl       CLabel      
30
31         -- Simple string
32         | ImmLit        Doc         
33         | ImmIndex      CLabel Int
34         | ImmFloat      Rational
35         | ImmDouble     Rational
36
37         | ImmConstantSum  Imm Imm
38         | ImmConstantDiff Imm Imm
39
40         | LO    Imm                
41         | HI    Imm
42
43
44 -- | Create a ImmLit containing this string.
45 strImmLit :: String -> Imm
46 strImmLit s = ImmLit (text s)
47
48
49 -- | Convert a CmmLit to an Imm.
50 --      Narrow to the width: a CmmInt might be out of
51 --      range, but we assume that ImmInteger only contains
52 --      in-range values.  A signed value should be fine here.
53 --
54 litToImm :: CmmLit -> Imm
55 litToImm lit
56  = case lit of
57         CmmInt i w              -> ImmInteger (narrowS w i)
58         CmmFloat f W32          -> ImmFloat f
59         CmmFloat f W64          -> ImmDouble f
60         CmmLabel l              -> ImmCLbl l
61         CmmLabelOff l off       -> ImmIndex l off
62
63         CmmLabelDiffOff l1 l2 off
64          -> ImmConstantSum
65                 (ImmConstantDiff (ImmCLbl l1) (ImmCLbl l2))
66                 (ImmInt off)
67
68         CmmBlock id     -> ImmCLbl (infoTblLbl id)
69         _               -> panic "SPARC.Regs.litToImm: no match"
70
71