-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
target: Use Verilator to generate accurate dependency files
- Loading branch information
Showing
5 changed files
with
77 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 ETH Zurich and University of Bologna. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
VCS_TOP_MODULE = tb_bin | ||
|
||
$(VCS_BUILDDIR): | ||
mkdir -p $@ | ||
|
||
$(VCS_BUILDDIR)/compile.sh: $(BENDER_YML) $(BENDER_LOCK) | $(VCS_BUILDDIR) | ||
$(BENDER) script vcs $(VCS_BENDER) --vlog-arg="$(VLOGAN_FLAGS)" --vcom-arg="$(VHDLAN_FLAGS)" > $@ | ||
chmod +x $@ | ||
|
||
# Generate dependency file with RTL sources and headers using Verilator | ||
$(VCS_BUILDDIR)/$(VCS_TOP_MODULE).d: $(BENDER_YML) $(BENDER_LOCK) $(GENERATED_RTL_SOURCES) | $(VCS_BUILDDIR) | ||
$(VLT) $(shell $(BENDER) script verilator $(VCS_BENDER)) \ | ||
--Mdir $(VCS_BUILDDIR) --MMD -E --top-module $(VCS_TOP_MODULE) > /dev/null | ||
mv $(VCS_BUILDDIR)/V$(VCS_TOP_MODULE)__ver.d $@ | ||
sed -i 's|^[^:]*:|$(BIN_DIR)/$(TARGET).vcs:|' $@ | ||
|
||
# Run compilation script and create VCS simulation binary | ||
$(BIN_DIR)/$(TARGET).vcs: $(VCS_BUILDDIR)/compile.sh $(TB_CC_SOURCES) $(RTL_CC_SOURCES) work/lib/libfesvr.a | $(BIN_DIR) | ||
$(VCS_SEPP) $< > $(VCS_BUILDDIR)/compile.log | ||
$(VCS) -Mlib=$(VCS_BUILDDIR) -Mdir=$(VCS_BUILDDIR) -o $@ -cc $(CC) -cpp $(CXX) \ | ||
-assert disable_cover -override_timescale=1ns/1ps -full64 $(VCS_TOP_MODULE) $(TB_CC_SOURCES) $(RTL_CC_SOURCES) \ | ||
-CFLAGS "$(TB_CC_FLAGS)" -LDFLAGS "-L$(FESVR)/lib" -lfesvr | ||
|
||
# Clean all build directories and temporary files for VCS simulation | ||
.PHONY: clean-vcs | ||
clean-vcs: clean-work | ||
rm -rf $(BIN_DIR)/$(TARGET).vcs $(VCS_BUILDDIR) vc_hdrs.h | ||
|
||
clean: clean-vcs | ||
|
||
ifneq ($(filter-out clean%,$(MAKECMDGOALS)),) | ||
-include $(VCS_BUILDDIR)/$(VCS_TOP_MODULE).d | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,34 +2,47 @@ | |
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
VSIM_TOP_MODULE = tb_bin | ||
|
||
$(VSIM_BUILDDIR): | ||
mkdir -p $@ | ||
|
||
$(VSIM_BUILDDIR)/compile.vsim.tcl: $(BENDER_LOCK) | $(VSIM_BUILDDIR) | ||
$(VSIM_BUILDDIR)/compile.vsim.tcl: $(BENDER_YML) $(BENDER_LOCK) | $(VSIM_BUILDDIR) | ||
$(VLIB) $(dir $@) | ||
$(BENDER) script vsim $(VSIM_BENDER) --vlog-arg="$(VLOG_FLAGS) -work $(dir $@) " > $@ | ||
echo '$(VLOG) -work $(dir $@) $(TB_CC_SOURCES) $(RTL_CC_SOURCES) -vv -ccflags "$(TB_CC_FLAGS)"' >> $@ | ||
echo 'return 0' >> $@ | ||
|
||
# Build compilation script and compile all sources for Questasim simulation | ||
$(BIN_DIR)/$(TARGET).vsim: $(VSIM_BUILDDIR)/compile.vsim.tcl $(VSIM_SOURCES) $(TB_SRCS) $(TB_CC_SOURCES) $(RTL_CC_SOURCES) work/lib/libfesvr.a | $(BIN_DIR) | ||
# Intermediate file required to avoid "Argument list too long" errors in Occamy | ||
# when invoking Verilator | ||
$(VSIM_BUILDDIR)/$(TARGET).f: $(BENDER_YML) $(BENDER_LOCK) | $(VSIM_BUILDDIR) | ||
$(BENDER) script verilator $(VSIM_BENDER) > $@ | ||
|
||
# Generate dependency file with RTL sources and headers using Verilator | ||
$(VSIM_BUILDDIR)/$(VSIM_TOP_MODULE).d: $(VSIM_BUILDDIR)/$(TARGET).f $(GENERATED_RTL_SOURCES) | $(VSIM_BUILDDIR) | ||
$(VLT) -f $< --Mdir $(VSIM_BUILDDIR) --MMD -E --top-module $(VSIM_TOP_MODULE) > /dev/null | ||
mv $(VSIM_BUILDDIR)/V$(VSIM_TOP_MODULE)__ver.d $@ | ||
sed -i 's|^[^:]*:|$(BIN_DIR)/$(TARGET).vsim:|' $@ | ||
|
||
# Run compilation script and create Questasim simulation binary | ||
$(BIN_DIR)/$(TARGET).vsim: $(VSIM_BUILDDIR)/compile.vsim.tcl $(TB_CC_SOURCES) $(RTL_CC_SOURCES) work/lib/libfesvr.a | $(BIN_DIR) | ||
$(VSIM) -c -do "source $<; quit" | tee $(dir $<)vlog.log | ||
@! grep -P "Errors: [1-9]*," $(dir $<)vlog.log | ||
$(VOPT) $(VOPT_FLAGS) -work $(VSIM_BUILDDIR) tb_bin -o tb_bin_opt | tee $(dir $<)vopt.log | ||
$(VOPT) $(VOPT_FLAGS) -work $(VSIM_BUILDDIR) $(VSIM_TOP_MODULE) -o $(VSIM_TOP_MODULE)_opt | tee $(dir $<)vopt.log | ||
@! grep -P "Errors: [1-9]*," $(dir $<)vopt.log | ||
@echo "#!/bin/bash" > $@ | ||
@echo 'binary=$$(realpath $$1)' >> $@ | ||
@echo 'echo $$binary > .rtlbinary' >> $@ | ||
@echo '$(VSIM) +permissive $(VSIM_FLAGS) $$3 -work $(MKFILE_DIR)/$(VSIM_BUILDDIR) -c \ | ||
-ldflags "-Wl,-rpath,$(FESVR)/lib -L$(FESVR)/lib -lfesvr -lutil" \ | ||
tb_bin_opt +permissive-off ++$$binary ++$$2' >> $@ | ||
$(VSIM_TOP_MODULE)_opt +permissive-off ++$$binary ++$$2' >> $@ | ||
@chmod +x $@ | ||
@echo "#!/bin/bash" > $@.gui | ||
@echo 'binary=$$(realpath $$1)' >> $@.gui | ||
@echo 'echo $$binary > .rtlbinary' >> $@.gui | ||
@echo '$(VSIM) +permissive $(VSIM_FLAGS) -work $(MKFILE_DIR)/$(VSIM_BUILDDIR) \ | ||
-ldflags "-Wl,-rpath,$(FESVR)/lib -L$(FESVR)/lib -lfesvr -lutil" \ | ||
tb_bin_opt +permissive-off ++$$binary ++$$2' >> [email protected] | ||
$(VSIM_TOP_MODULE)_opt +permissive-off ++$$binary ++$$2' >> [email protected] | ||
@chmod +x $@.gui | ||
|
||
# Clean all build directories and temporary files for Questasim simulation | ||
|
@@ -38,3 +51,7 @@ clean-vsim: clean-work | |
rm -rf $(BIN_DIR)/$(TARGET).vsim $(BIN_DIR)/$(TARGET).vsim.gui $(VSIM_BUILDDIR) vsim.wlf | ||
|
||
clean: clean-vsim | ||
|
||
ifneq ($(filter-out clean%,$(MAKECMDGOALS)),) | ||
-include $(VSIM_BUILDDIR)/$(VSIM_TOP_MODULE).d | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters