cvw/sim/verilator/Makefile

83 lines
3.0 KiB
Makefile
Raw Normal View History

2024-04-20 21:12:55 +00:00
# Verilator Makefile for WALLY
# Kunlin Han, Rose Thompson, David Harris 2024
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
SHELL := /bin/bash
2024-04-12 03:02:20 +00:00
.PHONY: profile run questa clean
# verilator configurations
2024-04-12 03:02:20 +00:00
OPT=
PARAMS?=--no-trace-top
2024-04-12 03:02:20 +00:00
NONPROF?=--stats
VERILATOR_DIR=${WALLY}/sim/verilator
2024-04-23 17:19:08 +00:00
SOURCE=${WALLY}/config/shared/*.vh ${WALLY}/config/${WALLYCONF} ${WALLY}/config/deriv/${WALLYCONF} ${WALLY}/src/cvw.sv ${WALLY}/testbench/*.sv ${WALLY}/testbench/common/*.sv ${WALLY}/src/*/*.sv ${WALLY}/src/*/*/*.sv
PLUS_ARGS=
PARAM_ARGS=
EXPANDED_PARAM_ARGS:=$(patsubst %,-G%,$(PARAM_ARGS))
2024-04-22 18:35:18 +00:00
2024-04-12 03:02:20 +00:00
WALLYCONF?=rv64gc
TEST?=arch64i
TESTBENCH?=testbench
2024-04-12 03:02:20 +00:00
# constants
# assume WALLY variable is correctly configured in the shell environment
WORKING_DIR=${WALLY}/sim/verilator
TARGET=$(WORKING_DIR)/target
# INCLUDE_PATH are pathes that Verilator should search for files it needs
INCLUDE_PATH="-I${WALLY}/config/shared" "-I${WALLY}/config/$(WALLYCONF)" "-I${WALLY}/config/deriv/$(WALLYCONF)"
# SOURCES are source files
SOURCES=${WALLY}/src/cvw.sv ${WALLY}/testbench/${TESTBENCH}.sv ${WALLY}/testbench/common/*.sv ${WALLY}/src/*/*.sv ${WALLY}/src/*/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*/*/*.sv
# DEPENDENCIES are configuration files and source files, which leads to recompilation of executables
DEPENDENCIES=${WALLY}/config/shared/*.vh $(SOURCES)
# regular testbench requires a wrapper defining getenvval
ifeq ($(TESTBENCH), testbench)
WRAPPER=${WALLY}/sim/verilator/wrapper.c
ARGTEST=+TEST=$(TEST)
else
WRAPPER=
ARGTEST=
endif
2024-04-12 03:02:20 +00:00
default: run
run: wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH}
mkdir -p $(VERILATOR_DIR)/logs
wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH} ${ARGTEST} $(PLUS_ARGS)
2024-06-19 21:25:31 +00:00
profile: obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF)
$(VERILATOR_DIR)/obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF) ${ARGTEST}
2024-04-12 03:02:20 +00:00
mv gmon.out gmon_$(WALLYCONF).out
gprof $(VERILATOR_DIR)/obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF) gmon_$(WALLYCONF).out > gmon_$(WALLYCONF).log
2024-04-12 03:02:20 +00:00
verilator_profcfunc gmon_$(WALLYCONF).log > gmon_$(WALLYCONF).log2
mkdir -p $(VERILATOR_DIR)/logs_profiling
mv gmon_$(WALLYCONF)* $(VERILATOR_DIR)/logs_profiling
echo "Please check $(VERILATOR_DIR)/logs_profiling/gmon_$(WALLYCONF)* for logs and output files."
2024-04-12 03:02:20 +00:00
wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH}: $(DEPENDENCIES)
mkdir -p wkdir/$(WALLYCONF)_$(TEST)
verilator \
--Mdir wkdir/$(WALLYCONF)_$(TEST) -o V${TESTBENCH} \
2024-04-22 20:03:51 +00:00
--binary --trace \
2024-04-12 03:02:20 +00:00
$(OPT) $(PARAMS) $(NONPROF) \
--top-module ${TESTBENCH} --relative-includes \
2024-04-23 17:19:08 +00:00
$(INCLUDE_PATH) \
${WRAPPER} \
${EXPANDED_PARAM_ARGS} \
2024-04-23 17:19:08 +00:00
$(SOURCES)
2024-04-22 18:35:18 +00:00
obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF): $(DEPENDENCIES)
2024-04-12 03:02:20 +00:00
mkdir -p obj_dir_profiling
verilator \
--Mdir obj_dir_profiling -o V${TESTBENCH}_$(WALLYCONF) \
--binary \
2024-04-12 03:02:20 +00:00
--prof-cfuncs $(OPT) $(PARAMS) \
--top-module ${TESTBENCH} --relative-includes \
$(INCLUDE_PATH) \
${WRAPPER} \
${EXPANDED_PARAM_ARGS} \
$(SOURCES)
2024-04-12 03:02:20 +00:00
clean:
2024-06-19 21:25:31 +00:00
rm -rf $(VERILATOR_DIR)/wkdir $(VERILATOR_DIR)/obj_dir_profiling $(VERILATOR_DIR)/logs $(VERILATOR_DIR)/logs_profiling