ce7b97bd86bf8b3903d6b16613fea581bd7c7b7d
[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
53 targetRealRegSqueeze :: Platform -> RegClass -> RealReg -> FastInt
54 targetRealRegSqueeze platform
55 = case platformArch platform of
56 ArchX86 -> X86.realRegSqueeze
57 ArchX86_64 -> X86.realRegSqueeze
58 ArchPPC -> PPC.realRegSqueeze
59 ArchSPARC -> SPARC.realRegSqueeze
60 ArchPPC_64 -> panic "targetRealRegSqueeze ArchPPC_64"
61 ArchARM _ _ -> panic "targetRealRegSqueeze ArchARM"
62
63 targetClassOfRealReg :: Platform -> RealReg -> RegClass
64 targetClassOfRealReg platform
65 = case platformArch platform of
66 ArchX86 -> X86.classOfRealReg
67 ArchX86_64 -> X86.classOfRealReg
68 ArchPPC -> PPC.classOfRealReg
69 ArchSPARC -> SPARC.classOfRealReg
70 ArchPPC_64 -> panic "targetClassOfRealReg ArchPPC_64"
71 ArchARM _ _ -> panic "targetClassOfRealReg ArchARM"
72
73 -- TODO: This should look at targetPlatform too
74 targetWordSize :: Size
75 targetWordSize = intSize wordWidth
76
77 targetMkVirtualReg :: Platform -> Unique -> Size -> VirtualReg
78 targetMkVirtualReg platform
79 = case platformArch platform of
80 ArchX86 -> X86.mkVirtualReg
81 ArchX86_64 -> X86.mkVirtualReg
82 ArchPPC -> PPC.mkVirtualReg
83 ArchSPARC -> SPARC.mkVirtualReg
84 ArchPPC_64 -> panic "targetMkVirtualReg ArchPPC_64"
85 ArchARM _ _ -> panic "targetMkVirtualReg ArchARM"
86
87 targetRegDotColor :: Platform -> RealReg -> SDoc
88 targetRegDotColor platform
89 = case platformArch platform of
90 ArchX86 -> X86.regDotColor platform
91 ArchX86_64 -> X86.regDotColor platform
92 ArchPPC -> PPC.regDotColor
93 ArchSPARC -> SPARC.regDotColor
94 ArchPPC_64 -> panic "targetRegDotColor ArchPPC_64"
95 ArchARM _ _ -> panic "targetRegDotColor ArchARM"
96
97
98 targetClassOfReg :: Platform -> Reg -> RegClass
99 targetClassOfReg platform reg
100 = case reg of
101 RegVirtual vr -> classOfVirtualReg vr
102 RegReal rr -> targetClassOfRealReg platform rr
103
104