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