Revert "Remove ArchUnknown"
[ghc.git] / compiler / nativeGen / TargetReg.hs
1
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
12 module TargetReg (
13 targetVirtualRegSqueeze,
14 targetRealRegSqueeze,
15 targetClassOfRealReg,
16 targetMkVirtualReg,
17 targetWordSize,
18 targetRegDotColor,
19 targetClassOfReg
20 )
21
22 where
23
24 #include "HsVersions.h"
25
26 import Reg
27 import RegClass
28 import Size
29
30 import CmmType (wordWidth)
31 import Outputable
32 import Unique
33 import FastTypes
34 import Platform
35
36 import qualified X86.Regs as X86
37 import qualified X86.RegInfo as X86
38
39 import qualified PPC.Regs as PPC
40
41 import qualified SPARC.Regs as SPARC
42
43 targetVirtualRegSqueeze :: Platform -> RegClass -> VirtualReg -> FastInt
44 targetVirtualRegSqueeze platform
45 = case platformArch platform of
46 ArchX86 -> X86.virtualRegSqueeze
47 ArchX86_64 -> X86.virtualRegSqueeze
48 ArchPPC -> PPC.virtualRegSqueeze
49 ArchSPARC -> SPARC.virtualRegSqueeze
50 ArchPPC_64 -> panic "targetVirtualRegSqueeze ArchPPC_64"
51 ArchARM _ _ -> panic "targetVirtualRegSqueeze ArchARM"
52 ArchUnknown -> panic "targetVirtualRegSqueeze ArchUnknown"
53
54 targetRealRegSqueeze :: Platform -> RegClass -> RealReg -> FastInt
55 targetRealRegSqueeze platform
56 = case platformArch platform of
57 ArchX86 -> X86.realRegSqueeze
58 ArchX86_64 -> X86.realRegSqueeze
59 ArchPPC -> PPC.realRegSqueeze
60 ArchSPARC -> SPARC.realRegSqueeze
61 ArchPPC_64 -> panic "targetRealRegSqueeze ArchPPC_64"
62 ArchARM _ _ -> panic "targetRealRegSqueeze ArchARM"
63 ArchUnknown -> panic "targetRealRegSqueeze ArchUnknown"
64
65 targetClassOfRealReg :: Platform -> RealReg -> RegClass
66 targetClassOfRealReg platform
67 = case platformArch platform of
68 ArchX86 -> X86.classOfRealReg
69 ArchX86_64 -> X86.classOfRealReg
70 ArchPPC -> PPC.classOfRealReg
71 ArchSPARC -> SPARC.classOfRealReg
72 ArchPPC_64 -> panic "targetClassOfRealReg ArchPPC_64"
73 ArchARM _ _ -> panic "targetClassOfRealReg ArchARM"
74 ArchUnknown -> panic "targetClassOfRealReg ArchUnknown"
75
76 -- TODO: This should look at targetPlatform too
77 targetWordSize :: Size
78 targetWordSize = intSize wordWidth
79
80 targetMkVirtualReg :: Platform -> Unique -> Size -> VirtualReg
81 targetMkVirtualReg platform
82 = case platformArch platform of
83 ArchX86 -> X86.mkVirtualReg
84 ArchX86_64 -> X86.mkVirtualReg
85 ArchPPC -> PPC.mkVirtualReg
86 ArchSPARC -> SPARC.mkVirtualReg
87 ArchPPC_64 -> panic "targetMkVirtualReg ArchPPC_64"
88 ArchARM _ _ -> panic "targetMkVirtualReg ArchARM"
89 ArchUnknown -> panic "targetMkVirtualReg ArchUnknown"
90
91 targetRegDotColor :: Platform -> RealReg -> SDoc
92 targetRegDotColor platform
93 = case platformArch platform of
94 ArchX86 -> X86.regDotColor platform
95 ArchX86_64 -> X86.regDotColor platform
96 ArchPPC -> PPC.regDotColor
97 ArchSPARC -> SPARC.regDotColor
98 ArchPPC_64 -> panic "targetRegDotColor ArchPPC_64"
99 ArchARM _ _ -> panic "targetRegDotColor ArchARM"
100 ArchUnknown -> panic "targetRegDotColor ArchUnknown"
101
102
103 targetClassOfReg :: Platform -> Reg -> RegClass
104 targetClassOfReg platform reg
105 = case reg of
106 RegVirtual vr -> classOfVirtualReg vr
107 RegReal rr -> targetClassOfRealReg platform rr
108
109