never executed always true always false
1 module GHC.CmmToAsm.SPARC.CodeGen.Amode (
2 getAmode
3 )
4
5 where
6
7 import GHC.Prelude
8
9 import {-# SOURCE #-} GHC.CmmToAsm.SPARC.CodeGen.Gen32
10 import GHC.CmmToAsm.SPARC.CodeGen.Base
11 import GHC.CmmToAsm.SPARC.AddrMode
12 import GHC.CmmToAsm.SPARC.Imm
13 import GHC.CmmToAsm.SPARC.Instr
14 import GHC.CmmToAsm.SPARC.Regs
15 import GHC.CmmToAsm.SPARC.Base
16 import GHC.CmmToAsm.Monad
17 import GHC.CmmToAsm.Format
18
19 import GHC.Cmm
20
21 import GHC.Data.OrdList
22
23
24 -- | Generate code to reference a memory address.
25 getAmode
26 :: CmmExpr -- ^ expr producing an address
27 -> NatM Amode
28
29 getAmode tree@(CmmRegOff _ _)
30 = do platform <- getPlatform
31 getAmode (mangleIndexTree platform tree)
32
33 getAmode (CmmMachOp (MO_Sub _) [x, CmmLit (CmmInt i _)])
34 | fits13Bits (-i)
35 = do
36 (reg, code) <- getSomeReg x
37 let
38 off = ImmInt (-(fromInteger i))
39 return (Amode (AddrRegImm reg off) code)
40
41
42 getAmode (CmmMachOp (MO_Add _) [x, CmmLit (CmmInt i _)])
43 | fits13Bits i
44 = do
45 (reg, code) <- getSomeReg x
46 let
47 off = ImmInt (fromInteger i)
48 return (Amode (AddrRegImm reg off) code)
49
50 getAmode (CmmMachOp (MO_Add _) [x, y])
51 = do
52 (regX, codeX) <- getSomeReg x
53 (regY, codeY) <- getSomeReg y
54 let
55 code = codeX `appOL` codeY
56 return (Amode (AddrRegReg regX regY) code)
57
58 getAmode (CmmLit lit)
59 = do
60 let imm__2 = litToImm lit
61 tmp1 <- getNewRegNat II32
62 tmp2 <- getNewRegNat II32
63
64 let code = toOL [ SETHI (HI imm__2) tmp1
65 , OR False tmp1 (RIImm (LO imm__2)) tmp2]
66
67 return (Amode (AddrRegReg tmp2 g0) code)
68
69 getAmode other
70 = do
71 (reg, code) <- getSomeReg other
72 let
73 off = ImmInt 0
74 return (Amode (AddrRegImm reg off) code)