| 1 |
|
| 2 |
|
| 3 |
import sys |
| 4 |
import re |
| 5 |
|
| 6 |
args = sys.argv[1:] |
| 7 |
assert len(args) == 2, "usage is <bpl-file-name> <trace-to-convert>" |
| 8 |
print args |
| 9 |
|
| 10 |
|
| 11 |
def make_bpl_c_mapping(bpl_filename): |
| 12 |
linenum = 0 |
| 13 |
bpl_c_mapping = {} |
| 14 |
current_bb_line = -1 |
| 15 |
with open(bpl_filename) as bpl_file: |
| 16 |
for line in bpl_file: |
| 17 |
linenum += 1 |
| 18 |
if re.match(r'\$bb\d+', line): |
| 19 |
current_bb_line = linenum |
| 20 |
bpl_c_mapping[current_bb_line] = [] |
| 21 |
|
| 22 |
matchObj = re.match(r' assume {:sourceloc "(.+)", (\d+), (\d+)} true;', line) |
| 23 |
if matchObj: |
| 24 |
matched_filename = matchObj.group(1) |
| 25 |
matched_fileline = matchObj.group(2) |
| 26 |
bpl_c_mapping[current_bb_line].append((matched_filename, matched_fileline)) |
| 27 |
|
| 28 |
return bpl_c_mapping |
| 29 |
|
| 30 |
|
| 31 |
def convert_trace_to_c(trace_filename, bpl_c_mapping): |
| 32 |
with open(trace_filename) as tracefile: |
| 33 |
for line in tracefile: |
| 34 |
matchObj = re.match(r'.*\.bpl\((\d+),\d+\).*', line) |
| 35 |
if matchObj: |
| 36 |
bpl_line = int(matchObj.group(1)) |
| 37 |
if bpl_line in bpl_c_mapping: |
| 38 |
mapping = bpl_c_mapping[bpl_line] |
| 39 |
if len(mapping) > 0: |
| 40 |
print mapping[0] |
| 41 |
else: |
| 42 |
print "No Source Loc" |
| 43 |
else: |
| 44 |
print "unknown basic block" |
| 45 |
|
| 46 |
print "\t\t", matchObj.group(0), matchObj.group(1) |
| 47 |
|
| 48 |
|
| 49 |
bpl_c_mapping = make_bpl_c_mapping(args[0]) |
| 50 |
convert_trace_to_c(args[1], bpl_c_mapping) |