From 39e6a2117e62e7022005e3e29ce40355e9387244 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 30 Nov 2019 10:15:05 +0100 Subject: Annotate GFD entry points in IRProgram show output --- Intermediate.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Intermediate.hs b/Intermediate.hs index 62a5d4a..6f4c360 100644 --- a/Intermediate.hs +++ b/Intermediate.hs @@ -82,7 +82,7 @@ instance Show IRProgram where show (IRProgram bbs gfds datas) = intercalate "\n" $ ["IRPROGRAM", "Data Table:"] ++ map (("- " ++) . show) datas ++ ["Global functions:"] ++ map (\(n, gfd) -> "- " ++ n ++ ": " ++ show gfd) (Map.assocs gfds) ++ - ["Blocks:"] ++ [intercalate "\n" (map (genericShowBB icshow termshow) bbs)] + ["Blocks:"] ++ [intercalate "\n" (map (genericShowBB bbannot icshow termshow) bbs)] where annotate s "" = s annotate s a = s ++ " ; " ++ a @@ -95,6 +95,8 @@ instance Show IRProgram where icshow ins@(IData n) = annotate (show ins) (maybe "??" show (datas `safeIndex` n)) icshow ins = annotate (show ins) (refAnnot (allRefs ins)) termshow term = annotate (show term) (refAnnot (allRefs term)) + bidToName = Map.fromList [(bid, n) | (n, GlobFuncDef bid _ _) <- Map.assocs gfds] + bbannot bid = maybe "" ("entry point of " ++) (Map.lookup bid bidToName) instance Show GlobFuncDef where show (GlobFuncDef bbid na []) = "BB " ++ show bbid ++ " (" ++ show na ++ ")" @@ -102,7 +104,7 @@ instance Show GlobFuncDef where "BB " ++ show bbid ++ " (" ++ show na ++ ") (closure slots: " ++ intercalate ", " cs ++ ")" instance Show BB where - show = genericShowBB show show + show = genericShowBB (const "") show show instance Show Ref where show (RConst n) = show n @@ -127,9 +129,9 @@ instance Show Terminator where show IExit = "exit" show IUnknown = "<>" -genericShowBB :: (InsCode -> String) -> (Terminator -> String) -> BB -> String -genericShowBB icshow termshow (BB i inss term) = - "BB " ++ show i ++ +genericShowBB :: (Int -> String) -> (InsCode -> String) -> (Terminator -> String) -> BB -> String +genericShowBB bbannot icshow termshow (BB i inss term) = + "BB " ++ show i ++ (case bbannot i of { "" -> "" ; s -> " ; " ++ s }) ++ concatMap (\(r, ic) -> case r of RNone -> "\n " ++ icshow ic _ -> "\n " ++ show r ++ " <- " ++ icshow ic) inss ++ -- cgit v1.2.3-54-g00ecf