module GHC.CmmToAsm.SPARC.CodeGen.Sanity (
checkBlock
)
where
import GHC.Prelude
import GHC.Platform
import GHC.CmmToAsm.SPARC.Instr
import GHC.CmmToAsm.SPARC.Ppr ()
import GHC.CmmToAsm.Types
import GHC.Cmm
import GHC.Utils.Outputable
import GHC.Utils.Panic
checkBlock :: Platform
-> CmmBlock
-> NatBasicBlock Instr
-> NatBasicBlock Instr
checkBlock :: Platform -> CmmBlock -> NatBasicBlock Instr -> NatBasicBlock Instr
checkBlock Platform
platform CmmBlock
cmm block :: NatBasicBlock Instr
block@(BasicBlock BlockId
_ [Instr]
instrs)
| [Instr] -> Bool
checkBlockInstrs [Instr]
instrs
= NatBasicBlock Instr
block
| Bool
otherwise
= forall a. HasCallStack => String -> SDoc -> a
pprPanic
(String
"SPARC.CodeGen: bad block\n")
( [SDoc] -> SDoc
vcat [ String -> SDoc
text String
" -- cmm -----------------\n"
, forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform CmmBlock
cmm
, String -> SDoc
text String
" -- native code ---------\n"
, forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform NatBasicBlock Instr
block ])
checkBlockInstrs :: [Instr] -> Bool
checkBlockInstrs :: [Instr] -> Bool
checkBlockInstrs [Instr]
ii
| Instr
instr : Instr
NOP : [Instr]
_ <- [Instr]
ii
, Instr -> Bool
isUnconditionalJump Instr
instr
= Bool
True
| Instr
instr : Instr
NOP : [Instr]
is <- [Instr]
ii
, Instr -> Bool
isJumpishInstr Instr
instr
= [Instr] -> Bool
checkBlockInstrs [Instr]
is
| Instr
_:Instr
i2:[Instr]
is <- [Instr]
ii
= [Instr] -> Bool
checkBlockInstrs (Instr
i2forall a. a -> [a] -> [a]
:[Instr]
is)
| Bool
otherwise
= Bool
False