File: DSAclean.py

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (36 lines) | stat: -rwxr-xr-x 1,280 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python

# changelog:
# 10/13/2005b: replaced the # in tmp(.#*)* with alphanumeric and _, this will then remove
# nodes such as %tmp.1.i and %tmp._i.3
# 10/13/2005: exntended to remove variables of the form %tmp(.#)* rather than just
#%tmp.#, i.e. it now will remove %tmp.12.3.15 etc, additionally fixed a spelling error in
# the comments
# 10/12/2005: now it only removes nodes and edges for which the label is %tmp.# rather
# than removing all lines for which the lable CONTAINS %tmp.#

from __future__ import print_function

import re
import sys

if len(sys.argv) < 3:
    print("usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>")
    sys.exit(1)
# get a file object
input = open(sys.argv[1], "r")
output = open(sys.argv[2], "w")
# we'll get this one line at a time...while we could just put the whole thing in a string
# it would kill old computers
buffer = input.readline()
while buffer != "":
    if re.compile('label(\s*)=(\s*)"\s%tmp(.\w*)*(\s*)"').search(buffer):
        # skip next line, write neither this line nor the next
        buffer = input.readline()
    else:
        # this isn't a tmp Node, we can write it
        output.write(buffer)
    # prepare for the next iteration
    buffer = input.readline()
input.close()
output.close()