{-# LANGUAGE CPP #-}
-- | 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 (
        targetVirtualRegSqueeze,
        targetRealRegSqueeze,
        targetClassOfRealReg,
        targetMkVirtualReg,
        targetRegDotColor,
        targetClassOfReg
)

where

#include "HsVersions.h"

import GhcPrelude

import Reg
import RegClass
import Format

import Outputable
import Unique
import GHC.Platform

import qualified X86.Regs       as X86
import qualified X86.RegInfo    as X86

import qualified PPC.Regs       as PPC

import qualified SPARC.Regs     as SPARC

targetVirtualRegSqueeze :: Platform -> RegClass -> VirtualReg -> Int
targetVirtualRegSqueeze :: Platform -> RegClass -> VirtualReg -> Int
targetVirtualRegSqueeze Platform
platform
    = case Platform -> Arch
platformArch Platform
platform of
      Arch
ArchX86       -> RegClass -> VirtualReg -> Int
X86.virtualRegSqueeze
      Arch
ArchX86_64    -> RegClass -> VirtualReg -> Int
X86.virtualRegSqueeze
      Arch
ArchPPC       -> RegClass -> VirtualReg -> Int
PPC.virtualRegSqueeze
      Arch
ArchS390X     -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchS390X"
      Arch
ArchSPARC     -> RegClass -> VirtualReg -> Int
SPARC.virtualRegSqueeze
      Arch
ArchSPARC64   -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchSPARC64"
      ArchPPC_64 PPC_64ABI
_  -> RegClass -> VirtualReg -> Int
PPC.virtualRegSqueeze
      ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchARM"
      Arch
ArchARM64     -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchARM64"
      Arch
ArchAlpha     -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchAlpha"
      Arch
ArchMipseb    -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchMipseb"
      Arch
ArchMipsel    -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchMipsel"
      Arch
ArchJavaScript-> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchJavaScript"
      Arch
ArchUnknown   -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic String
"targetVirtualRegSqueeze ArchUnknown"


targetRealRegSqueeze :: Platform -> RegClass -> RealReg -> Int
targetRealRegSqueeze :: Platform -> RegClass -> RealReg -> Int
targetRealRegSqueeze Platform
platform
    = case Platform -> Arch
platformArch Platform
platform of
      Arch
ArchX86       -> RegClass -> RealReg -> Int
X86.realRegSqueeze
      Arch
ArchX86_64    -> RegClass -> RealReg -> Int
X86.realRegSqueeze
      Arch
ArchPPC       -> RegClass -> RealReg -> Int
PPC.realRegSqueeze
      Arch
ArchS390X     -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchS390X"
      Arch
ArchSPARC     -> RegClass -> RealReg -> Int
SPARC.realRegSqueeze
      Arch
ArchSPARC64   -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchSPARC64"
      ArchPPC_64 PPC_64ABI
_  -> RegClass -> RealReg -> Int
PPC.realRegSqueeze
      ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchARM"
      Arch
ArchARM64     -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchARM64"
      Arch
ArchAlpha     -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchAlpha"
      Arch
ArchMipseb    -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchMipseb"
      Arch
ArchMipsel    -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchMipsel"
      Arch
ArchJavaScript-> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchJavaScript"
      Arch
ArchUnknown   -> String -> RegClass -> RealReg -> Int
forall a. String -> a
panic String
"targetRealRegSqueeze ArchUnknown"

targetClassOfRealReg :: Platform -> RealReg -> RegClass
targetClassOfRealReg :: Platform -> RealReg -> RegClass
targetClassOfRealReg Platform
platform
    = case Platform -> Arch
platformArch Platform
platform of
      Arch
ArchX86       -> Platform -> RealReg -> RegClass
X86.classOfRealReg Platform
platform
      Arch
ArchX86_64    -> Platform -> RealReg -> RegClass
X86.classOfRealReg Platform
platform
      Arch
ArchPPC       -> RealReg -> RegClass
PPC.classOfRealReg
      Arch
ArchS390X     -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchS390X"
      Arch
ArchSPARC     -> RealReg -> RegClass
SPARC.classOfRealReg
      Arch
ArchSPARC64   -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchSPARC64"
      ArchPPC_64 PPC_64ABI
_  -> RealReg -> RegClass
PPC.classOfRealReg
      ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchARM"
      Arch
ArchARM64     -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchARM64"
      Arch
ArchAlpha     -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchAlpha"
      Arch
ArchMipseb    -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchMipseb"
      Arch
ArchMipsel    -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchMipsel"
      Arch
ArchJavaScript-> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchJavaScript"
      Arch
ArchUnknown   -> String -> RealReg -> RegClass
forall a. String -> a
panic String
"targetClassOfRealReg ArchUnknown"

targetMkVirtualReg :: Platform -> Unique -> Format -> VirtualReg
targetMkVirtualReg :: Platform -> Unique -> Format -> VirtualReg
targetMkVirtualReg Platform
platform
    = case Platform -> Arch
platformArch Platform
platform of
      Arch
ArchX86       -> Unique -> Format -> VirtualReg
X86.mkVirtualReg
      Arch
ArchX86_64    -> Unique -> Format -> VirtualReg
X86.mkVirtualReg
      Arch
ArchPPC       -> Unique -> Format -> VirtualReg
PPC.mkVirtualReg
      Arch
ArchS390X     -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchS390X"
      Arch
ArchSPARC     -> Unique -> Format -> VirtualReg
SPARC.mkVirtualReg
      Arch
ArchSPARC64   -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchSPARC64"
      ArchPPC_64 PPC_64ABI
_  -> Unique -> Format -> VirtualReg
PPC.mkVirtualReg
      ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchARM"
      Arch
ArchARM64     -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchARM64"
      Arch
ArchAlpha     -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchAlpha"
      Arch
ArchMipseb    -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchMipseb"
      Arch
ArchMipsel    -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchMipsel"
      Arch
ArchJavaScript-> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchJavaScript"
      Arch
ArchUnknown   -> String -> Unique -> Format -> VirtualReg
forall a. String -> a
panic String
"targetMkVirtualReg ArchUnknown"

targetRegDotColor :: Platform -> RealReg -> SDoc
targetRegDotColor :: Platform -> RealReg -> SDoc
targetRegDotColor Platform
platform
    = case Platform -> Arch
platformArch Platform
platform of
      Arch
ArchX86       -> Platform -> RealReg -> SDoc
X86.regDotColor Platform
platform
      Arch
ArchX86_64    -> Platform -> RealReg -> SDoc
X86.regDotColor Platform
platform
      Arch
ArchPPC       -> RealReg -> SDoc
PPC.regDotColor
      Arch
ArchS390X     -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchS390X"
      Arch
ArchSPARC     -> RealReg -> SDoc
SPARC.regDotColor
      Arch
ArchSPARC64   -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchSPARC64"
      ArchPPC_64 PPC_64ABI
_  -> RealReg -> SDoc
PPC.regDotColor
      ArchARM ArmISA
_ [ArmISAExt]
_ ArmABI
_ -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchARM"
      Arch
ArchARM64     -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchARM64"
      Arch
ArchAlpha     -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchAlpha"
      Arch
ArchMipseb    -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchMipseb"
      Arch
ArchMipsel    -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchMipsel"
      Arch
ArchJavaScript-> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchJavaScript"
      Arch
ArchUnknown   -> String -> RealReg -> SDoc
forall a. String -> a
panic String
"targetRegDotColor ArchUnknown"


targetClassOfReg :: Platform -> Reg -> RegClass
targetClassOfReg :: Platform -> Reg -> RegClass
targetClassOfReg Platform
platform Reg
reg
 = case Reg
reg of
   RegVirtual VirtualReg
vr -> VirtualReg -> RegClass
classOfVirtualReg VirtualReg
vr
   RegReal RealReg
rr -> Platform -> RealReg -> RegClass
targetClassOfRealReg Platform
platform RealReg
rr