{-# LANGUAGE CPP #-}
module X86.RegInfo (
        mkVirtualReg,
        regDotColor
)

where

#include "nativeGen/NCG.h"
#include "HsVersions.h"

import GhcPrelude

import Format
import Reg

import Outputable
import Platform
import Unique

import UniqFM
import X86.Regs


mkVirtualReg :: Unique -> Format -> VirtualReg
mkVirtualReg :: Unique -> Format -> VirtualReg
mkVirtualReg u :: Unique
u format :: Format
format
   = case Format
format of
        FF32    -> Unique -> VirtualReg
VirtualRegSSE Unique
u
        FF64    -> Unique -> VirtualReg
VirtualRegSSE Unique
u
        FF80    -> Unique -> VirtualReg
VirtualRegD   Unique
u
        _other :: Format
_other  -> Unique -> VirtualReg
VirtualRegI   Unique
u

regDotColor :: Platform -> RealReg -> SDoc
regDotColor :: Platform -> RealReg -> SDoc
regDotColor platform :: Platform
platform reg :: RealReg
reg
 = let Just str :: [Char]
str = UniqFM [Char] -> RealReg -> Maybe [Char]
forall key elt. Uniquable key => UniqFM elt -> key -> Maybe elt
lookupUFM (Platform -> UniqFM [Char]
regColors Platform
platform) RealReg
reg
   in [Char] -> SDoc
text [Char]
str

regColors :: Platform -> UniqFM [Char]
regColors :: Platform -> UniqFM [Char]
regColors platform :: Platform
platform = [(Reg, [Char])] -> UniqFM [Char]
forall key elt. Uniquable key => [(key, elt)] -> UniqFM elt
listToUFM (Platform -> [(Reg, [Char])]
normalRegColors Platform
platform [(Reg, [Char])] -> [(Reg, [Char])] -> [(Reg, [Char])]
forall a. [a] -> [a] -> [a]
++ [(Reg, [Char])]
fpRegColors)

normalRegColors :: Platform -> [(Reg,String)]
normalRegColors :: Platform -> [(Reg, [Char])]
normalRegColors platform :: Platform
platform
 | Platform -> Bool
target32Bit Platform
platform = [ (Reg
eax, "#00ff00")
                          , (Reg
ebx, "#0000ff")
                          , (Reg
ecx, "#00ffff")
                          , (Reg
edx, "#0080ff") ]
 | Bool
otherwise            = [ (Reg
rax, "#00ff00"), (Reg
eax, "#00ff00")
                          , (Reg
rbx, "#0000ff"), (Reg
ebx, "#0000ff")
                          , (Reg
rcx, "#00ffff"), (Reg
ecx, "#00ffff")
                          , (Reg
rdx, "#0080ff"), (Reg
edx, "#00ffff")
                          , (Reg
r8,  "#00ff80")
                          , (Reg
r9,  "#008080")
                          , (Reg
r10, "#0040ff")
                          , (Reg
r11, "#00ff40")
                          , (Reg
r12, "#008040")
                          , (Reg
r13, "#004080")
                          , (Reg
r14, "#004040")
                          , (Reg
r15, "#002080") ]

fpRegColors :: [(Reg,String)]
fpRegColors :: [(Reg, [Char])]
fpRegColors =
        [ (Reg
fake0, "#ff00ff")
        , (Reg
fake1, "#ff00aa")
        , (Reg
fake2, "#aa00ff")
        , (Reg
fake3, "#aa00aa")
        , (Reg
fake4, "#ff0055")
        , (Reg
fake5, "#5500ff") ]

        [(Reg, [Char])] -> [(Reg, [Char])] -> [(Reg, [Char])]
forall a. [a] -> [a] -> [a]
++ [Reg] -> [[Char]] -> [(Reg, [Char])]
forall a b. [a] -> [b] -> [(a, b)]
zip ((RegNo -> Reg) -> [RegNo] -> [Reg]
forall a b. (a -> b) -> [a] -> [b]
map RegNo -> Reg
regSingle [24..39]) ([Char] -> [[Char]]
forall a. a -> [a]
repeat "red")