forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vtemplate
executable file
·116 lines (94 loc) · 2.73 KB
/
vtemplate
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
#!/usr/bin/env python
import re
import sys
# maybe https://github.com/fukatani/Pyverilog-1
txt = open(sys.argv[1], 'r').read()
modname = None
params = []
ios = []
for l in txt.split('\n'):
l = l.strip()
# module RAMB18E1 (
m = re.match(r'module (.*) ', l)
if m:
modname = m.group(1)
continue
# input CLKARDCLK,
# input [13:0] ADDRARDADDR,
# output [1:0] DOPBDOP
m = re.match(r'(input|output)( \[([0-9]*):([0:9]*)\] | )([a-zA-Z0-9_ ,]+)', l)
if m:
names = m.group(5)
aio = m.group(1)
for name in names.split(','):
name = name.strip()
if not name:
continue
wout = None
width = m.group(2).strip()
if width:
mw = re.match(r'\[([0-9]*):([0:9]*)\]', width)
wl = int(mw.group(1))
wr = int(mw.group(2))
wout = (wl, wr)
ios.append((name, aio, wout))
continue
# output DPO, SPO,
# input D, WCLK, WE,
m = re.match(r'(input|output)(.*)', l)
if m:
aio = m.group(1)
wout = None
for name in m.group(2).split(','):
name = name.strip()
if not name:
continue
ios.append((name, aio, wout))
# parameter SIM_DEVICE = "VIRTEX6";
m = re.match(r'parameter([ ])([a-zA-Z0-9_]+) = (.+);', l)
if m:
#aio = m.group(1)
name = m.group(2)
defval = m.group(3)
wout = None
params.append((name, wout, defval))
# input A0, A1, A2, A3, A4, A5, D, WCLK, WE;
modinst = modname
print '''\
module my_%s (input clk, input [7:0] din, output [7:0] dout);
parameter LOC = "";
''' % modname
print ' (* LOC=LOC, KEEP, DONT_TOUCH *)'
print ' %s #(' % modname
for pi, p in enumerate(params):
name, wout, defval = p
comma = ',' if pi != len(params) - 1 else ''
print ' .%s(%s)%s' % (name, defval, comma)
print ' ) %s (' % modinst
DII_N = 8
DOI_N = 8
dii = 0
doi = 0
for ioi, io in enumerate(ios):
name, aio, wout = io
comma = ',' if ioi != len(ios) - 1 else ');'
if aio == 'input':
if wout:
n = int(abs(wout[1] - wout[0]) + 1)
if dii + n >= DII_N:
dii = 0
wire = 'din[%d:%d]' % (dii + n, dii)
dii = (dii + n) % DII_N
else:
wire = 'din[%d]' % dii
dii = (dii + 1) % DII_N
else:
if wout:
n = int(abs(wout[1] - wout[0]) + 1)
wire = 'dout[%d:%d]' % (doi + n, doi)
doi = doi + n
else:
wire = 'dout[%d]' % doi
doi += 1
print ' .%s(%s)%s' % (name, wire, comma)
print 'endmodule'