{-# OPTIONS_GHC -fno-warn-orphans #-}

-- | Native code generator for PPC architectures
module GHC.CmmToAsm.PPC
   ( ncgPPC
   )
where

import GHC.Prelude

import GHC.CmmToAsm.Instr
import GHC.CmmToAsm.Monad
import GHC.CmmToAsm.Config
import GHC.CmmToAsm.Types

import qualified GHC.CmmToAsm.PPC.Instr   as PPC
import qualified GHC.CmmToAsm.PPC.Ppr     as PPC
import qualified GHC.CmmToAsm.PPC.CodeGen as PPC
import qualified GHC.CmmToAsm.PPC.Regs    as PPC
import qualified GHC.CmmToAsm.PPC.RegInfo as PPC

ncgPPC :: NCGConfig -> NcgImpl RawCmmStatics PPC.Instr PPC.JumpDest
ncgPPC :: NCGConfig -> NcgImpl RawCmmStatics Instr JumpDest
ncgPPC NCGConfig
config = NcgImpl
   { ncgConfig :: NCGConfig
ncgConfig                 = NCGConfig
config
   , cmmTopCodeGen :: RawCmmDecl -> NatM [NatCmmDecl RawCmmStatics Instr]
cmmTopCodeGen             = RawCmmDecl -> NatM [NatCmmDecl RawCmmStatics Instr]
PPC.cmmTopCodeGen
   , generateJumpTableForInstr :: Instr -> Maybe (NatCmmDecl RawCmmStatics Instr)
generateJumpTableForInstr = NCGConfig -> Instr -> Maybe (NatCmmDecl RawCmmStatics Instr)
PPC.generateJumpTableForInstr NCGConfig
config
   , getJumpDestBlockId :: JumpDest -> Maybe BlockId
getJumpDestBlockId        = JumpDest -> Maybe BlockId
PPC.getJumpDestBlockId
   , canShortcut :: Instr -> Maybe JumpDest
canShortcut               = Instr -> Maybe JumpDest
PPC.canShortcut
   , shortcutStatics :: (BlockId -> Maybe JumpDest) -> RawCmmStatics -> RawCmmStatics
shortcutStatics           = (BlockId -> Maybe JumpDest) -> RawCmmStatics -> RawCmmStatics
PPC.shortcutStatics
   , shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr
shortcutJump              = (BlockId -> Maybe JumpDest) -> Instr -> Instr
PPC.shortcutJump
   , pprNatCmmDeclH :: NatCmmDecl RawCmmStatics Instr -> HDoc
pprNatCmmDeclH            = NCGConfig -> NatCmmDecl RawCmmStatics Instr -> HDoc
forall doc.
IsDoc doc =>
NCGConfig -> NatCmmDecl RawCmmStatics Instr -> doc
PPC.pprNatCmmDecl NCGConfig
config
   , pprNatCmmDeclS :: NatCmmDecl RawCmmStatics Instr -> SDoc
pprNatCmmDeclS            = NCGConfig -> NatCmmDecl RawCmmStatics Instr -> SDoc
forall doc.
IsDoc doc =>
NCGConfig -> NatCmmDecl RawCmmStatics Instr -> doc
PPC.pprNatCmmDecl NCGConfig
config
   , maxSpillSlots :: Int
maxSpillSlots             = NCGConfig -> Int
PPC.maxSpillSlots NCGConfig
config
   , allocatableRegs :: [RealReg]
allocatableRegs           = Platform -> [RealReg]
PPC.allocatableRegs Platform
platform
   , ncgAllocMoreStack :: Int
-> NatCmmDecl RawCmmStatics Instr
-> UniqDSM (NatCmmDecl RawCmmStatics Instr, [(BlockId, BlockId)])
ncgAllocMoreStack         = Platform
-> Int
-> NatCmmDecl RawCmmStatics Instr
-> UniqDSM (NatCmmDecl RawCmmStatics Instr, [(BlockId, BlockId)])
forall statics.
Platform
-> Int
-> NatCmmDecl statics Instr
-> UniqDSM (NatCmmDecl statics Instr, [(BlockId, BlockId)])
PPC.allocMoreStack Platform
platform
   , ncgMakeFarBranches :: Platform
-> LabelMap RawCmmStatics
-> [NatBasicBlock Instr]
-> UniqDSM [NatBasicBlock Instr]
ncgMakeFarBranches        = Platform
-> LabelMap RawCmmStatics
-> [NatBasicBlock Instr]
-> UniqDSM [NatBasicBlock Instr]
PPC.makeFarBranches
   , extractUnwindPoints :: [Instr] -> [UnwindPoint]
extractUnwindPoints       = [UnwindPoint] -> [Instr] -> [UnwindPoint]
forall a b. a -> b -> a
const []
   , invertCondBranches :: Maybe CFG
-> LabelMap RawCmmStatics
-> [NatBasicBlock Instr]
-> [NatBasicBlock Instr]
invertCondBranches        = \Maybe CFG
_ LabelMap RawCmmStatics
_ -> [NatBasicBlock Instr] -> [NatBasicBlock Instr]
forall a. a -> a
id
   }
    where
      platform :: Platform
platform = NCGConfig -> Platform
ncgPlatform NCGConfig
config

-- | Instruction instance for powerpc
instance Instruction PPC.Instr where
   regUsageOfInstr :: Platform -> Instr -> RegUsage
regUsageOfInstr     = Platform -> Instr -> RegUsage
PPC.regUsageOfInstr
   patchRegsOfInstr :: HasDebugCallStack => Platform -> Instr -> (Reg -> Reg) -> Instr
patchRegsOfInstr Platform
_  = Instr -> (Reg -> Reg) -> Instr
PPC.patchRegsOfInstr
   isJumpishInstr :: Instr -> Bool
isJumpishInstr      = Instr -> Bool
PPC.isJumpishInstr
   jumpDestsOfInstr :: Instr -> [BlockId]
jumpDestsOfInstr    = Instr -> [BlockId]
PPC.jumpDestsOfInstr
   canFallthroughTo :: Instr -> BlockId -> Bool
canFallthroughTo    = Instr -> BlockId -> Bool
PPC.canFallthroughTo
   patchJumpInstr :: Instr -> (BlockId -> BlockId) -> Instr
patchJumpInstr      = Instr -> (BlockId -> BlockId) -> Instr
PPC.patchJumpInstr
   mkSpillInstr :: HasDebugCallStack =>
NCGConfig -> RegWithFormat -> Int -> Int -> [Instr]
mkSpillInstr        = NCGConfig -> RegWithFormat -> Int -> Int -> [Instr]
PPC.mkSpillInstr
   mkLoadInstr :: HasDebugCallStack =>
NCGConfig -> RegWithFormat -> Int -> Int -> [Instr]
mkLoadInstr         = NCGConfig -> RegWithFormat -> Int -> Int -> [Instr]
PPC.mkLoadInstr
   takeDeltaInstr :: Instr -> Maybe Int
takeDeltaInstr      = Instr -> Maybe Int
PPC.takeDeltaInstr
   isMetaInstr :: Instr -> Bool
isMetaInstr         = Instr -> Bool
PPC.isMetaInstr
   mkRegRegMoveInstr :: HasDebugCallStack => NCGConfig -> Format -> Reg -> Reg -> Instr
mkRegRegMoveInstr NCGConfig
_ = Format -> Reg -> Reg -> Instr
PPC.mkRegRegMoveInstr
   takeRegRegMoveInstr :: Platform -> Instr -> Maybe (Reg, Reg)
takeRegRegMoveInstr Platform
_ = Instr -> Maybe (Reg, Reg)
PPC.takeRegRegMoveInstr
   mkJumpInstr :: BlockId -> [Instr]
mkJumpInstr         = BlockId -> [Instr]
PPC.mkJumpInstr
   mkStackAllocInstr :: Platform -> Int -> [Instr]
mkStackAllocInstr   = Platform -> Int -> [Instr]
PPC.mkStackAllocInstr
   mkStackDeallocInstr :: Platform -> Int -> [Instr]
mkStackDeallocInstr = Platform -> Int -> [Instr]
PPC.mkStackDeallocInstr
   pprInstr :: Platform -> Instr -> SDoc
pprInstr            = Platform -> Instr -> SDoc
forall doc. IsDoc doc => Platform -> Instr -> doc
PPC.pprInstr
   mkComment :: FastString -> [Instr]
mkComment           = Instr -> [Instr]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Instr -> [Instr])
-> (FastString -> Instr) -> FastString -> [Instr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> Instr
PPC.COMMENT