summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-11-30 10:15:05 +0100
committertomsmeding <tom.smeding@gmail.com>2019-11-30 10:15:52 +0100
commit39e6a2117e62e7022005e3e29ce40355e9387244 (patch)
tree3f504efa13c7cfc05d66a4a528a9a1e6610914c6
parentfe61bf61f9a1e12cd758f1e196e44d472992089f (diff)
Annotate GFD entry points in IRProgram show output
-rw-r--r--Intermediate.hs12
1 files 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 = "<<UNKNOWN>>"
-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 ++