module SPARC.CodeGen.Sanity (
checkBlock
)
where
import GhcPrelude
import SPARC.Instr
import SPARC.Ppr ()
import Instruction
import Cmm
import Outputable
checkBlock :: CmmBlock
-> NatBasicBlock Instr
-> NatBasicBlock Instr
checkBlock :: CmmBlock -> NatBasicBlock Instr -> NatBasicBlock Instr
checkBlock cmm :: CmmBlock
cmm block :: NatBasicBlock Instr
block@(BasicBlock _ instrs :: [Instr]
instrs)
| [Instr] -> Bool
checkBlockInstrs [Instr]
instrs
= NatBasicBlock Instr
block
| Bool
otherwise
= String -> SDoc -> NatBasicBlock Instr
forall a. HasCallStack => String -> SDoc -> a
pprPanic
("SPARC.CodeGen: bad block\n")
( [SDoc] -> SDoc
vcat [ String -> SDoc
text " -- cmm -----------------\n"
, CmmBlock -> SDoc
forall a. Outputable a => a -> SDoc
ppr CmmBlock
cmm
, String -> SDoc
text " -- native code ---------\n"
, NatBasicBlock Instr -> SDoc
forall a. Outputable a => a -> SDoc
ppr NatBasicBlock Instr
block ])
checkBlockInstrs :: [Instr] -> Bool
checkBlockInstrs :: [Instr] -> Bool
checkBlockInstrs ii :: [Instr]
ii
| instr :: Instr
instr : NOP : _ <- [Instr]
ii
, Instr -> Bool
isUnconditionalJump Instr
instr
= Bool
True
| instr :: Instr
instr : NOP : is :: [Instr]
is <- [Instr]
ii
, Instr -> Bool
forall instr. Instruction instr => instr -> Bool
isJumpishInstr Instr
instr
= [Instr] -> Bool
checkBlockInstrs [Instr]
is
| _:i2 :: Instr
i2:is :: [Instr]
is <- [Instr]
ii
= [Instr] -> Bool
checkBlockInstrs (Instr
i2Instr -> [Instr] -> [Instr]
forall a. a -> [a] -> [a]
:[Instr]
is)
| Bool
otherwise
= Bool
False