Skip to content

Commit

Permalink
Shuffle around RTL simulation and unittest makefrags
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbiancolin committed Sep 28, 2018
1 parent a1abbc1 commit 80137ec
Show file tree
Hide file tree
Showing 8 changed files with 441 additions and 106 deletions.
29 changes: 17 additions & 12 deletions src/main/cc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,43 @@ $(OUT_DIR)/$(DESIGN).chain:
$(if $(wildcard $(GEN_DIR)/$(DESIGN).chain),cp $(GEN_DIR)/$(DESIGN).chain $@,)

override CXXFLAGS += -I$(midas_dir) -I$(util_dir)
override LDFLAGS := $(LDFLAGS) -L$(GEN_DIR) -lstdc++ -lpthread -lgmp
# The trailing whitespace is important for some reason...
override LDFLAGS := $(LDFLAGS) -L$(GEN_DIR) -lstdc++ -lpthread -lgmp -lmidas

design_v = $(GEN_DIR)/$(shim).v
design_v := $(GEN_DIR)/$(shim).v
design_h := $(GEN_DIR)/$(DESIGN)-const.h
design_vh := $(GEN_DIR)/$(DESIGN)-const.vh
driver_h = $(foreach t, $(DRIVER), $(wildcard $(dir $(t))/*.h))
endpoint_h := $(wildcard $(endpoint_dir)/*.h)
endpoint_cc := $(wildcard $(endpoint_dir)/*.cc)
endpoint_o := $(patsubst $(endpoint_dir)/%.cc, $(GEN_DIR)/%.o, $(endpoint_cc))
$(endpoint_o): $(GEN_DIR)/%.o: $(endpoint_dir)/%.cc $(GEN_DIR)/$(DESIGN)-const.h $(endpoint_h)
$(endpoint_o): $(GEN_DIR)/%.o: $(endpoint_dir)/%.cc $(design_h) $(endpoint_h)
$(CXX) $(CXXFLAGS) -c -o $@ $< -include $(word 2, $^)

platform_files := simif simif_$(PLATFORM) sample/sample
platform_h := $(addprefix $(midas_dir)/, $(addsuffix .h, $(platform_files)))
platform_cc := $(addprefix $(midas_dir)/, $(addsuffix .cc, $(platform_files) sample/simif_sample))
platform_o := $(addprefix $(GEN_DIR)/, $(addsuffix .o, $(platform_files) sample/simif_sample))

$(platform_o): $(GEN_DIR)/%.o: $(midas_dir)/%.cc $(GEN_DIR)/$(DESIGN)-const.h $(platform_h)
$(platform_o): $(GEN_DIR)/%.o: $(midas_dir)/%.cc $(design_h) $(platform_h)
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c -o $@ $< -include $(word 2, $^)

$(OUT_DIR)/$(DESIGN)-$(PLATFORM): $(GEN_DIR)/$(DESIGN)-const.h $(lib) $(DRIVER) $(driver_h) $(platform_o) $(endpoint_o)
$(OUT_DIR)/$(DESIGN)-$(PLATFORM): $(design_h) $(lib) $(DRIVER) $(driver_h) $(platform_o) $(endpoint_o)
mkdir -p $(OUT_DIR)
$(CXX) $(CXXFLAGS) -include $< \
-o $@ $(DRIVER) $(dramsim_o) $(lib_o) $(platform_o) $(endpoint_o) $(LDFLAGS)

$(PLATFORM): $(OUT_DIR)/$(DESIGN)-$(PLATFORM) $(OUT_DIR)/$(DESIGN).chain

# Sources for building MIDAS-level simulators. Must be defined before sources VCS/Verilator Makefrags
override CFLAGS += -include $(design_h)

emul_files := simif simif_emul emul/mmio_$(PLATFORM) sample/sample
emul_h := $(driver_h) $(endpoint_h) $( $(addprefix $(midas_dir)/, $(addsuffix .h, $(emul_files) emul/mmio))
emul_h := $(driver_h) $(endpoint_h) $( $(addprefix $(midas_dir)/, $(addsuffix .h, $(emul_files) emul/mmio)))
# This includes c sources and static libraries
emul_cc := $(DRIVER) $(endpoint_cc) $(addprefix $(midas_dir)/, $(addsuffix .cc, $(emul_files) sample/simif_sample)) $(lib)
emul_v := $(design_v)
emul_h_inc := $(GEN_DIR)/$(DESIGN)-const.h
emul_cc := $(DRIVER) $(endpoint_cc) $(addprefix $(midas_dir)/, $(addsuffix .cc, $(emul_files) sample/simif_sample)) $(lib)
emul_v := $(design_vh) $(design_v)

# The lop level module must be called out for verilator
ifeq ($(PLATFORM),zynq)
Expand All @@ -91,15 +95,16 @@ endif
ifeq ($(PLATFORM),f1)
top_module = F1Shim
endif

include Makefrag-verilator
include rtlsim/Makefrag-verilator

verilator: $(OUT_DIR)/V$(DESIGN) $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini
verilator-debug: $(OUT_DIR)/V$(DESIGN)-debug $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini

# Add an extra wrapper source for VCS simulators
vcs_wrapper_v := $(v_dir)/emul_$(PLATFORM).v
include Makefrag-vcs
TB := emul
VCS_FLAGS := -e vcs_main
include rtlsim/Makefrag-vcs

vcs: $(OUT_DIR)/$(DESIGN) $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini
vcs-debug: $(OUT_DIR)/$(DESIGN)-debug $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini
Expand Down
40 changes: 0 additions & 40 deletions src/main/cc/Makefrag-vcs

This file was deleted.

43 changes: 43 additions & 0 deletions src/main/cc/rtlsim/Makefrag-vcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# VCS RTL Simulation Makefrag
#
# This makefrag stores common recipes for building RTL simulators with VCS
#
# Compulsory variables:
# All those described Makefrag-verilator
# vcs_wrapper_v: An additional verilog wrapper around the DUT not used in verilator
# CLOCK_PERIOD: Self explanatory
# TB := The top level module on which the stop and printf conditions are defined
#

VCS ?= vcs -full64
override VCS_FLAGS := -quiet -timescale=1ns/1ps +v2k +rad +vcs+initreg+random +vcs+lic+wait \
-notice -line +lint=all,noVCDE,noONGS,noUI -quiet -debug_pp +no_notifier -cpp $(CXX) \
-Mdir=$(GEN_DIR)/$(DESIGN)-debug.csrc \
+vc+list \
-CFLAGS "$(CXXFLAGS) $(CFLAGS) -DVCS -I$(VCS_HOME)/include" \
-LDFLAGS "$(LDFLAGS)" \
-sverilog \
+define+CLOCK_PERIOD=$(CLOCK_PERIOD) \
+define+RANDOMIZE_MEM_INIT \
+define+RANDOMIZE_REG_INIT \
+define+RANDOMIZE_GARBAGE_ASSIGN \
+define+RANDOMIZE_INVALID_ASSIGN \
+define+STOP_COND=!$(TB).reset \
+define+PRINTF_COND=!$(TB).reset \
$(VCS_FLAGS)

vcs_v := $(emul_v) $(vcs_wrapper_v)

$(OUT_DIR)/$(DESIGN): $(vcs_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/$(DESIGN).csrc
rm -rf $(OUT_DIR)/$(DESIGN).daidir
$(VCS) $(VCS_FLAGS) \
-o $@ $(vcs_v) $(emul_cc)

$(OUT_DIR)/$(DESIGN)-debug: $(vcs_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/$(DESIGN)-debug.csrc
rm -rf $(OUT_DIR)/$(DESIGN)-debug.daidir
$(VCS) $(VCS_FLAGS) +define+DEBUG \
-o $@ $(vcs_v) $(emul_cc)
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
# OUT_DIR: See Makefile
# GEN_DIR: See Makefile
# DESIGN: See Makefile
# emul_h_inc: A c header with macro definitions to be included in all compilation units
# emul_cc: C++ sources
# emul_h: C++ headers
# emul_v: verilog sources
# emul_v: verilog sources and headers
#
# Verilator Only:
# top_module: The top of the DUT

VERILATOR ?= verilator --cc --exe
override VERILATOR_FLAGS := --assert -Wno-STMTDLY -O3 \
-CFLAGS "$(CXXFLAGS)" -LDFLAGS "$(LDFLAGS) -lmidas" \
-CFLAGS "$(CXXFLAGS) $(CFLAGS)" \
-LDFLAGS "$(LDFLAGS) " \
$(VERILATOR_FLAGS)

$(OUT_DIR)/V$(DESIGN): $(emul_h_inc) $(emul_v) $(emul_cc) $(emul_h)
$(OUT_DIR)/V$(DESIGN): $(emul_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/V$(DESIGN).csrc
$(VERILATOR) $(VERILATOR_FLAGS) --top-module $(top_module) -Mdir $(GEN_DIR)/V$(DESIGN).csrc \
-CFLAGS "-include $< -include $(GEN_DIR)/V$(DESIGN).csrc/V$(top_module).h" \
-o $@ $(emul_v) $(DRIVER) $(emul_cc) $(endpoint_cc)
-CFLAGS "-include $(GEN_DIR)/V$(DESIGN).csrc/V$(top_module).h" \
-o $@ $(emul_v) $(emul_cc)
$(MAKE) -C $(GEN_DIR)/V$(DESIGN).csrc -f V$(top_module).mk

$(OUT_DIR)/V$(DESIGN)-debug: $(emul_h_inc) $(emul_v) $(emul_cc) $(emul_h)
$(OUT_DIR)/V$(DESIGN)-debug: $(emul_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/V$(DESIGN)-debug.csrc
$(VERILATOR) $(VERILATOR_FLAGS) --trace --top-module $(top_module) -Mdir $(GEN_DIR)/V$(DESIGN)-debug.csrc \
-CFLAGS "-include $< -include $(GEN_DIR)/V$(DESIGN)-debug.csrc/V$(top_module).h" \
-CFLAGS "-include $(GEN_DIR)/V$(DESIGN)-debug.csrc/V$(top_module).h" \
-o $@ $(emul_v) $(emul_cc)
$(MAKE) -C $(GEN_DIR)/V$(DESIGN)-debug.csrc -f V$(top_module).mk
Loading

0 comments on commit 80137ec

Please sign in to comment.