-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhlsparser.py
74 lines (60 loc) · 2.58 KB
/
hlsparser.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
# HLS report parser.
# Author: Tiago Lascasas dos Santos
# Available on Github: https://github.com/tiagolascasas/Vivado-HLS-Report-Parser/blob/master/hlsparser.py
import sys
import csv
import xml.etree.ElementTree as ET
from os import path
usage = '''
Usage:
\thlsparser <path to report> <name of input code> <optimizations>
\t - <path to report>: Relative path to the csynth.xml file (including the file)
\t Alternatively, use -d to assume default location
\t - <name of the input code>: Benchmark name, with commas if it has spaces
\t - <optimizations>: Optimizations performed, with commas if it has spaces
'''
def main(argv):
if len(argv) != 4:
print(usage)
return 1
report = {}
if argv[1] == "-d":
argv[1] = "solution1/syn/report/csynth.xml"
try:
root = ET.parse(argv[1]).getroot()
except OSError:
print("Unable to read specified report file \"" + argv[1] + "\", aborting...")
return 1
print(root)
user_assign = root.find('UserAssignments')
perf_estim = root.find('PerformanceEstimates')
area_estim = root.find('AreaEstimates/Resources')
report['input'] = argv[2]
report['optimizations'] = argv[3]
report['part'] = user_assign.find('Part').text
report['target_clock'] = user_assign.find('TargetClockPeriod').text
report['estim_clock'] = perf_estim.find('SummaryOfTimingAnalysis/EstimatedClockPeriod').text
report['lat_worst'] = perf_estim.find('SummaryOfOverallLatency/Worst-caseLatency').text
report['lat_avg'] = perf_estim.find('SummaryOfOverallLatency/Average-caseLatency').text
report['lat_best'] = perf_estim.find('SummaryOfOverallLatency/Best-caseLatency').text
report['FF'] = area_estim.find('FF').text
report['LUT'] = area_estim.find('LUT').text
report['BRAM'] = area_estim.find('BRAM_18K').text
report['DSP'] = area_estim.find('DSP48E').text
fieldnames = report.keys()
if path.exists('reports.csv'):
print("reports.csv found in current directory, adding...")
with open('reports.csv', 'a', newline='') as output:
writer = csv.DictWriter(output, fieldnames=fieldnames)
writer.writerow(report)
else:
with open('reports.csv', 'w', newline='') as output:
print("reports.csv not found, creating...")
writer = csv.DictWriter(output, fieldnames=fieldnames)
writer.writeheader()
writer.writerow(report)
print("Report for \"" + report['input'] + "\" successfully added to reports.csv")
return 0
if __name__ == "__main__":
main(sys.argv)