never executed always true always false
1 module GHC.CmmToAsm.SPARC.Imm (
2 -- immediate values
3 Imm(..),
4 strImmLit,
5 litToImm
6 )
7
8 where
9
10 import GHC.Prelude
11
12 import GHC.Cmm
13 import GHC.Cmm.CLabel
14
15 import GHC.Utils.Outputable
16 import GHC.Utils.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 SDoc
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 _ -> panic "SPARC.Regs.litToImm: no match"