summaryrefslogtreecommitdiff
path: root/Intermediate.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Intermediate.hs')
-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 ++