Fix todo in compiler/nativeGen: Rename Size to Format
[ghc.git] / compiler / nativeGen / TargetReg.hs
1 {-# LANGUAGE CPP #-}
2 -- | Hard wired things related to registers.
3 -- This is module is preventing the native code generator being able to
4 -- emit code for non-host architectures.
5 --
6 -- TODO: Do a better job of the overloading, and eliminate this module.
7 -- We'd probably do better with a Register type class, and hook this to
8 -- Instruction somehow.
9 --
10 -- TODO: We should also make arch specific versions of RegAlloc.Graph.TrivColorable
11 module TargetReg (
12 targetVirtualRegSqueeze,
13 targetRealRegSqueeze,
14 targetClassOfRealReg,
15 targetMkVirtualReg,
16 targetRegDotColor,
17 targetClassOfReg
18 )
19
20 where
21
22 #include "HsVersions.h"
23
24 import Reg
25 import RegClass
26 import Format
27
28 import Outputable
29 import Unique
30 import FastTypes
31 import Platform
32
33 import qualified X86.Regs as X86
34 import qualified X86.RegInfo as X86
35
36 import qualified PPC.Regs as PPC
37
38 import qualified SPARC.Regs as SPARC
39
40 targetVirtualRegSqueeze :: Platform -> RegClass -> VirtualReg -> FastInt
41 targetVirtualRegSqueeze platform
42 = case platformArch platform of
43 ArchX86 -> X86.virtualRegSqueeze
44 ArchX86_64 -> X86.virtualRegSqueeze
45 ArchPPC -> PPC.virtualRegSqueeze
46 ArchSPARC -> SPARC.virtualRegSqueeze
47 ArchPPC_64 _ -> PPC.virtualRegSqueeze
48 ArchARM _ _ _ -> panic "targetVirtualRegSqueeze ArchARM"
49 ArchARM64 -> panic "targetVirtualRegSqueeze ArchARM64"
50 ArchAlpha -> panic "targetVirtualRegSqueeze ArchAlpha"
51 ArchMipseb -> panic "targetVirtualRegSqueeze ArchMipseb"
52 ArchMipsel -> panic "targetVirtualRegSqueeze ArchMipsel"
53 ArchJavaScript-> panic "targetVirtualRegSqueeze ArchJavaScript"
54 ArchUnknown -> panic "targetVirtualRegSqueeze ArchUnknown"
55
56
57 targetRealRegSqueeze :: Platform -> RegClass -> RealReg -> FastInt
58 targetRealRegSqueeze platform
59 = case platformArch platform of
60 ArchX86 -> X86.realRegSqueeze
61 ArchX86_64 -> X86.realRegSqueeze
62 ArchPPC -> PPC.realRegSqueeze
63 ArchSPARC -> SPARC.realRegSqueeze
64 ArchPPC_64 _ -> PPC.realRegSqueeze
65 ArchARM _ _ _ -> panic "targetRealRegSqueeze ArchARM"
66 ArchARM64 -> panic "targetRealRegSqueeze ArchARM64"
67 ArchAlpha -> panic "targetRealRegSqueeze ArchAlpha"
68 ArchMipseb -> panic "targetRealRegSqueeze ArchMipseb"
69 ArchMipsel -> panic "targetRealRegSqueeze ArchMipsel"
70 ArchJavaScript-> panic "targetRealRegSqueeze ArchJavaScript"
71 ArchUnknown -> panic "targetRealRegSqueeze ArchUnknown"
72
73 targetClassOfRealReg :: Platform -> RealReg -> RegClass
74 targetClassOfRealReg platform
75 = case platformArch platform of
76 ArchX86 -> X86.classOfRealReg platform
77 ArchX86_64 -> X86.classOfRealReg platform
78 ArchPPC -> PPC.classOfRealReg
79 ArchSPARC -> SPARC.classOfRealReg
80 ArchPPC_64 _ -> PPC.classOfRealReg
81 ArchARM _ _ _ -> panic "targetClassOfRealReg ArchARM"
82 ArchARM64 -> panic "targetClassOfRealReg ArchARM64"
83 ArchAlpha -> panic "targetClassOfRealReg ArchAlpha"
84 ArchMipseb -> panic "targetClassOfRealReg ArchMipseb"
85 ArchMipsel -> panic "targetClassOfRealReg ArchMipsel"
86 ArchJavaScript-> panic "targetClassOfRealReg ArchJavaScript"
87 ArchUnknown -> panic "targetClassOfRealReg ArchUnknown"
88
89 targetMkVirtualReg :: Platform -> Unique -> Format -> VirtualReg
90 targetMkVirtualReg platform
91 = case platformArch platform of
92 ArchX86 -> X86.mkVirtualReg
93 ArchX86_64 -> X86.mkVirtualReg
94 ArchPPC -> PPC.mkVirtualReg
95 ArchSPARC -> SPARC.mkVirtualReg
96 ArchPPC_64 _ -> PPC.mkVirtualReg
97 ArchARM _ _ _ -> panic "targetMkVirtualReg ArchARM"
98 ArchARM64 -> panic "targetMkVirtualReg ArchARM64"
99 ArchAlpha -> panic "targetMkVirtualReg ArchAlpha"
100 ArchMipseb -> panic "targetMkVirtualReg ArchMipseb"
101 ArchMipsel -> panic "targetMkVirtualReg ArchMipsel"
102 ArchJavaScript-> panic "targetMkVirtualReg ArchJavaScript"
103 ArchUnknown -> panic "targetMkVirtualReg ArchUnknown"
104
105 targetRegDotColor :: Platform -> RealReg -> SDoc
106 targetRegDotColor platform
107 = case platformArch platform of
108 ArchX86 -> X86.regDotColor platform
109 ArchX86_64 -> X86.regDotColor platform
110 ArchPPC -> PPC.regDotColor
111 ArchSPARC -> SPARC.regDotColor
112 ArchPPC_64 _ -> PPC.regDotColor
113 ArchARM _ _ _ -> panic "targetRegDotColor ArchARM"
114 ArchARM64 -> panic "targetRegDotColor ArchARM64"
115 ArchAlpha -> panic "targetRegDotColor ArchAlpha"
116 ArchMipseb -> panic "targetRegDotColor ArchMipseb"
117 ArchMipsel -> panic "targetRegDotColor ArchMipsel"
118 ArchJavaScript-> panic "targetRegDotColor ArchJavaScript"
119 ArchUnknown -> panic "targetRegDotColor ArchUnknown"
120
121
122 targetClassOfReg :: Platform -> Reg -> RegClass
123 targetClassOfReg platform reg
124 = case reg of
125 RegVirtual vr -> classOfVirtualReg vr
126 RegReal rr -> targetClassOfRealReg platform rr