TargetReg.hs 3.89 KB
Newer Older
1

Ian Lynagh's avatar
Ian Lynagh committed
2 3 4 5 6 7 8
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See
--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
-- for details

9 10 11 12 13 14 15 16 17 18 19
-- | Hard wired things related to registers.
--	This is module is preventing the native code generator being able to 
--	emit code for non-host architectures.
--
--	TODO: Do a better job of the overloading, and eliminate this module.
--	We'd probably do better with a Register type class, and hook this to 
--	Instruction somehow.
--
--	TODO: We should also make arch specific versions of RegAlloc.Graph.TrivColorable

module TargetReg (
20 21 22 23
	targetVirtualRegSqueeze,
	targetRealRegSqueeze,
	targetClassOfRealReg,
	targetMkVirtualReg,
24
	targetWordSize,
25 26
	targetRegDotColor,
	targetClassOfReg
27 28 29 30 31 32 33 34 35 36
)

where

#include "HsVersions.h"

import Reg
import RegClass
import Size

37
import CmmType	(wordWidth)
38 39
import Outputable
import Unique
40
import FastTypes
41
import Platform
42

43 44
import qualified X86.Regs       as X86
import qualified X86.RegInfo    as X86
45

46
import qualified PPC.Regs       as PPC
47

48
import qualified SPARC.Regs     as SPARC
49

50 51 52
targetVirtualRegSqueeze :: Platform -> RegClass -> VirtualReg -> FastInt
targetVirtualRegSqueeze platform
    = case platformArch platform of
53 54 55 56 57 58 59
      ArchX86       -> X86.virtualRegSqueeze
      ArchX86_64    -> X86.virtualRegSqueeze
      ArchPPC       -> PPC.virtualRegSqueeze
      ArchSPARC     -> SPARC.virtualRegSqueeze
      ArchPPC_64    -> panic "targetVirtualRegSqueeze ArchPPC_64"
      ArchARM _ _ _ -> panic "targetVirtualRegSqueeze ArchARM"
      ArchUnknown   -> panic "targetVirtualRegSqueeze ArchUnknown"
60

61 62 63
targetRealRegSqueeze :: Platform -> RegClass -> RealReg -> FastInt
targetRealRegSqueeze platform
    = case platformArch platform of
64 65 66 67 68 69 70
      ArchX86       -> X86.realRegSqueeze
      ArchX86_64    -> X86.realRegSqueeze
      ArchPPC       -> PPC.realRegSqueeze
      ArchSPARC     -> SPARC.realRegSqueeze
      ArchPPC_64    -> panic "targetRealRegSqueeze ArchPPC_64"
      ArchARM _ _ _ -> panic "targetRealRegSqueeze ArchARM"
      ArchUnknown   -> panic "targetRealRegSqueeze ArchUnknown"
71

72 73 74
targetClassOfRealReg :: Platform -> RealReg -> RegClass
targetClassOfRealReg platform
    = case platformArch platform of
75 76
      ArchX86       -> X86.classOfRealReg platform
      ArchX86_64    -> X86.classOfRealReg platform
77 78 79 80 81
      ArchPPC       -> PPC.classOfRealReg
      ArchSPARC     -> SPARC.classOfRealReg
      ArchPPC_64    -> panic "targetClassOfRealReg ArchPPC_64"
      ArchARM _ _ _ -> panic "targetClassOfRealReg ArchARM"
      ArchUnknown   -> panic "targetClassOfRealReg ArchUnknown"
82 83 84 85 86

-- TODO: This should look at targetPlatform too
targetWordSize :: Size
targetWordSize = intSize wordWidth

87 88 89
targetMkVirtualReg :: Platform -> Unique -> Size -> VirtualReg
targetMkVirtualReg platform
    = case platformArch platform of
90 91 92 93 94 95 96
      ArchX86       -> X86.mkVirtualReg
      ArchX86_64    -> X86.mkVirtualReg
      ArchPPC       -> PPC.mkVirtualReg
      ArchSPARC     -> SPARC.mkVirtualReg
      ArchPPC_64    -> panic "targetMkVirtualReg ArchPPC_64"
      ArchARM _ _ _ -> panic "targetMkVirtualReg ArchARM"
      ArchUnknown   -> panic "targetMkVirtualReg ArchUnknown"
97

98 99 100
targetRegDotColor :: Platform -> RealReg -> SDoc
targetRegDotColor platform
    = case platformArch platform of
101 102 103 104 105 106 107
      ArchX86       -> X86.regDotColor platform
      ArchX86_64    -> X86.regDotColor platform
      ArchPPC       -> PPC.regDotColor
      ArchSPARC     -> SPARC.regDotColor
      ArchPPC_64    -> panic "targetRegDotColor ArchPPC_64"
      ArchARM _ _ _ -> panic "targetRegDotColor ArchARM"
      ArchUnknown   -> panic "targetRegDotColor ArchUnknown"
108 109


110 111
targetClassOfReg :: Platform -> Reg -> RegClass
targetClassOfReg platform reg
112
 = case reg of
113 114
   RegVirtual vr -> classOfVirtualReg vr
   RegReal rr -> targetClassOfRealReg platform rr
115

116