get_defines
3.18 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python
# Script for parsing source code file and extracting compile flags and options
# 2020 Roman Bartosinski, daiteq s.r.o.
#
# Line begins with:
# //A: assembler flags
# //C: C compiler flags
# //D: selection of data types for specific testing framework
import sys
meta={}
#print(sys.argv)
if len(sys.argv)>2:
onlytype = sys.argv[2]
else:
onlytype = None
try:
if len(sys.argv)<2:
raise Exception('no arg')
with open(sys.argv[1]) as f:
content = f.readlines()
# print(content)
for ln in content:
# skip unsupported lines
if not ln.startswith('//'):
continue
if (len(ln)<5) or (ln[3]!=':'):
continue
ctp = ln[2]
if (onlytype is not None) and (ctp!=onlytype[0]):
continue
# get data types
if ctp=='D':
if 'D' not in meta:
meta['D'] = ""
f = ln.find("'")
i = ln.find("=")
if f<0:
f = 3
l = len(ln)
else:
l = ln.rfind("'")
if i<0:
i = l
args = ln[f+1:i]
if i<l:
res = ln[i+1:l]
else:
res = ''
#print(args)
i = args.find(',')
if i<0:
a1 = args.strip()
a2 = "none"
else:
a1 = args[0:i].strip()
a2 = args[i+1:].strip()
if a1=='half':
meta['D'] += " -DPAR_A_HALF=1"
elif a1=='float':
meta['D'] += " -DPAR_A_SINGLE=1"
elif a1=='double':
meta['D'] += " -DPAR_A_DOUBLE=1"
elif a1=='int32':
meta['D'] += " -DPAR_A_INT32=1"
elif a1=='packhalf':
meta['D'] += " -DPAR_A_PACKHALF=1"
else:
meta['D'] += " -DPAR_A_NONE=1"
if a2=='none':
meta['D'] += " -DPAR_B_NONE=1"
elif a2=='half':
meta['D'] += " -DPAR_B_HALF=1"
elif a2=='float':
meta['D'] += " -DPAR_B_SINGLE=1"
elif a2=='double':
meta['D'] += " -DPAR_B_DOUBLE=1"
elif a2=='int32':
meta['D'] += " -DPAR_B_INT32=1"
elif a2=='packhalf':
meta['D'] += " -DPAR_B_PACKHALF=1"
res = res.strip()
if res=='half':
meta['D'] += " -DRES_HALF=1"
elif res=='float':
meta['D'] += " -DRES_SINGLE=1"
elif res=='double':
meta['D'] += " -DRES_DOUBLE=1"
elif res=='int32':
meta['D'] += " -DRES_INT32=1"
elif res=='packhalf':
meta['D'] += " -DRES_PACKHALF=1"
else:
meta['D'] += " -DRES_NONE=1"
# get list of compilator flags
if ctp=='C':
if 'C' not in meta:
meta['C'] = []
f = ln.find("'")
if f<0:
f = 4
l = len(ln)
else:
l = ln.rfind("'")
meta['C'].append(ln[f+1:l].strip())
# get assembler flags
if ctp=='A':
if 'A' not in meta:
meta['A'] = ""
f = ln.find("'")
if f<0:
f = 4
l = len(ln)
else:
l = ln.rfind("'")
meta['A'] += " " + ln[f+1:l].strip()
except:
if 'D' not in meta:
meta['D'] = ""
meta['D'] += " -DNOTREADY"
sys.exit
if onlytype is not None:
if onlytype in meta:
if isinstance(meta[onlytype], str):
print(meta[onlytype])
else:
print("\n".join(meta[onlytype]))
else:
print(meta)