From: Nathaniel Wesley Filardo Date: Wed, 15 May 2013 04:40:35 +0000 (-0400) Subject: Improve ./debug X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=e8af9d4b84f6fcb87c0bc1bfb79f550f1700850f;p=dyna2 Improve ./debug --- diff --git a/.gitignore b/.gitignore index d0cef49..a17f27d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ *.pyc dist/ +examples/*.d +examples/*.out +examples/*.plan diff --git a/bin/prototype.js b/external/prototype-1.6.0.3.js old mode 100755 new mode 100644 similarity index 100% rename from bin/prototype.js rename to external/prototype-1.6.0.3.js diff --git a/src/Dyna/Analysis/ANFPretty.hs b/src/Dyna/Analysis/ANFPretty.hs index 2d88e00..7a54bbe 100644 --- a/src/Dyna/Analysis/ANFPretty.hs +++ b/src/Dyna/Analysis/ANFPretty.hs @@ -40,7 +40,7 @@ printANF (Rule rix h a result sp _ cruxes) = pev (CEval n o i) = parens (pretty o <+> pretty i <> char '@' <> pretty n) pev (CCall n o is f) = parens (pretty o <+> pnft (n,(f,is))) - pun (CStruct o is f) = parens (pretty o <+> parens (pft (f,is))) + pun (CStruct o is f) = parens (pretty o <+> parens (char '&' <+> pft (f,is))) pun (CAssign o v ) = parens (pretty o <+> parens (equals <+> pretty v)) pun (CEquals v1 v2 ) = parens (pretty v1 <+> parens (equals <+> pretty v2)) pun (CNotEqu v1 v2 ) = parens (pretty v1 <+> parens (char '!' <+> pretty v2)) diff --git a/src/Dyna/Analysis/DOpAMine.hs b/src/Dyna/Analysis/DOpAMine.hs index 31e018a..1000771 100644 --- a/src/Dyna/Analysis/DOpAMine.hs +++ b/src/Dyna/Analysis/DOpAMine.hs @@ -115,19 +115,23 @@ type BackendRenderDopIter bs e = -- | Given a mechanism for rendering backend-specific information, -- pretty-print a 'DOpAMine' opcode. renderDOpAMine :: BackendRenderDopIter bs e -> DOpAMine bs -> Doc e -renderDOpAMine _ (OPAsgn v n) = text "OPAsgn" <+> pretty v <+> pretty n -renderDOpAMine _ (OPCheq a b) = text "OPCheq" <+> pretty a <+> pretty b -renderDOpAMine _ (OPCkne a b) = text "OPCkne" <+> pretty a <+> pretty b -renderDOpAMine _ (OPIndr a b) = text "OPIndr" <+> pretty a <+> pretty b -renderDOpAMine _ (OPPeel vs v f) = text "OPPeel" <+> pretty vs - <+> pretty v <+> pretty f -renderDOpAMine _ (OPWrap v vs f) = text "OPWrap" <+> pretty v - <+> pretty vs <+> pretty f -renderDOpAMine e (OPIter v vs f d b) = text "OPIter" - <+> pretty v - <+> list (map pretty vs) - <+> squotes (pretty f) - <+> text (show d) - <> maybe empty ((space <>) . braces . e v vs f d) b +renderDOpAMine = r + where + r _ (OPAsgn v n) = text "OPAsgn" <+> pretty v <+> pretty n + r _ (OPCheq a b) = text "OPCheq" <+> pretty a <+> pretty b + r _ (OPCkne a b) = text "OPCkne" <+> pretty a <+> pretty b + r _ (OPIndr a b) = text "OPIndr" <+> pretty a <+> pretty b + r _ (OPPeel vs v f) = text "OPPeel" <+> pretty vs + <+> pretty v <+> pretty f + r _ (OPWrap v vs f) = text "OPWrap" <+> pretty v + <+> pretty vs <+> pretty f + r e (OPIter v vs f d b) = text "OPIter" + <+> pretty v + <+> list (map pretty vs) + <+> squotes (pretty f) + <+> text (show d) + <> maybe empty + ((space <>) . braces . e v vs f d) + b ------------------------------------------------------------------------}}} diff --git a/src/Dyna/Analysis/Mode/Execution/NamedInst.hs b/src/Dyna/Analysis/Mode/Execution/NamedInst.hs index f2819c4..157fe47 100644 --- a/src/Dyna/Analysis/Mode/Execution/NamedInst.hs +++ b/src/Dyna/Analysis/Mode/Execution/NamedInst.hs @@ -108,11 +108,11 @@ instance (Pretty f) => Pretty (NIX f) where UClobbered -> "cl" -- render inst - ri IFree = text "$f" - ri (IAny u) = text "$a@" <> ru u - ri (IUniv u) = text "$u@" <> ru u - ri (IBound u bm b) = ru u - <> (semiBraces $ if b then (text "$b"):rm else rm) + ri IFree = text "F" + ri (IAny u) = text "A@" <> ru u + ri (IUniv u) = text "U@" <> ru u + ri (IBound u bm b) = (semiBraces $ if b then (text "B"):rm else rm) + <> char '@' <> ru u where rm = map (\(k,vs) -> pretty k <> tupled (map rix vs)) (M.toList bm) @@ -290,7 +290,7 @@ nExpose :: NIX f -> InstF f (NIX f) nExpose n@(NIX r m) = fmap (\a -> either id (\i -> NIX i m) (ml n m a)) r {-# INLINABLE nExpose #-} --- | An inefficient \"inverse\" of nExpose. +-- | An inefficient \"inverse\" (up to isomorphism) of nExpose. nHide :: InstF f (NIX f) -> NIX f nHide i = uncurry NIX $ runState (T.mapM next i) M.empty where diff --git a/bin/style.css b/src/Dyna/Backend/Python/debug-pygments.css similarity index 100% rename from bin/style.css rename to src/Dyna/Backend/Python/debug-pygments.css diff --git a/src/Dyna/Backend/Python/debug.py b/src/Dyna/Backend/Python/debug.py index b1bd025..4585a3b 100644 --- a/src/Dyna/Backend/Python/debug.py +++ b/src/Dyna/Backend/Python/debug.py @@ -4,7 +4,7 @@ Generates a visual representation of a Dyna program rules after the normalization process. """ -import re, os +import re, os, shutil from collections import defaultdict, namedtuple from utils import magenta, red, green, yellow, white, read_anf @@ -12,6 +12,8 @@ from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter +cssfile="src/Dyna/Backend/Python/debug-pygments.css" +jsfile="external/prototype-1.6.0.3.js" Edge = namedtuple('Edge', 'head label body') # "body" is sometimes called the "tail" @@ -161,7 +163,10 @@ def circuit(anf): g.edge(head=var, label=op, body=args) for var, op, val in unifs: - g.edge(head=var, label='& %s' % op, body=val) + if op == '&' : + op = '%s %s' % (op,val[0]) + val = val[1:] + g.edge(head=var, label='%s' % op, body=val) g.head = head g.result = result @@ -179,7 +184,9 @@ def graph_styles(g): # edge styles for e in g.edges: - if e.label.startswith('&'): # distiguish unif edges + if e.label.startswith('&') \ + or e.label.startswith('!') \ + or e.label.startswith('=') : # distiguish unif edges sty[e].update({'style': 'filled', 'fillcolor': 'grey'}) # node styles @@ -200,9 +207,16 @@ def graph_styles(g): def main(dynafile): + if not os.path.exists(cssfile) or not os.path.exists(jsfile): + print("Debug must be run from the root of the Dyna source tree") + return + d = dynafile + '.d' os.system('mkdir -p %s' % d) + shutil.copyfile(cssfile,d+"/debug-pygments.css") + shutil.copyfile(jsfile,d+"/prototype.js") + with file(d + '/index.html', 'wb') as html: print >> html, """\ @@ -213,9 +227,10 @@ html, body {margin:0; padding:0;} #dyna-source { position:absolute; height: 95%; width: 42%; top: 10px; left: 0%; padding-left: 10px; } #circuit-pane { position:absolute; width: 50%; top: 10px; left: 42%; padding-left: 5%; } -#update-handler-pane { position: absolute; top: 10px; left: 100%; width: 45%; padding-right: 5%; } +#dopamine-pane { position: absolute; top: 10px; left: 100%; width: 42%; padding-right: 5%; } +#update-handler-pane { position: absolute; top: 10px; left: 150%; width: 45%; padding-right: 5%; } -#dyna-source, #circuit-pane { +#dyna-source, #circuit-pane, #dopamine-pane { border-right: 1px solid #666 } @@ -226,9 +241,9 @@ body { background: black; color: white; } - + - +