Skip to content

Commit

Permalink
Makefile: add common compiling flags (#170)
Browse files Browse the repository at this point in the history
These flags are moved from verilator.mk to Makefile to allow reuse
across various simulation platforms.
  • Loading branch information
poemonsense authored Sep 21, 2023
1 parent 1c26c49 commit 273e088
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 126 deletions.
128 changes: 119 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,136 @@ REMOTE ?= localhost
.DEFAULT_GOAL = emu

# simulation
SIM_CONFIG_DIR = $(abspath ./config)
SIM_CSRC_DIR = $(abspath ./src/test/csrc/common)
SIM_CXXFILES = $(shell find $(SIM_CSRC_DIR) -name "*.cpp")
SIM_CXXFLAGS = -I$(SIM_CSRC_DIR) -I$(SIM_CONFIG_DIR)

# generated-src
GEN_CSRC_DIR = $(BUILD_DIR)/generated-src
GEN_CXXFILES = $(shell find $(GEN_CSRC_DIR) -name "*.cpp")
GEN_CSRC_DIR = $(BUILD_DIR)/generated-src
SIM_CXXFILES += $(shell find $(GEN_CSRC_DIR) -name "*.cpp")
SIM_CXXFLAGS += -I$(GEN_CSRC_DIR)

PLUGIN_CSRC_DIR = $(abspath ./src/test/csrc/plugin)
PLUGIN_INC_DIR = $(abspath $(PLUGIN_CSRC_DIR)/include)
SIM_CXXFLAGS += -I$(PLUGIN_INC_DIR)

VSRC_DIR = $(abspath ./src/test/vsrc/common)
SIM_VSRC = $(shell find $(VSRC_DIR) -name "*.v" -or -name "*.sv")

# DiffTest support
DIFFTEST_CSRC_DIR = $(abspath ./src/test/csrc/difftest)
DIFFTEST_CXXFILES = $(shell find $(DIFFTEST_CSRC_DIR) -name "*.cpp")
ifeq ($(NO_DIFF), 1)
SIM_CXXFLAGS += -DCONFIG_NO_DIFFTEST
else
SIM_CXXFILES += $(DIFFTEST_CXXFILES)
SIM_CXXFLAGS += -I$(DIFFTEST_CSRC_DIR)
endif

# ChiselDB
WITH_CHISELDB ?= 1
ifeq ($(WITH_CHISELDB), 1)
SIM_CXXFILES += $(BUILD_DIR)/chisel_db.cpp
SIM_CXXFLAGS += -I$(BUILD_DIR) -DENABLE_CHISEL_DB
SIM_LDFLAGS += -lsqlite3
endif

# ConstantIn
WITH_CONSTANTIN ?= 1
ifeq ($(WITH_CONSTANTIN), 1)
SIM_CXXFILES += $(BUILD_DIR)/constantin.cpp
SIM_CXXFLAGS += -I$(BUILD_DIR) -DENABLE_CONSTANTIN
endif

ifeq ($(WITH_IPC), 1)
SIM_CXXFLAGS += -I$(BUILD_DIR) -DENABLE_IPC
endif

# REF SELECTION
ifneq ($(REF),)
ifneq ($(wildcard $(REF)),)
SIM_CXXFLAGS += -DREF_PROXY=LinkedProxy -DLINKED_REFPROXY_LIB=\\\"$(REF)\\\"
SIM_LDFLAGS += $(REF)
else
SIM_CXXFLAGS += -DREF_PROXY=$(REF)Proxy
REF_HOME_VAR = $(shell echo $(REF)_HOME | tr a-z A-Z)
ifneq ($(origin $(REF_HOME_VAR)), undefined)
SIM_CXXFLAGS += -DREF_HOME=\\\"$(shell echo $$$(REF_HOME_VAR))\\\"
endif
endif
endif

# co-simulation with DRAMsim3
ifeq ($(WITH_DRAMSIM3),1)
SIM_CXXFLAGS += -I$(DRAMSIM3_HOME)/src
SIM_CXXFLAGS += -DWITH_DRAMSIM3 -DDRAMSIM3_CONFIG=\\\"$(DRAMSIM3_HOME)/configs/XiangShan.ini\\\" -DDRAMSIM3_OUTDIR=\\\"$(BUILD_DIR)\\\"
SIM_LDFLAGS += $(DRAMSIM3_HOME)/build/libdramsim3.a
endif

PLUGIN_CSRC_DIR = $(abspath ./src/test/csrc/plugin)
PLUGIN_INC_DIR = $(abspath $(PLUGIN_CSRC_DIR)/include)
ifeq ($(RELEASE),1)
SIM_CXXFLAGS += -DBASIC_DIFFTEST_ONLY
endif

PLUGIN_DASM_DIR = $(abspath $(PLUGIN_CSRC_DIR)/spikedasm)
PLUGIN_DASM_CXXFILES = $(shell find $(PLUGIN_CSRC_DIR)/spikedasm -name "*.cpp")
# VGA support
ifeq ($(SHOW_SCREEN),1)
SIM_CXXFLAGS += $(shell sdl2-config --cflags) -DSHOW_SCREEN
SIM_LDFLAGS += -lSDL2
endif

PLUGIN_RUNAHEAD_DIR = $(abspath $(PLUGIN_CSRC_DIR)/runahead)
PLUGIN_RUNAHEAD_CXXFILES = $(shell find $(PLUGIN_CSRC_DIR)/runahead -name "*.cpp")
# GZ image support
IMAGE_GZ_COMPRESS ?= 1
ifeq ($(IMAGE_GZ_COMPRESS),0)
SIM_CXXFLAGS += -DNO_GZ_COMPRESSION
else
SIM_LDFLAGS += -lz
endif

# spike-dasm plugin
WITH_SPIKE_DASM ?= 1
ifeq ($(WITH_SPIKE_DASM),1)
SIM_CXXFLAGS += -I$(abspath $(PLUGIN_CSRC_DIR)/spikedasm)
SIM_CXXFILES += $(shell find $(PLUGIN_CSRC_DIR)/spikedasm -name "*.cpp")
endif

SIM_VSRC = $(shell find ./src/test/vsrc/common -name "*.v" -or -name "*.sv")
# runahead support
ifeq ($(WITH_RUNAHEAD),1)
SIM_CXXFLAGS += -I$(abspath $(PLUGIN_CSRC_DIR)/runahead)
SIM_CXXFILES += $(shell find $(PLUGIN_CSRC_DIR)/runahead -name "*.cpp")
endif

# Check if XFUZZ is set
ifeq ($(XFUZZ), 1)
XFUZZ_HOME_VAR = XFUZZ_HOME
ifeq ($(origin $(XFUZZ_HOME_VAR)), undefined)
$(error $(XFUZZ_HOME_VAR) is not set)
endif
FUZZER_LIB = $(shell echo $$$(XFUZZ_HOME_VAR))/target/release/libfuzzer.a
SIM_LDFLAGS += -lrt -lpthread
endif

# Link fuzzer libraries
ifneq ($(FUZZER_LIB), )
SIM_CXXFLAGS += -DFUZZER_LIB
SIM_LDFLAGS += $(abspath $(FUZZER_LIB))
FUZZING = 1
endif

# Fuzzer support
ifeq ($(FUZZING),1)
SIM_CXXFLAGS += -DFUZZING
endif

# FIRRTL Coverage support
ifneq ($(FIRRTL_COVER),)
SIM_CXXFLAGS += -DFIRRTL_COVER
endif

# LLVM Sanitizer Coverage support
ifneq ($(LLVM_COVER),)
SIM_CXXFLAGS += -DLLVM_COVER
SIM_LDFLAGS += -fsanitize-coverage=trace-pc-guard -fsanitize-coverage=pc-table
endif

include verilator.mk
include vcs.mk
Expand Down
122 changes: 5 additions & 117 deletions verilator.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,20 @@ EMU_TOP = SimTop
EMU_CSRC_DIR = $(abspath ./src/test/csrc/verilator)
EMU_CONFIG_DIR = $(abspath ./config)

EMU_CXXFILES = $(shell find $(EMU_CSRC_DIR) -name "*.cpp")
EMU_CXXFILES += $(SIM_CXXFILES) $(GEN_CXXFILES)

EMU_CXXFLAGS += -I$(SIM_CSRC_DIR) -I$(GEN_CSRC_DIR) -I$(PLUGIN_INC_DIR)
EMU_CXXFLAGS += -I$(EMU_CONFIG_DIR) -I$(EMU_CSRC_DIR)
EMU_CXXFILES = $(SIM_CXXFILES) $(shell find $(EMU_CSRC_DIR) -name "*.cpp")
EMU_CXXFLAGS = $(SIM_CXXFLAGS) -I$(EMU_CSRC_DIR)
EMU_CXXFLAGS += -DVERILATOR -DNUM_CORES=$(NUM_CORES) --std=c++17
EMU_LDFLAGS += -ldl
EMU_LDFLAGS = $(SIM_LDFLAGS) -ldl

# DiffTest support
ifeq ($(NO_DIFF), 1)
EMU_CXXFLAGS += -DCONFIG_NO_DIFFTEST
else
EMU_CXXFILES += $(DIFFTEST_CXXFILES)
EMU_CXXFLAGS += -I$(DIFFTEST_CSRC_DIR)
ifneq ($(NO_DIFF), 1)
VEXTRA_FLAGS += +define+DIFFTEST
endif

# Check if XFUZZ is set
ifeq ($(XFUZZ), 1)
XFUZZ_HOME_VAR = XFUZZ_HOME
ifeq ($(origin $(XFUZZ_HOME_VAR)), undefined)
$(error $(XFUZZ_HOME_VAR) is not set)
endif
FUZZER_LIB = $(shell echo $$$(XFUZZ_HOME_VAR))/target/release/libfuzzer.a
EMU_LDFLAGS += -lrt -lpthread
endif

# Link fuzzer libraries
ifneq ($(FUZZER_LIB), )
# the target is named as fuzzer for clarity
EMU = $(BUILD_DIR)/fuzzer
EMU_CXXFLAGS += -DFUZZER_LIB
EMU_LDFLAGS += $(abspath $(FUZZER_LIB))
FUZZING = 1
endif

# ChiselDB
WITH_CHISELDB ?= 1
ifeq ($(WITH_CHISELDB), 1)
EMU_CXXFILES += $(BUILD_DIR)/chisel_db.cpp
EMU_CXXFLAGS += -I$(BUILD_DIR) -DENABLE_CHISEL_DB
EMU_LDFLAGS += -lsqlite3
endif

WITH_CONSTANTIN ?= 1
ifeq ($(WITH_CONSTANTIN), 1)
EMU_CXXFILES += $(BUILD_DIR)/constantin.cpp
EMU_CXXFLAGS += -I$(BUILD_DIR) -DENABLE_CONSTANTIN
endif

ifeq ($(WITH_IPC), 1)
EMU_CXXFLAGS += -I$(BUILD_DIR) -DENABLE_IPC
EMU = $(BUILD_DIR)/fuzzer
endif

# CCACHE
Expand All @@ -80,26 +42,6 @@ ifneq ($(CCACHE),)
export OBJCACHE = ccache
endif

# REF SELECTION
ifneq ($(REF),)
ifneq ($(wildcard $(REF)),)
EMU_CXXFLAGS += -DREF_PROXY=LinkedProxy -DLINKED_REFPROXY_LIB=\\\"$(REF)\\\"
EMU_LDFLAGS += $(REF)
else
EMU_CXXFLAGS += -DREF_PROXY=$(REF)Proxy
REF_HOME_VAR = $(shell echo $(REF)_HOME | tr a-z A-Z)
ifneq ($(origin $(REF_HOME_VAR)), undefined)
EMU_CXXFLAGS += -DREF_HOME=\\\"$(shell echo $$$(REF_HOME_VAR))\\\"
endif
endif
endif

# Verilator
USE_VERILATOR ?= 1
ifeq ($(USE_VERILATOR),1)
EMU_CXXFLAGS += -I$(EMU_CSRC_DIR)/verilator
endif

# Verilator version check
VERILATOR_VER_CMD = verilator --version | cut -f2 -d' ' | tr -d '.'
VERILATOR_4_210 := $(shell expr `$(VERILATOR_VER_CMD)` \>= 4210)
Expand Down Expand Up @@ -147,60 +89,6 @@ ifeq ($(EMU_COVERAGE),1)
VEXTRA_FLAGS += --coverage-line --coverage-toggle
endif

# co-simulation with DRAMsim3
ifeq ($(WITH_DRAMSIM3),1)
EMU_CXXFLAGS += -I$(DRAMSIM3_HOME)/src
EMU_CXXFLAGS += -DWITH_DRAMSIM3 -DDRAMSIM3_CONFIG=\\\"$(DRAMSIM3_HOME)/configs/XiangShan.ini\\\" -DDRAMSIM3_OUTDIR=\\\"$(BUILD_DIR)\\\"
EMU_LDFLAGS += $(DRAMSIM3_HOME)/build/libdramsim3.a
endif

ifeq ($(RELEASE),1)
EMU_CXXFLAGS += -DBASIC_DIFFTEST_ONLY
endif

# VGA support
ifeq ($(SHOW_SCREEN),1)
EMU_CXXFLAGS += $(shell sdl2-config --cflags) -DSHOW_SCREEN
EMU_LDFLAGS += -lSDL2
endif

# GZ image support
EMU_GZ_COMPRESS ?= 1
ifeq ($(EMU_GZ_COMPRESS),0)
EMU_CXXFLAGS += -DNO_GZ_COMPRESSION
else
EMU_LDFLAGS += -lz
endif

# Verilator
WITH_SPIKE_DASM ?= 1
ifeq ($(WITH_SPIKE_DASM),1)
EMU_CXXFLAGS += -I$(PLUGIN_DASM_DIR)
EMU_CXXFILES += $(PLUGIN_DASM_CXXFILES)
endif

# runahead support
ifeq ($(WITH_RUNAHEAD),1)
EMU_CXXFLAGS += -I$(PLUGIN_RUNAHEAD_DIR)
EMU_CXXFILES += $(PLUGIN_RUNAHEAD_CXXFILES)
endif

# Fuzzer support
ifeq ($(FUZZING),1)
EMU_CXXFLAGS += -DFUZZING
endif

# FIRRTL Coverage support
ifneq ($(FIRRTL_COVER),)
EMU_CXXFLAGS += -DFIRRTL_COVER
endif

# LLVM Sanitizer Coverage support
ifneq ($(LLVM_COVER),)
EMU_CXXFLAGS += -DLLVM_COVER
EMU_LDFLAGS += -fsanitize-coverage=trace-pc-guard -fsanitize-coverage=pc-table
endif

VERILATOR_FLAGS = \
--exe \
--cc -O3 --top-module $(EMU_TOP) \
Expand Down

0 comments on commit 273e088

Please sign in to comment.