module SPARC.CodeGen.Sanity (
checkBlock
)
where
import SPARC.Instr
import SPARC.Ppr ()
import Instruction
import OldCmm
import Outputable
import Platform
checkBlock :: Platform
-> CmmBasicBlock
-> NatBasicBlock Instr
-> NatBasicBlock Instr
checkBlock platform cmm block@(BasicBlock _ instrs)
| checkBlockInstrs instrs
= block
| otherwise
= pprPanic
("SPARC.CodeGen: bad block\n")
( vcat [ text " -- cmm -----------------\n"
, pprPlatform platform cmm
, text " -- native code ---------\n"
, pprPlatform 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