I ran into a couple of problems with cfg_to_dot.
First, cfg_to_dot seems to pass arguments reversed to CfgPrettyPrinter.
I changed how cfg_to_dot is defined to match CfgPrettyPrinter.
Second, I got errors in block_to_dot_label. Apparently I have a
statement without a location; this winds up as a None object which
doesn't work with get_src_for_loc, or have line or column attributes.
I patched this in a kind of dumb way, maybe something better is possible.
Tom
diff --git a/gccutils.py b/gccutils.py
index fa21012..68a0476 100644
--- a/gccutils.py
+++ b/gccutils.py
@@ -283,14 +283,21 @@ class CfgPrettyPrinter(DotPrettyPrinter):
for stmtidx, stmt in enumerate(bb.gimple):
if curloc != stmt.loc:
curloc = stmt.loc
- code = get_src_for_loc(stmt.loc).rstrip()
+ if curloc:
+ code = get_src_for_loc(curloc).rstrip()
+ line = curloc.line
+ column = curloc.column
+ else:
+ code = '<<no code>>'
+ line = 0
+ column = 0
pseudohtml = self.code_to_html(code)
# print('pseudohtml: %r' % pseudohtml)
result += ('<tr><td align="left">'
- + self.to_html('%4i ' % stmt.loc.line)
+ + self.to_html('%4i ' % line)
+ pseudohtml
+ '<br/>'
- + (' ' * (5 + stmt.loc.column-1)) + '^'
+ + (' ' * (5 + column-1)) + '^'
+ '</td></tr>')
result += '<tr><td></td>' +
self.stmt_to_html(stmt, stmtidx) + '</tr>\n'
@@ -454,8 +461,8 @@ class TreePrettyPrinter(DotPrettyPrinter):
result += '}\n'
return result
-def cfg_to_dot(name, cfg):
- pp = CfgPrettyPrinter(name, cfg)
+def cfg_to_dot(cfg, name = None):
+ pp = CfgPrettyPrinter(cfg, name)
return pp.to_dot()
Show replies by date