-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracer.py
43 lines (36 loc) · 1.03 KB
/
tracer.py
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
37
38
39
40
41
42
43
import sys
filename = sys.argv[1]
def marker(annot, depth, bnum):
return 'errs() << __func__ << "-' + \
annot + str(depth) + '-' + str(bnum) + '\\n";'
def ifFirstWordIsIn(ss, listOfWords):
if len(ss.split()) == 0: return False
return ss.split()[0] in listOfWords
newf = ''
with open(filename) as f_in:
depth = 0
bnum = 0
multiline_comment = False
for chunk in f_in:
ignoreLine = False
for i,ch in enumerate(chunk):
newf+=ch
if multiline_comment:
if ch == '*' and chunk[i+1] == '/':
multiline_comment = False
elif not ignoreLine:
if ch == '{':
depth+=1
bnum+=1
newf+=marker('entr', depth, bnum)
elif ch == '}':
newf= newf[:-1] + marker('exit', depth, bnum) + '}'
depth-=1
elif ch == '/':
nchar = chunk[i+1]
if nchar == '/':
ignoreLine = True;
elif nchar == '*':
multiline_comment = True
with open('trace.out', 'w') as f_out:
f_out.write(newf)