fix haddock submodule pointer
[ghc-hetmet.git] / compiler / nativeGen / SPARC / CodeGen / Base.hs
1
2 module SPARC.CodeGen.Base (
3         InstrBlock,
4         CondCode(..),
5         ChildCode64(..),
6         Amode(..),
7
8         Register(..),
9         setSizeOfRegister,
10         
11         getRegisterReg,
12         mangleIndexTree
13 )
14
15 where
16
17 import SPARC.Instr
18 import SPARC.Cond
19 import SPARC.AddrMode
20 import SPARC.Regs
21 import SPARC.RegPlate
22 import Size
23 import Reg
24
25 import OldCmm
26 import OldPprCmm ()
27
28 import Outputable
29 import OrdList
30
31 --------------------------------------------------------------------------------
32 -- | 'InstrBlock's are the insn sequences generated by the insn selectors.
33 --      They are really trees of insns to facilitate fast appending, where a
34 --      left-to-right traversal yields the insns in the correct order.
35 --
36 type InstrBlock 
37         = OrdList Instr
38
39
40 -- | Condition codes passed up the tree.
41 --
42 data CondCode   
43         = CondCode Bool Cond InstrBlock
44
45
46 -- | a.k.a "Register64"
47 --      Reg is the lower 32-bit temporary which contains the result. 
48 --      Use getHiVRegFromLo to find the other VRegUnique.  
49 --
50 --      Rules of this simplified insn selection game are therefore that
51 --      the returned Reg may be modified
52 --
53 data ChildCode64        
54    = ChildCode64 
55         InstrBlock
56         Reg             
57
58
59 -- | Holds code that references a memory address.
60 data Amode 
61         = Amode 
62                 -- the AddrMode we can use in the instruction 
63                 --      that does the real load\/store.
64                 AddrMode        
65
66                 -- other setup code we have to run first before we can use the
67                 --      above AddrMode.
68                 InstrBlock      
69
70
71
72 --------------------------------------------------------------------------------
73 -- | Code to produce a result into a register.
74 --      If the result must go in a specific register, it comes out as Fixed.
75 --      Otherwise, the parent can decide which register to put it in.
76 --
77 data Register
78         = Fixed Size Reg InstrBlock
79         | Any   Size (Reg -> InstrBlock)
80
81
82 -- | Change the size field in a Register.
83 setSizeOfRegister
84         :: Register -> Size -> Register
85
86 setSizeOfRegister reg size
87  = case reg of
88         Fixed _ reg code        -> Fixed size reg code
89         Any _ codefn            -> Any   size codefn
90
91
92 --------------------------------------------------------------------------------
93 -- | Grab the Reg for a CmmReg
94 getRegisterReg :: CmmReg -> Reg
95
96 getRegisterReg (CmmLocal (LocalReg u pk))
97         = RegVirtual $ mkVirtualReg u (cmmTypeSize pk)
98
99 getRegisterReg (CmmGlobal mid)
100   = case globalRegMaybe mid of
101         Just reg -> RegReal reg
102         Nothing  -> pprPanic
103                         "SPARC.CodeGen.Base.getRegisterReg: global is in memory"
104                         (ppr $ CmmGlobal mid)
105
106
107 -- Expand CmmRegOff.  ToDo: should we do it this way around, or convert
108 -- CmmExprs into CmmRegOff?
109 mangleIndexTree :: CmmExpr -> CmmExpr
110
111 mangleIndexTree (CmmRegOff reg off)
112         = CmmMachOp (MO_Add width) [CmmReg reg, CmmLit (CmmInt (fromIntegral off) width)]
113         where width = typeWidth (cmmRegType reg)
114
115 mangleIndexTree _
116         = panic "SPARC.CodeGen.Base.mangleIndexTree: no match"
117
118
119
120