-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (120 loc) · 3.84 KB
/
Makefile
File metadata and controls
147 lines (120 loc) · 3.84 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
INC_DIR := ./include
RTL_SRCS := $(shell find rtl -name '*.sv' -or -name '*.v')
INCLUDE_DIRS := $(sort $(dir $(shell find . -name '*.svh')))
RTL_DIRS := $(sort $(dir $(RTL_SRCS)))
# Include both Include and RTL directories for linting
LINT_INCLUDES := $(foreach dir, $(INCLUDE_DIRS) $(RTL_DIRS), -I$(realpath $(dir))) -I$(PDKPATH)
TEST_DIR = ./tests
TEST_SUBDIRS = $(shell cd $(TEST_DIR) && ls -d */ | grep -v "__pycache__" )
TESTS = $(TEST_SUBDIRS:/=)
# Main Linter and Simulatior is Verilator
LINTER := verilator
SIMULATOR := verilator
SIMULATOR_ARGS := --binary --timing --trace --trace-structs \
--assert --timescale 1ns --quiet
SIMULATOR_BINARY := ./obj_dir/V*
SIMULATOR_SRCS := *.sv
# Optional use of Icarus as Linter and Simulator
ifdef ICARUS
SIMULATOR := iverilog
SIMULATOR_ARGS := -g2012
SIMULATOR_BINARY := a.out
SIMULATOR_SRCS := $(foreach src, $(RTL_SRCS), $(realpath $(src))) *.sv
SIM_TOP := `$(shell pwd)/scripts/top.sh -s`
# LINT_INCLUDES := ""
endif
# Gate Level Verification
ifdef GL
SIMULATOR := iverilog
LINT_INCLUDES := -I$(PDKPATH) -I$(realpath gl)
SIMULATOR_ARGS := -g2012 -DFUNCTIONAL -DUSE_POWER_PINS
SIMULATOR_BINARY := a.out
SIMULATOR_SRCS = $(realpath gl)/* *.sv
endif
LINT_OPTS += --lint-only --timing $(LINT_INCLUDES)
# Text formatting for tests
BOLD = `tput bold`
GREEN = `tput setaf 2`
ORANG = `tput setaf 214`
RED = `tput setaf 1`
RESET = `tput sgr0`
TEST_GREEN := $(shell tput setaf 2)
TEST_ORANGE := $(shell tput setaf 214)
TEST_RED := $(shell tput setaf 1)
TEST_RESET := $(shell tput sgr0)
all: lint_all tests
lint: lint_all
.PHONY: lint_all
lint_all:
@printf "\n$(GREEN)$(BOLD) ----- Linting All Modules ----- $(RESET)\n"
@for src in $(RTL_SRCS); do \
top_module=$$(basename $$src .sv); \
top_module=$$(basename $$top_module .v); \
printf "Linting $$src . . . "; \
if $(LINTER) $(LINT_OPTS) --top-module $$top_module $$src > /dev/null 2>&1; then \
printf "$(GREEN)PASSED$(RESET)\n"; \
else \
printf "$(RED)FAILED$(RESET)\n"; \
$(LINTER) $(LINT_OPTS) --top-module $$top_module $$src; \
fi; \
done
.PHONY: lint_top
lint_top:
@printf "\n$(GREEN)$(BOLD) ----- Linting $(TOP_MODULE) ----- $(RESET)\n"
@printf "Linting Top Level Module: $(TOP_FILE)\n";
$(LINTER) $(LINT_OPTS) --top-module $(TOP_MODULE) $(TOP_FILE)
tests: $(TESTS)
tests/%: FORCE
make -s $(subst /,, $(basename $*))
itests:
@ICARUS=1 make tests
gl_tests:
@mkdir -p gl
@cp runs/recent/final/pnl/* gl/
@cat scripts/gatelevel.vh gl/*.v > gl/temp
@mv -f gl/temp gl/*.v
@rm -f gl/temp
@GL=1 make tests
.PHONY: $(TESTS)
$(TESTS):
@printf "\n$(GREEN)$(BOLD) ----- Running Test: $@ ----- $(RESET)\n"
@printf "\n$(BOLD) Building with $(SIMULATOR)... $(RESET)\n"
# Build With Simulator
@cd $(TEST_DIR)/$@;\
$(SIMULATOR) $(SIMULATOR_ARGS) $(SIMULATOR_SRCS) $(LINT_INCLUDES) $(SIM_TOP) > build.log
@printf "\n$(BOLD) Running... $(RESET)\n"
# Run Binary and Check for Error in Result
@if cd $(TEST_DIR)/$@;\
./$(SIMULATOR_BINARY) > results.log \
&& !( cat results.log | grep -qi error ) \
then \
printf "$(GREEN)PASSED $@$(RESET)\n"; \
else \
printf "$(RED)FAILED $@$(RESET)\n"; \
cat results.log; \
fi; \
COCOTEST_DIR = ./cocotests
COCOTEST_SUBDIRS = $(shell cd $(COCOTEST_DIR) && ls -d */ | grep -v "__pycache__" )
COCOTESTS = $(COCOTEST_SUBDIRS:/=)
.PHONY: cocotests
cocotests:
@$(foreach test, $(COCOTESTS), make -sC $(COCOTEST_DIR)/$(test);)
OPENLANE_CONF ?= config.*
openlane:
@`which openlane` --flow Classic $(OPENLANE_CONF)
@cd runs && rm -f recent && ln -sf `ls | tail -n 1` recent
%.json %.yaml: FORCE
@echo $@
OPENLANE_CONF=$@ make openlane
FORCE: ;
openroad:
scripts/openroad_launch.sh | openroad
.PHONY: clean
clean:
rm -f `find tests -iname "*.vcd"`
rm -f `find tests -iname "a.out"`
rm -f `find tests -iname "*.log"`
rm -rf `find tests -iname "obj_dir"`
.PHONY: VERILOG_SOURCES
VERILOG_SOURCES:
@echo $(realpath $(RTL_SRCS))