-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdodo.py
executable file
·227 lines (175 loc) · 5.48 KB
/
dodo.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env -S doit -v2 -f
import os
import glob
from doit.action import CmdAction
from doit.tools import Interactive
from functools import partial
DOIT_CONFIG = {"default_tasks": ["elaborate:Top"], "backend": "sqlite3"}
# PNR_ARGS = "--pcf icestick.pcf --freq 60 --hx1k --package tq144"
PNR_ARGS = "--pcf icestick.pcf --freq 12 --hx1k --package tq144"
TOP_BLOCKS = [
"Alu",
"Core",
"Decoder",
"Memory",
"RegFile",
"System",
"Top",
]
def get_scala_sources():
return glob.glob("./eepyu/src/**/*.scala", recursive=True)
def get_scala_test_sources():
return glob.glob("./eepyu/**/*.scala", recursive=True)
def get_bin_sources(block):
return glob.glob(f"./simWorkspace/{block}/{block}.**.bin")
def get_mill_cmd(cmd, verilator=False):
if verilator:
os.environ["EEPYU_SIM_OPTS"] = "verilator"
else:
os.environ["EEPYU_SIM_OPTS"] = "iverilog"
return f"./mill {cmd}"
def get_edit_file_cmd(top):
editor = os.environ.get("EDITOR")
return f"{editor} out/{top}.v"
def with_oss_cad_suite(cmd):
return "source /opt/oss-cad-suite/environment && " + cmd
def task_elaborate():
for top in TOP_BLOCKS:
yield {
"name": top,
"actions": [get_mill_cmd(f"eepyu.runMain eepyu.{top}Verilog")],
"file_dep": get_scala_sources(),
"targets": [f"out/{top}.v"],
}
yield {"name": None, "task_dep": ["elaborate:Top"]}
def task_verilog():
for top in TOP_BLOCKS:
yield {
"name": top,
"actions": [Interactive(get_edit_file_cmd(top))],
"file_dep": [f"out/{top}.v"],
"uptodate": [False],
}
yield {"name": None, "task_dep": ["verilog:Top"]}
def task_sim():
for top in TOP_BLOCKS:
yield {
"name": top,
"actions": [get_mill_cmd(f"eepyu.runMain eepyu.{top}Sim")],
"file_dep": get_scala_sources(),
"uptodate": [False],
}
yield {"name": None, "task_dep": ["sim:Top"]}
def task_wave():
for top in TOP_BLOCKS:
wave_file = f"simWorkspace/{top}/test.vcd"
yield {
"name": top,
"actions": [Interactive(f"gtkwave {wave_file}")],
"file_dep": [wave_file],
"uptodate": [False],
}
yield {"name": None, "task_dep": ["wave:Top"]}
def task_test():
def get_test_cmd(top, sub_test, verilator):
if verilator:
cmd = with_oss_cad_suite(
get_mill_cmd(f"eepyu.test.testOnly eepyu.{top}Tests", True)
)
else:
# For now, we have to run iverilog outside the OSS cad suite.
cmd = get_mill_cmd(f"eepyu.test.testOnly eepyu.{top}Tests")
# ScalaTest syntax to run specific commands
if len(sub_test) > 0:
cmd += " -- -z " + sub_test
return cmd
for top in TOP_BLOCKS:
yield {
"name": top,
"actions": [CmdAction(partial(get_test_cmd, top))],
"params": [
{"name": "sub_test", "short": "t", "default": ""},
{
"name": "verilator",
"long": "verilator",
"type": bool,
"default": False,
},
],
"file_dep": get_scala_sources() + get_scala_test_sources(),
"uptodate": [False],
"verbosity": 2,
}
def task_synthesize():
return {
"actions": [
with_oss_cad_suite(
'yosys -p "synth_ice40 -top Top -json out/Top.json" out/Top.v out/BlackboxRTL.v'
)
],
"file_dep": ["out/Top.v", "out/BlackboxRTL.v"] + get_bin_sources("Top"),
"targets": ["out/Top.json"],
}
def task_show():
for top in TOP_BLOCKS:
yield {
"name": top,
"actions": [
with_oss_cad_suite(
f'yosys -p "read_verilog out/Top.v out/BlackboxRTL.v; opt; show {top}"'
)
],
"file_dep": ["out/Top.v", "out/BlackboxRTL.v"],
"uptodate": [False],
}
yield {"name": None, "task_dep": ["elaborate:Core"]}
def task_pnr():
return {
"actions": [
with_oss_cad_suite(
f"nextpnr-ice40 --json out/Top.json --asc out/Top.asc {PNR_ARGS}"
)
],
"file_dep": ["out/Top.json"],
"targets": ["out/Top.asc"],
}
def task_gui():
return {
"actions": [
Interactive(
with_oss_cad_suite(
f"nextpnr-ice40 --json out/Top.json {PNR_ARGS} --gui"
)
)
],
"file_dep": ["out/Top.json"],
"uptodate": [False],
}
def task_pack():
return {
"actions": [with_oss_cad_suite("icepack out/Top.asc out/Top.bin")],
"file_dep": ["out/Top.asc"],
"targets": ["out/Top.bin"],
}
def task_flash():
return {
"actions": [with_oss_cad_suite("iceprog out/Top.bin")],
"file_dep": ["out/Top.bin"],
}
def task_util():
return {
"actions": [
with_oss_cad_suite(
f"nextpnr-ice40 --pack-only --json out/Top.json {PNR_ARGS}"
)
],
"file_dep": ["out/Top.json"],
"uptodate": [False],
}
def task_timing():
return {
"actions": [with_oss_cad_suite("icetime -d hx1k -t out/Top.asc")],
"file_dep": ["out/Top.asc"],
"uptodate": [False],
"verbosity": 2,
}