Makefile 2.2 KB
Newer Older
Z
Zihao Yu 已提交
1 2 3 4 5
TOP = TopMain
BUILD_DIR = ./build
TOP_V = $(BUILD_DIR)/$(TOP).v
SCALA_FILE = $(shell find ./src/main/scala -name '*.scala')

Z
Zihao Yu 已提交
6
SIMTOP = top.TestMain
Z
Zihao Yu 已提交
7 8 9
EMU_IMAGE = $(BUILD_DIR)/bin-readmemh
IMAGE ?= temp
SIMCMD = test:runMain $(SIMTOP) -td $(BUILD_DIR) --image $(EMU_IMAGE) \
10
	--more-vcs-flags "+define+RANDOMIZE_REG_INIT"
Z
Zihao Yu 已提交
11

Z
Zihao Yu 已提交
12 13
.DEFAULT_GOAL = verilog

Z
Zihao Yu 已提交
14
help:
Z
Zihao Yu 已提交
15
	sbt 'test:runMain gcd.GCDMain --help'
Z
Zihao Yu 已提交
16

Z
Zihao Yu 已提交
17
LIBDEVICE_PATH = ./src/test/libdevice
Z
Zihao Yu 已提交
18 19 20
libdevice:
	make -C $(LIBDEVICE_PATH)

Z
Zihao Yu 已提交
21 22 23
$(TOP_V): $(SCALA_FILE)
	mkdir -p $(@D)
	sbt 'runMain top.$(TOP) -td $(@D) --output-file $@'
Z
Zihao Yu 已提交
24
	sed -i -e 's/_\(aw\|ar\|w\|r\|b\)_\(\|bits_\)/_\1/g' $@
Z
Zihao Yu 已提交
25

Z
Zihao Yu 已提交
26 27
verilog: $(TOP_V)

Z
Zihao Yu 已提交
28 29 30 31
SIM_TOP = NOOPSimTop
SIM_TOP_V = $(BUILD_DIR)/$(SIM_TOP).v
$(SIM_TOP_V): $(SCALA_FILE)
	mkdir -p $(@D)
Z
Zihao Yu 已提交
32
	sbt 'test:runMain $(SIMTOP) -td $(BUILD_DIR) --image $(EMU_IMAGE) --output-file $@'
Z
Zihao Yu 已提交
33

Z
Zihao Yu 已提交
34
test: libdevice
35
	sbt '$(SIMCMD) --tr-rollback-buffers 0'
Z
Zihao Yu 已提交
36

Z
Zihao Yu 已提交
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

EMU_CSRC_DIR = $(abspath ./src/test/csrc)
EMU_VSRC_DIR = $(abspath ./src/test/vsrc)
EMU_CXXFILES = $(shell find $(EMU_CSRC_DIR) -name "*.cpp")
EMU_VFILES = $(shell find $(EMU_VSRC_DIR) -name "*.v" -or -name "*.sv")

EMU_CXXFLAGS  = -O3 -std=c++11 -static -g -Wall -I$(EMU_CSRC_DIR)
EMU_CXXFLAGS += -DVERILATOR -Wno-maybe-uninitialized
EMU_LDFLAGS   = -lpthread -lreadline -lSDL

VERILATOR_FLAGS = --top-module $(SIM_TOP) \
  +define+PRINTF_COND=1 \
	+define+RANDOMIZE_REG_INIT \
  --assert --output-split 20000 \
  --x-assign unique -O3 -CFLAGS "$(EMU_CXXFLAGS)" \
   -LDFLAGS "$(EMU_LDFLAGS)"

EMU_MK := $(BUILD_DIR)/emu-compile/V$(SIM_TOP).mk
EMU_DEPS := $(EMU_VFILES) $(EMU_CXXFILES)
EMU_HEADERS := $(shell find $(EMU_CSRC_DIR) -name "*.h")
EMU := $(BUILD_DIR)/emu

$(EMU_MK): $(SIM_TOP_V) | $(EMU_DEPS)
	@mkdir -p $(@D)
	verilator --cc --exe $(VERILATOR_FLAGS) \
		-o $(abspath $(EMU)) -Mdir $(@D) \
Z
Zihao Yu 已提交
63
		-f $(BUILD_DIR)/black_box_verilog_files.f $^ $(EMU_DEPS)
Z
Zihao Yu 已提交
64 65 66 67 68

$(EMU): $(EMU_MK) $(EMU_DEPS) $(EMU_HEADERS)
	$(MAKE) -C $(dir $(EMU_MK)) -f $(abspath $(EMU_MK))

emu: $(EMU)
Z
Zihao Yu 已提交
69 70 71 72
	ln -sf $(IMAGE)_0 $(EMU_IMAGE)_0
	ln -sf $(IMAGE)_1 $(EMU_IMAGE)_1
	ln -sf $(IMAGE)_2 $(EMU_IMAGE)_2
	ln -sf $(IMAGE)_3 $(EMU_IMAGE)_3
Z
Zihao Yu 已提交
73 74 75 76
	$(EMU)

#emu: libdevice
#	sbt '$(SIMCMD) --backend-name verilator --generate-vcd-output off'
77

Z
Zihao Yu 已提交
78
clean:
79
	rm -rf $(BUILD_DIR)
Z
Zihao Yu 已提交
80

Z
Zihao Yu 已提交
81
.PHONY: libdevice verilog test emu clean help