brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 1b833ff Raw
37 lines · python
1#!/usr/bin/env python2 3# changelog:4# 10/13/2005b: replaced the # in tmp(.#*)* with alphanumeric and _, this will then remove5# nodes such as %tmp.1.i and %tmp._i.36# 10/13/2005: exntended to remove variables of the form %tmp(.#)* rather than just7#%tmp.#, i.e. it now will remove %tmp.12.3.15 etc, additionally fixed a spelling error in8# the comments9# 10/12/2005: now it only removes nodes and edges for which the label is %tmp.# rather10# than removing all lines for which the lable CONTAINS %tmp.#11 12from __future__ import print_function13 14import re15import sys16 17if len(sys.argv) < 3:18    print("usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>")19    sys.exit(1)20# get a file object21input = open(sys.argv[1], "r")22output = open(sys.argv[2], "w")23# we'll get this one line at a time...while we could just put the whole thing in a string24# it would kill old computers25buffer = input.readline()26while buffer != "":27    if re.compile('label(\s*)=(\s*)"\s%tmp(.\w*)*(\s*)"').search(buffer):28        # skip next line, write neither this line nor the next29        buffer = input.readline()30    else:31        # this isn't a tmp Node, we can write it32        output.write(buffer)33    # prepare for the next iteration34    buffer = input.readline()35input.close()36output.close()37