printMapBB hmap = do
printfBb "BlockIDs: "
let keys = M.keys hmap
- mapM_ (printfBb. (flip (++)) ", " . show) keys
- printfBb "\n\nBasicBlocks:"
+ mapM_ (printfBb . flip (++) ", " . show) keys
+ printfBb "\n\nBasicBlocks:\n"
printMapBB' keys hmap
where
printMapBB' :: [BlockID] -> MapBB -> IO ()
printMapBB' [] _ = return ()
printMapBB' (i:is) hmap' = case M.lookup i hmap' of
Just bb -> do
- printfBb $ "Block " ++ (show i)
- mapM_ printfBb (map ((++) "\t" . show) $ code bb)
+ printfBb $ "Block " ++ show i ++ "\n"
+ mapM_ (printfBb . flip (++) "\n" . (++) "\t" . show) $ code bb
printfBb $ case successor bb of
Return -> ""
- FallThrough t1 -> "Sucessor: " ++ (show t1) ++ "\n"
- OneTarget t1 -> "Sucessor: " ++ (show t1) ++ "\n"
- TwoTarget t1 t2 -> "Sucessor: " ++ (show t1) ++ ", " ++ (show t2) ++ "\n"
+ FallThrough t1 -> "Sucessor: " ++ show t1 ++ "\n"
+ OneTarget t1 -> "Sucessor: " ++ show t1 ++ "\n"
+ TwoTarget t1 t2 -> "Sucessor: " ++ show t1 ++ ", " ++ show t2 ++ "\n"
printMapBB' is hmap
Nothing -> error $ "BlockID " ++ show i ++ " not found."
markBackwardTargets insns@(x@((x_off,x_bbend),x_ins):y@((y_off,_),_):xs) =
x_new:markBackwardTargets (y:xs)
where
- x_new = if isTarget then checkX y_off else x
- checkX w16 = case x_bbend of
+ x_new = case x_bbend of
Just _ -> x -- already marked, don't change
+ Nothing -> if isTarget then checkX y_off else x
+ checkX w16 = case x_bbend of
Nothing -> ((x_off, Just $ FallThrough w16), x_ins) -- mark previous insn
+ _ -> error "basicblock: something is wrong"
-- look through all remaining insns in the stream if there is a jmp to `y'
isTarget = case find cmpOffset insns of Just _ -> True; Nothing -> False