{-# 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 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
platform
    = case Platform -> Arch
platformArch Platform
platform of
      ArchX86       -> RegClass -> VirtualReg -> Int
X86.virtualRegSqueeze
      ArchX86_64    -> RegClass -> VirtualReg -> Int
X86.virtualRegSqueeze
      ArchPPC       -> RegClass -> VirtualReg -> Int
PPC.virtualRegSqueeze
      ArchSPARC     -> RegClass -> VirtualReg -> Int
SPARC.virtualRegSqueeze
      ArchSPARC64   -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchSPARC64"
      ArchPPC_64 _  -> RegClass -> VirtualReg -> Int
PPC.virtualRegSqueeze
      ArchARM _ _ _ -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchARM"
      ArchARM64     -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchARM64"
      ArchAlpha     -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchAlpha"
      ArchMipseb    -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchMipseb"
      ArchMipsel    -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchMipsel"
      ArchJavaScript-> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchJavaScript"
      ArchUnknown   -> String -> RegClass -> VirtualReg -> Int
forall a. String -> a
panic "targetVirtualRegSqueeze ArchUnknown"


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

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

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

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


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