module GHC.CmmToAsm.SPARC.CodeGen.Sanity (
checkBlock
)
where
import GHC.Prelude
import GHC.CmmToAsm.SPARC.Instr
import GHC.CmmToAsm.SPARC.Ppr ()
import GHC.CmmToAsm.Instr
import GHC.Cmm
import GHC.Utils.Outputable
checkBlock :: CmmBlock
-> NatBasicBlock Instr
-> NatBasicBlock Instr
checkBlock cmm block@(BasicBlock _ instrs)
| checkBlockInstrs instrs
= block
| otherwise
= pprPanic
("SPARC.CodeGen: bad block\n")
( vcat [ text " -- cmm -----------------\n"
, ppr cmm
, text " -- native code ---------\n"
, ppr 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