diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | scripts/gdb_pretty_printer.py | 19 | ||||
-rw-r--r-- | scripts/mir_to_dot.py | 119 |
3 files changed, 143 insertions, 0 deletions
@@ -14,6 +14,8 @@ /crates.io /test_deps_run-pass.mk +/tools/bin + /output /vsproject/Win32 /vsproject/x64 @@ -37,6 +39,9 @@ /gitstats +/lib/libproc_macro/Cargo.lock +/lib/libproc_macro/target + /bnf/*.o /bnf/*.dep /bnf/.gen/ diff --git a/scripts/gdb_pretty_printer.py b/scripts/gdb_pretty_printer.py new file mode 100644 index 00000000..55e5eb26 --- /dev/null +++ b/scripts/gdb_pretty_printer.py @@ -0,0 +1,19 @@ +import gdb + +class EnumPrinter(object): + def __init__(self, val): + # TODO: Support NonZero optimised enums + self.tag = int(val['TAG']) + self.var_data = val['DATA']['var_%i' % (self.tag,)] + def to_string(self): + return "var %i" % (self.tag,) + def children(self): + for f in self.var_data.type.fields(): + yield (f.name, self.var_data[f.name],) + return + +def register(): + pp = gdb.printing.RegexpCollectionPrettyPrinter("mrustc") + pp.add_printer('enum', '^e__', EnumPrinter) + return pp +gdb.printing.register_pretty_printer( gdb.current_objfile(), register(), replace=True ) diff --git a/scripts/mir_to_dot.py b/scripts/mir_to_dot.py new file mode 100644 index 00000000..4df784e6 --- /dev/null +++ b/scripts/mir_to_dot.py @@ -0,0 +1,119 @@ +import re + + +class Link(object): + def __init__(self, src, dst, label): + self._src = 'bb%i' % (src,) + self._dst = dst if isinstance(dst, str) else 'bb%i' % (dst,) + self._label = label + +def main(): + + #cratename,pat = 'rustc_lint','fn .*expr_refers_to_this_method.*' + cratename,pat = 'std','fn resize.*HashMap' + #cratename,pat = 'rustc', 'fn tables.*::"rustc"::ty::context::TyCtxt' + + fp = open('output/lib'+cratename+'.hir_3_mir.rs'); + start_pat = re.compile(pat) + def_line = None + for line in fp: + line = line.strip() + if start_pat.match(line) != None: + print "#",line + def_line = line + break + + if def_line is None: + return + + for line in fp: + if line.strip() == "bb0: {": + break + + bbs = [] + cur_bb_lines = [] + level = 2 + for line in fp: + line = line.strip() + if line == "}": + level -= 1 + if level == 0: + break + else: + bbs.append( cur_bb_lines ) + cur_bb_lines = [] + continue + + if "bb" in line and ": {" in line: + level += 1 + continue + + outstr = "" + comment_level = 0 + i = 0 + while i < len(line): + if comment_level > 0: + if line[i:i+2] == '*/': + comment_level -= 1 + i += 2 + continue + if line[i:i+2] == '/*': + comment_level += 1 + i += 2 + continue + if comment_level == 0: + outstr += line[i] + i += 1 + print "#",len(bbs),outstr + + cur_bb_lines.append(outstr) + + goto_regex = re.compile('goto bb(\d+);$') + call_regex = re.compile('.*goto bb(\d+) else bb(\d+)$') + if_regex = re.compile('.*goto bb(\d+); } else { goto bb(\d+); }$') + switch_regex = re.compile('(\d+) => bb(\d+),') + + links = [] + for idx,bb in enumerate(bbs): + if bb[-1] == 'return;': + links.append( Link(idx, 'return', "return") ) + continue + if bb[-1] == 'diverge;': + #links.append( Link(idx, 'panic', "diverge") ) + continue + m = goto_regex.match(bb[-1]) + if m != None: + links.append( Link(idx, int(m.group(1)), "") ) + continue + m = call_regex.match(bb[-1]) + if m != None: + links.append( Link(idx, int(m.group(1)), "ret") ) + #links.append( Link(idx, int(m.group(2)), "panic") ) + continue + m = if_regex.match(bb[-1]) + if m != None: + links.append( Link(idx, int(m.group(1)), "true") ) + links.append( Link(idx, int(m.group(2)), "false") ) + continue + + + for m in switch_regex.finditer(bb[-1]): + links.append( Link(idx, int(m.group(2)), "var%s" % (m.group(1),) ) ) + + + + print "digraph {" + for l in links: + print '"%s" -> "%s" [label="%s"];' % (l._src, l._dst, l._label) + + print "" + for idx,bb in enumerate(bbs): + print '"bb%i" [label="BB%i:' % (idx,idx,), + for stmt in bb: + print '\\n',stmt.replace('"', '\\"'), + print '"];' + print "}" + + +main() + |