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 cmm block@(BasicBlock _ instrs)
| checkBlockInstrs instrs
= block
| otherwise
= pprPanic
("SPARC.CodeGen: bad block\n")
( vcat [ text " -- cmm -----------------\n"
, pdoc platform cmm
, text " -- native code ---------\n"
, pdoc platform block ])
checkBlockInstrs :: [Instr] -> Bool
checkBlockInstrs ii
| instr : NOP : _ <- ii
, isUnconditionalJump instr
= True
| instr : NOP : is <- ii
, isJumpishInstr instr
= checkBlockInstrs is
| _:i2:is <- ii
= checkBlockInstrs (i2:is)
| otherwise
= False