-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
360 lines (310 loc) · 13.4 KB
/
Copy pathMakefile
File metadata and controls
360 lines (310 loc) · 13.4 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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# =============================================================================
# RTL Build System
# =============================================================================
# Tool selection: reads config.mk (generated by rat-init-project).
# Without config.mk, defaults to open-source tools.
#
# make sim TOP=my_module Simulate (preferred or verilator)
# make lint Lint (verilator + verible + slang)
# make syn TOP=my_module Synthesize (preferred or yosys)
# make formal TOP=my_module Formal verify (SymbiYosys)
# make cdc TOP=my_module CDC analysis
# make help Show all targets
#
# Commercial tool examples:
# make sim_xrun TOP=my_module Simulate (Cadence Xcelium)
# make syn_dc TOP=my_module Synthesize (Synopsys DC)
# =============================================================================
.DEFAULT_GOAL := help
# ─── Project config (auto-generated by generate_config.sh) ─────────────────
-include config.mk
# ─── Configuration (config.mk overrides, then defaults) ───────────────────
TOP ?=
FILELIST ?= rtl/filelist_top.f
BUILD_DIR ?= build
LIBERTY ?=
SDC_FILE ?= syn/constraints/design.sdc
SBY_FILE ?= formal/$(TOP).sby
TB ?=
# Tool preferences (from config.mk or defaults)
PREF_SIM ?= verilator
PREF_SYN ?= yosys
PREF_LINT ?= verilator
PREF_FORMAL ?= sby
PREF_CDC ?= structural
# Regression
SEEDS ?= 42 123 456 789 1337
# Script locations (deployed by rat-init-project)
LINT_SCRIPT := lint/scripts/run_lint.sh
SYN_SCRIPT := syn/scripts/run_syn.sh
CDC_SCRIPT := lint/scripts/run_cdc.sh
SIM_SCRIPT := scripts/run_sim.sh
# ─── Internal helpers ───────────────────────────────────────────────────────
define _require_top
$(if $(TOP),,$(error TOP is required. Usage: make $(MAKECMDGOALS) TOP=<module>))
endef
_top_flag = $(if $(TOP),--top $(TOP))
_liberty_flag = $(if $(LIBERTY),--liberty $(LIBERTY))
_sdc_flag = $(if $(SDC_FILE),--sdc $(SDC_FILE))
# Map Makefile sim names to cocotb SIM variable names
_cocotb_sim = $(if $(filter xrun,$(PREF_SIM)),xcelium,$(if $(filter iverilog,$(PREF_SIM)),icarus,$(PREF_SIM)))
# Tool runner wrapper (for targets that call tools directly)
_run_tool = . lib/tool-runner.sh 2>/dev/null && run_tool
# Parse filelist for tools that don't support -f (iverilog)
_src_files = $(or $(shell grep -v '^\s*//' $(FILELIST) 2>/dev/null \
| grep -v '^\s*+' | grep -v '^\s*$$'), \
$(shell find rtl -name '*.sv' -o -name '*.v' 2>/dev/null | sort))
# =============================================================================
# Simulation — default: preferred tool
# =============================================================================
.PHONY: sim sim_verilator sim_iverilog sim_xrun sim_vcs sim_questa sim_regression
sim: sim_$(PREF_SIM)
sim_verilator:
$(call _require_top)
@mkdir -p $(BUILD_DIR)/verilator
verilator --binary -Wall -Wpedantic -sv \
--Wno-TIMESCALEMOD \
--top-module $(TOP) -f $(FILELIST) $(TB) \
--Mdir $(BUILD_DIR)/verilator -o V$(TOP)
$(BUILD_DIR)/verilator/V$(TOP)
sim_iverilog:
$(call _require_top)
@mkdir -p $(BUILD_DIR)
iverilog -g2012 -I rtl/include \
-o $(BUILD_DIR)/$(TOP).vvp \
$(_src_files) $(TB)
vvp $(BUILD_DIR)/$(TOP).vvp
sim_xrun:
$(call _require_top)
xrun -sv -64bit -top $(TOP) \
-f $(FILELIST) $(TB) \
-xmlibdirpath $(BUILD_DIR)/xcelium
sim_vcs:
$(call _require_top)
@mkdir -p $(BUILD_DIR)/vcs
cd $(BUILD_DIR)/vcs && vcs -full64 -sverilog -top $(TOP) \
-f $(abspath $(FILELIST)) $(if $(TB),$(abspath $(TB)),) \
-o simv
cd $(BUILD_DIR)/vcs && ./simv
sim_questa:
$(call _require_top)
@mkdir -p $(BUILD_DIR)/questa
vlib $(BUILD_DIR)/questa/work 2>/dev/null || true
vlog -sv -work $(BUILD_DIR)/questa/work -f $(FILELIST) $(TB)
vsim -c -work $(BUILD_DIR)/questa/work -do "run -all; quit -f" $(TOP)
sim_regression:
$(call _require_top)
@echo "=== cocotb Multi-Seed Regression ==="
@FAIL=0; \
for seed in $(SEEDS); do \
echo "--- Seed: $$seed ---"; \
SIM=$(_cocotb_sim) TOPLEVEL=$(TOP) RANDOM_SEED=$$seed SIM_BUILD=$(BUILD_DIR)/regression/seed_$$seed \
$(MAKE) -C sim/$(TOP) > sim/$(TOP)/regression_seed_$$seed.log 2>&1; \
RC=$$?; cat sim/$(TOP)/regression_seed_$$seed.log; \
if [ $$RC -ne 0 ]; then FAIL=1; fi; \
done; \
echo "=== Regression Complete (seeds: $(SEEDS)) ==="; \
if [ $$FAIL -ne 0 ]; then echo "FAIL: one or more seeds failed"; exit 1; fi
# =============================================================================
# Lint — default: verilator + verible + slang (all open-source)
# =============================================================================
.PHONY: lint lint_spyglass lint_xmvlog
lint:
@echo "=== Running all open-source linters ==="
-$(LINT_SCRIPT) --tool verilator -f $(FILELIST) $(_top_flag)
-$(LINT_SCRIPT) --tool verible -f $(FILELIST)
-$(LINT_SCRIPT) --tool slang -f $(FILELIST) $(_top_flag)
lint_spyglass:
$(call _require_top)
$(LINT_SCRIPT) --tool spyglass --top $(TOP) -f $(FILELIST)
lint_xmvlog:
xmvlog -sv -f $(FILELIST)
# =============================================================================
# Synthesis — default: preferred tool
# =============================================================================
.PHONY: syn syn_yosys syn_dc syn_genus
syn: syn_$(PREF_SYN)
syn_yosys:
$(call _require_top)
$(SYN_SCRIPT) --tool yosys --top $(TOP) -f $(FILELIST) $(_liberty_flag)
syn_dc:
$(call _require_top)
$(SYN_SCRIPT) --tool dc_shell --top $(TOP) -f $(FILELIST) $(_liberty_flag) $(_sdc_flag)
syn_genus:
$(call _require_top)
$(SYN_SCRIPT) --tool genus --top $(TOP) -f $(FILELIST) $(_liberty_flag) $(_sdc_flag)
# =============================================================================
# Formal Verification — default: preferred tool
# =============================================================================
.PHONY: formal formal_sby formal_jasper formal_vcf
formal: formal_$(PREF_FORMAL)
formal_sby:
$(call _require_top)
@mkdir -p formal
cd formal && sby -f $(abspath $(SBY_FILE))
formal_jasper:
$(call _require_top)
$(if $(JASPER_TCL),,$(error JASPER_TCL required. Usage: make formal_jasper TOP=<m> JASPER_TCL=<tcl>))
@mkdir -p formal
cd formal && jg -batch $(abspath $(JASPER_TCL))
formal_vcf:
$(call _require_top)
$(if $(VCF_TCL),,$(error VCF_TCL required. Usage: make formal_vcf TOP=<m> VCF_TCL=<tcl>))
@mkdir -p formal
cd formal && vcf -f $(abspath $(VCF_TCL)) -batch
# =============================================================================
# UVM Verification — commercial simulators only
# =============================================================================
.PHONY: uvm_compile uvm_run uvm_regression uvm_coverage
UVM_TEST ?= base_test
UVM_SIM ?= vcs
UVM_TB_DIR ?= sim/uvm
UVM_REG_SCRIPT := sim/uvm/scripts/run_regression_uvm.sh
uvm_compile:
$(call _require_top)
@echo "=== UVM Compile ($(UVM_SIM)) ==="
ifeq ($(UVM_SIM),vcs)
@mkdir -p build/vcs
cd build/vcs && vcs -full64 -sverilog -ntb_opts uvm-1.2 -cm line+cond+fsm+tgl+branch \
-timescale=1ns/1ps -f $(abspath $(FILELIST)) $(abspath $(UVM_TB_DIR))/*.sv -o simv
else ifeq ($(UVM_SIM),xrun)
xrun -sv -uvm -compile -coverage all -timescale 1ns/1ps \
-f $(FILELIST) $(UVM_TB_DIR)/*.sv -xmlibdirpath build/xcelium
else ifeq ($(UVM_SIM),questa)
vlib build/work 2>/dev/null || true
vlog -sv -work build/work +cover=bcestf +incdir+$(UVM_TB_DIR) -f $(FILELIST) $(UVM_TB_DIR)/*.sv
endif
uvm_run: uvm_compile
$(call _require_top)
@echo "=== UVM Run: $(UVM_TEST) ==="
ifeq ($(UVM_SIM),vcs)
cd build/vcs && ./simv +UVM_TESTNAME=$(UVM_TEST) +ntb_random_seed=42 \
-cm line+cond+fsm+tgl+branch -cm_dir $(abspath sim/uvm/coverage/seed_42.vdb)
else ifeq ($(UVM_SIM),xrun)
xrun -sv -uvm -R +UVM_TESTNAME=$(UVM_TEST) -seed 42 -coverage all \
-xmlibdirpath build/xcelium
else ifeq ($(UVM_SIM),questa)
vsim -c -work build/work -coverage +UVM_TESTNAME=$(UVM_TEST) -sv_seed 42 \
-do "coverage save -onexit sim/uvm/coverage/seed_42.ucdb; run -all; quit -f" tb_top
endif
uvm_regression:
$(call _require_top)
$(UVM_REG_SCRIPT) --sim $(UVM_SIM) --seeds "$(SEEDS)" \
--test $(UVM_TEST) --module $(TOP) --filelist $(FILELIST)
uvm_coverage:
@echo "=== UVM Coverage Report ==="
ifeq ($(UVM_SIM),vcs)
urg -dir sim/uvm/coverage/*.vdb -report sim/uvm/coverage/report -format text
else ifeq ($(UVM_SIM),questa)
vcover merge sim/uvm/coverage/merged.ucdb sim/uvm/coverage/seed_*.ucdb
vcover report -details sim/uvm/coverage/merged.ucdb
endif
# =============================================================================
# CDC Analysis — default: preferred tool
# =============================================================================
.PHONY: cdc cdc_svlens cdc_spyglass
cdc:
$(call _require_top)
$(CDC_SCRIPT) --tool $(PREF_CDC) --top $(TOP) -f $(FILELIST)
cdc_svlens:
$(call _require_top)
$(CDC_SCRIPT) --tool svlens --top $(TOP) -f $(FILELIST)
cdc_spyglass:
$(call _require_top)
$(CDC_SCRIPT) --tool spyglass --top $(TOP) -f $(FILELIST)
# =============================================================================
# Structural Analysis (svlens) — connectivity, metrics, combined
# =============================================================================
.PHONY: conn metrics svlens_all
conn:
$(call _require_top)
$(_run_tool) svlens conn --format all --top $(TOP) -f $(FILELIST) -o sim/conn/reports
metrics:
$(call _require_top)
$(_run_tool) svlens metrics --format all --top $(TOP) -f $(FILELIST) -o sim/metrics/reports
svlens_all:
$(call _require_top)
$(_run_tool) svlens all --format all --top $(TOP) -f $(FILELIST) -o sim/svlens/reports
# =============================================================================
# Utility
# =============================================================================
.PHONY: help clean
help:
@echo ""
@echo "RTL Build System"
@echo "════════════════"
@echo ""
@echo " Simulation (default: $(PREF_SIM))"
@echo " sim Preferred simulator"
@echo " sim_verilator Verilator"
@echo " sim_iverilog Icarus Verilog"
@echo " sim_xrun Cadence Xcelium"
@echo " sim_vcs Synopsys VCS"
@echo " sim_questa Siemens Questa"
@echo " sim_regression cocotb multi-seed regression"
@echo ""
@echo " Lint (default: all open-source)"
@echo " lint Verilator + Verible + slang"
@echo " lint_spyglass Synopsys SpyGlass"
@echo " lint_xmvlog Cadence xmvlog (compile-check)"
@echo ""
@echo " Synthesis (default: $(PREF_SYN))"
@echo " syn Preferred synthesizer"
@echo " syn_yosys Yosys"
@echo " syn_dc Synopsys Design Compiler"
@echo " syn_genus Cadence Genus"
@echo ""
@echo " Formal Verification (default: $(PREF_FORMAL))"
@echo " formal Preferred formal tool"
@echo " formal_sby SymbiYosys"
@echo " formal_jasper Cadence JasperGold"
@echo " formal_vcf Synopsys VC Formal"
@echo ""
@echo " UVM Verification (commercial simulators)"
@echo " uvm_compile Compile UVM environment"
@echo " uvm_run Single test run (UVM_TEST=name)"
@echo " uvm_regression Multi-seed regression (UVM_SEEDS=\"...\")"
@echo " uvm_coverage Merge and report coverage"
@echo ""
@echo " CDC Analysis (default: $(PREF_CDC))"
@echo " cdc Preferred CDC tool"
@echo " cdc_svlens svlens cdc (standalone)"
@echo " cdc_spyglass Synopsys SpyGlass CDC"
@echo ""
@echo " Structural Analysis (svlens)"
@echo " conn Port connectivity analysis"
@echo " metrics RTL transformation complexity"
@echo " svlens_all Combined (cdc + conn + metrics)"
@echo ""
@echo " Utility"
@echo " help Show this help"
@echo " clean Remove all build/synthesis/sim artifacts"
@echo ""
@echo " Variables:"
@echo " TOP=<module> Top-level module (required for sim/syn/formal)"
@echo " FILELIST=<.f> Source filelist (default: rtl/filelist_top.f)"
@echo " TB=<file> Testbench file"
@echo " LIBERTY=<.lib> Liberty file for technology mapping"
@echo " SDC_FILE=<.sdc> SDC constraints (default: syn/constraints/design.sdc)"
@echo " SBY_FILE=<.sby> SymbiYosys config (default: formal/\$$TOP.sby)"
@echo " SEEDS=\"...\" Seed list for regression (default: 42 123 456 789 1337)"
@echo " JASPER_TCL=<tcl> JasperGold script"
@echo " VCF_TCL=<tcl> VC Formal script"
@echo " UVM_SIM=<sim> UVM simulator: vcs|xrun|questa (default: vcs)"
@echo " UVM_TEST=<name> UVM test name (default: base_test)"
@echo ""
@echo " Config: edit config.mk or re-run generate_config.sh to change defaults"
@echo ""
@echo " Examples:"
@echo " make sim TOP=entropy_coder"
@echo " make syn TOP=entropy_coder LIBERTY=lib/sky130_fd_sc_hd.lib"
@echo " make syn_dc TOP=entropy_coder"
@echo " make sim_regression TOP=entropy_coder SEEDS=\"42 123 456\""
@echo " make cdc TOP=entropy_coder"
@echo ""
clean:
rm -rf $(BUILD_DIR)
rm -rf lint/lint lint/cdc
rm -rf syn/db syn/vnet syn/svf syn/scr syn/rpt syn/log syn/temp syn/work
rm -rf sim/build sim/conn/reports sim/metrics/reports sim/svlens/reports
@echo "Cleaned: $(BUILD_DIR)/, lint/{lint,cdc}/, syn/*, sim/build/"