[improve grin graph some, highlight tail calls, print grin code to file name_grin.txt
John Meacham <john@repetae.net>**20060429234219] hunk ./Grin/Show.hs 6
+    hPrintGrin,
hunk ./Grin/Show.hs 13
+import Data.Maybe
+import IO
hunk ./Grin/Show.hs 32
-import Data.Graph.Inductive.Graphviz
+import Data.Graph.Inductive.Basic(elfilter)
+import Util.Graphviz
hunk ./Grin/Show.hs 125
-printGrin Grin { grinFunctions = ds', grinCafs = cafs } = do
+printGrin grin = hPrintGrin stderr grin
+
+hPrintGrin :: Handle -> Grin -> IO ()
+hPrintGrin handle Grin { grinFunctions = ds', grinCafs = cafs } = do
hunk ./Grin/Show.hs 130
-        putErrLn "-- Cafs"
-        mapM_ (putErrLn) $ map (\(x,y) -> show x ++ " = " ++  render (prettyVal y))  cafs
-    putErrLn "-- Functions"
-    mapM_ (putErrLn . render) $ map prettyFun ds'
+        hPutStrLn handle "-- Cafs"
+        mapM_ (hPutStrLn handle) $ map (\(x,y) -> show x ++ " = " ++  render (prettyVal y))  cafs
+    hPutStrLn handle "-- Functions"
+    mapM_ (hPutStrLn handle . render) $ map prettyFun ds'
hunk ./Grin/Show.hs 161
+{-# NOINLINE graphGrin #-}
hunk ./Grin/Show.hs 164
-graphGrin grin = graphviz' (gr :: Gr Atom CallType) where
+graphGrin grin = graphviz' gr fnode fedge  where
hunk ./Grin/Show.hs 167
-    gr = nmap fst $ mkGraph nodes [ (n,n2,tc) | (n,(_,_ :-> l)) <- nodes, (tc,fv) <- Set.toList (freeVars l), n2 <- Map.lookup fv nodeMap ]
+    gr :: Gr (Atom,Lam) CallType
+    gr =   mkGraph nodes [ (n,n2,tc) | (n,(_,_ :-> l)) <- nodes, (tc,fv) <- Set.toList (freeVars l), n2 <- Map.lookup fv nodeMap ]
+    fnode :: (Atom,Lam) -> [(String,String)]
+    fnode (x,_ :-> e) = [("label",show x)] ++ if hasError e then [("color","red")] else []
+    fedge :: CallType -> [(String,String)]
+    fedge TailCall = []
+    fedge StandardCall = [("style","dotted")]
+
+hasError x = isNothing (hasError' x)
+hasError' Error {} = Nothing
+hasError' e = mapExpExp hasError' e
hunk ./Main.hs 14
-import IO(hFlush,stderr,stdout)
+import IO(hFlush,stderr,stdout,openFile,hClose,IOMode(..))
hunk ./Main.hs 693
+    let fn = optOutName options
hunk ./Main.hs 696
-            fn = optOutName options
hunk ./Main.hs 697
+    h <- openFile (fn ++ "_grin.txt") WriteMode
+    hPrintGrin h grin
+    hClose h