xref: /aosp_15_r20/external/llvm/utils/DSAclean.py (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker#! /usr/bin/python
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker#changelog:
4*9880d681SAndroid Build Coastguard Worker#10/13/2005b: replaced the # in tmp(.#*)* with alphanumeric and _, this will then remove
5*9880d681SAndroid Build Coastguard Worker#nodes such as %tmp.1.i and %tmp._i.3
6*9880d681SAndroid Build Coastguard Worker#10/13/2005: exntended to remove variables of the form %tmp(.#)* rather than just
7*9880d681SAndroid Build Coastguard Worker#%tmp.#, i.e. it now will remove %tmp.12.3.15 etc, additionally fixed a spelling error in
8*9880d681SAndroid Build Coastguard Worker#the comments
9*9880d681SAndroid Build Coastguard Worker#10/12/2005: now it only removes nodes and edges for which the label is %tmp.# rather
10*9880d681SAndroid Build Coastguard Worker#than removing all lines for which the lable CONTAINS %tmp.#
11*9880d681SAndroid Build Coastguard Workerimport re
12*9880d681SAndroid Build Coastguard Workerimport sys
13*9880d681SAndroid Build Coastguard Workerif( len(sys.argv) < 3 ):
14*9880d681SAndroid Build Coastguard Worker	print 'usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>'
15*9880d681SAndroid Build Coastguard Worker	sys.exit(1)
16*9880d681SAndroid Build Coastguard Worker#get a file object
17*9880d681SAndroid Build Coastguard Workerinput = open(sys.argv[1], 'r')
18*9880d681SAndroid Build Coastguard Workeroutput = open(sys.argv[2], 'w')
19*9880d681SAndroid Build Coastguard Worker#we'll get this one line at a time...while we could just put the whole thing in a string
20*9880d681SAndroid Build Coastguard Worker#it would kill old computers
21*9880d681SAndroid Build Coastguard Workerbuffer = input.readline()
22*9880d681SAndroid Build Coastguard Workerwhile buffer != '':
23*9880d681SAndroid Build Coastguard Worker	if re.compile("label(\s*)=(\s*)\"\s%tmp(.\w*)*(\s*)\"").search(buffer):
24*9880d681SAndroid Build Coastguard Worker		#skip next line, write neither this line nor the next
25*9880d681SAndroid Build Coastguard Worker		buffer = input.readline()
26*9880d681SAndroid Build Coastguard Worker	else:
27*9880d681SAndroid Build Coastguard Worker		#this isn't a tmp Node, we can write it
28*9880d681SAndroid Build Coastguard Worker		output.write(buffer)
29*9880d681SAndroid Build Coastguard Worker	#prepare for the next iteration
30*9880d681SAndroid Build Coastguard Worker	buffer = input.readline()
31*9880d681SAndroid Build Coastguard Workerinput.close()
32*9880d681SAndroid Build Coastguard Workeroutput.close()
33