commit c6f1ad352ce73e2530f44118c8aba6961376544f Author: David Malcolm dmalcolm@redhat.com Date: Wed Jun 29 19:43:57 2011 -0400
Add an optional name to CFG renderings, along with other tweaks
gccutils.py | 27 +++++++++++++++++++++------ show-ssa.py | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) --- diff --git a/gccutils.py b/gccutils.py index 4eb4f3a..fa21012 100644 --- a/gccutils.py +++ b/gccutils.py @@ -258,8 +258,10 @@ except ImportError:
class CfgPrettyPrinter(DotPrettyPrinter): # Generate graphviz source for this gcc.Cfg instance, as a string - def __init__(self, cfg): + def __init__(self, cfg, name=None): self.cfg = cfg + if name: + self.name = name
def block_id(self, b): if b is self.cfg.entry: @@ -313,7 +315,7 @@ class CfgPrettyPrinter(DotPrettyPrinter): # For now, paint assignments to (PyObject*) vars and to ob_refcnt # fields, to highlight the areas needing tracking: # print 'stmt: %s' % stmt - if hasattr(stmt, 'lhs'): + if 0: # hasattr(stmt, 'lhs'): # print 'stmt.lhs: %s' % stmt.lhs # print 'stmt.lhs: %r' % stmt.lhs if stmt.lhs: @@ -352,9 +354,19 @@ class CfgPrettyPrinter(DotPrettyPrinter): return (' %s -> %s %s;\n' % (self.block_id(e.src), self.block_id(e.dest), attrliststr))
+ def extra_items(self): + # Hook for expansion + return '' + def to_dot(self): - result = 'digraph G {\n' - result += ' node [shape=record];\n' + if hasattr(self, 'name'): + name = self.name + else: + name = 'G' + result = 'digraph %s {\n' % name + result += ' subgraph cluster_cfg {\n' + #result += ' label="CFG";\n' + result += ' node [shape=box];\n' for block in self.cfg.basic_blocks:
result += (' %s [label=<%s>];\n' @@ -365,7 +377,10 @@ class CfgPrettyPrinter(DotPrettyPrinter): # FIXME: this will have duplicates: #for edge in block.preds: # result += edge_to_dot(edge) + result += ' }\n'
+ # Potentially add extra material: + result += self.extra_items() result += '}\n' return result
@@ -439,8 +454,8 @@ class TreePrettyPrinter(DotPrettyPrinter): result += '}\n' return result
-def cfg_to_dot(cfg): - pp = CfgPrettyPrinter(cfg) +def cfg_to_dot(name, cfg): + pp = CfgPrettyPrinter(name, cfg) return pp.to_dot()
diff --git a/show-ssa.py b/show-ssa.py index a2c9b25..794b01c 100644 --- a/show-ssa.py +++ b/show-ssa.py @@ -36,7 +36,7 @@ def my_pass_execution_callback(*args, **kwargs): print 'fun.cfg.entry.succs: %r' % fun.cfg.entry.succs print 'fun.cfg.exit.preds: %r' % fun.cfg.exit.preds
- dot = cfg_to_dot(fun.cfg) + dot = cfg_to_dot(fun.cfg, fun.decl.name) print dot invoke_dot(dot)
gcc-python-plugin-commits@lists.stg.fedorahosted.org