-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_fpga.py
191 lines (182 loc) · 6.45 KB
/
make_fpga.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
################################################################################
# make_fpga.py
# A part of make-fpga - see https://github.com/amb5l/make-fpga
# Shared functions.
################################################################################
import sys,os,argparse
def error_exit(s):
sys.exit(sys.argv[0]+': error: '+s)
def process_src(src,work):
l=[] # list of tuples, each comprising lib and source
d={} # dict of libraries, each containing all sources
s=[]
is_lib=False
for a in src:
for i in a:
if is_lib:
if i not in d:
d[i]=[]
l+=[(i,e) for e in s]
d[i]+=s
s=[]
is_lib=False
elif '=' in i: # src=lib,=lib or =
if i.split('=')[0]: # src specified
s.append(i.split('=')[0])
if i.split('=')[1]: # lib specified
if i.split('=')[1] not in d:
d[i.split('=')[1]]=[]
l+=[(i.split('=')[1],e) for e in s]
d[i.split('=')[1]]+=s
s=[]
else:
is_lib=True # defer
else:
s.append(i)
if s:
if work not in d:
d[work]=[]
l+=[(work,e) for e in s]
d[work]+=s
return l,d
# run spec: top[,gen][;sdf] for single run or name:top[,gen][;sdf]
# [name:]top[,gen][;sdf]
def process_run(run):
# list of runs, each comprising [name,top,gen,sdf]
# where gen = list of tuples (name,value)
# sdf = list of triplets (delay,path,file)
r=[]
for s in run:
# get name and top (or default to 'sim')
l = len(s)
if ';' in s:
l = s.index(';') # first semicolon demarks SDF or is part of generic
if ',' in s[:l]:
l = s[:l].index(',') # first comma before first semicolon must demark generics
if ':' in s[:l]:
name = s[:l].split(':')[0]
top = s[:l].split(':')[1]
else:
name = 'sim'
top = s[:l]
r.append([name,top,[],[]])
s = s[l:]
# generic section: ,name=value[,name=value...]
if s:
while s[0] == ',' and s.find('=') != -1:
s = s[1:]
n = s[:s.find('=')]
v = s[s.find('=')+1:]
sq = False # inside single quotes
dq = False # inside double quotes
for i in range(len(v)):
if i == len(v)-1:
s = ""
elif (v[i] == ',' or v[i] == ';') and not sq and not dq:
s = v[i:]
v = v[:i]
break
elif v[i] == "'":
sq = not sq
elif v[i] == '"':
dq = not dq
# ensure double quotes around strings
if ' ' in v and v[0] != '"':
v = '"'+v+'"'
r[-1][2].append((n,v))
if not s:
break
# SDF section: ;sdfxxx:path=file
while s and s[0] == ';':
s = s[1:]
if ':' not in s:
error_exit('bad SDF section in run spec:\n %s' % s)
delay = s.split(':')[0]
if delay != 'typ' and delay != 'min' and delay != 'max':
error_exit('bad SDF delay in run spec: %s' % delay)
path,file = s[s.index(':')+1:].split('=')
if ';' in file:
file = file.split(';')[0]
s = file[file.index(';'):]
else:
s = ''
r[-1][3].append((delay,path,file))
# finale
if s:
error_exit('unexpected text in run spec:\n %s' % s)
return r
def process_gen(gen):
if gen:
for i in range(len(gen)):
s = gen[i]
n,v = s.split('=')
sq = False # inside single quotes
dq = False # inside double quotes
for j in range(len(v)):
if (v[j] == ',' or v[j] == ';') and not sq and not dq:
v = v[:j]
s = v[j:]
break
elif s[j] == "'":
sq = not sq
elif s[j] == '"':
dq = not dq
if ' ' in v and v[0] != '"': # ensure double quotes around strings
v = '"'+v+'"'
gen[i] = (n,v)
return gen
else:
return []
def process_sdf(sdf):
if sdf:
for i in range(len(sdf)):
s = sdf[i]
if ':' not in s:
error_exit('bad SDF mapping: %s' % s)
delay = s.split(':')[0]
if delay != 'typ' and delay != 'min' and delay != 'max':
error_exit('bad SDF delay: %s' % delay)
path,file = s[s.index(':')+1:].split('=')
sdf[i] = (delay,path,file)
return sdf
else:
return []
def flatten(ll):
return [] if ll==None else [e for l in ll for e in l]
def var_vals(l):
if l:
if len(l)==1:
return l[0]
else:
return ' \\\n\t'+' \\\n\t'.join(l)
else:
return ''
help_run = \
'A generic assignment is specified as follows:\n' \
' name=value\n' \
'Examples:\n' \
' my_int=123\n' \
' my_str="abc"\n' \
' my_slv="101"\n' \
'\n' \
'An SDF mapping is specified as follows:\n' \
' delay:path=file\n' \
'where\n' \
' delay = typ, min or max\n' \
' unit = path to design unit e.g. /top/u1\n' \
' file = path/name of SDF file\n' \
'\n' \
'A simulation run is specified as follow:\n' \
' [name:]top[,gen][;sdf]\n' \
'where\n' \
' name = unique run name (defaults to sim)\n' \
' top = top design unit\n' \
' gen = run specific generic assignments:\n' \
' name=value[,name=value...]\n' \
' sdf = run specific SDF assignments:\n' \
' delay:unit=file[;delay=unit=file...]\n' \
'Examples:\n' \
' run1:my_design1\n' \
' run2:my_design2,gen1=123,gen2="abc"\n' \
' run3:my_design3,gen1=123,gen2="abc";typ:/TOP/UNIT1=unit1.sdf\n' \
' run4:my_design4,gen1=123;typ=/TOP/U1=unit1.sdf;min:/TOP/U2=unit2.sdf\n'