1# Licensed to the Apache Software Foundation (ASF) under one 2# or more contributor license agreements. See the NOTICE file 3# distributed with this work for additional information 4# regarding copyright ownership. The ASF licenses this file 5# to you under the Apache License, Version 2.0 (the 6# "License"); you may not use this file except in compliance 7# with the License. You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, 12# software distributed under the License is distributed on an 13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14# KIND, either express or implied. See the License for the 15# specific language governing permissions and limitations 16# under the License. 17 18ifeq (, $(shell which verilator)) 19 $(error "No Verilator in $(PATH), consider doing apt-get install verilator") 20endif 21 22# Change VERILATOR_INC_DIR if Verilator is installed on a different location 23ifeq (, $(VERILATOR_INC_DIR)) 24 ifeq (, $(wildcard /usr/local/share/verilator/include/*)) 25 ifeq (, $(wildcard /usr/share/verilator/include/*)) 26 $(error "Verilator include directory is not set properly") 27 else 28 VERILATOR_INC_DIR := /usr/share/verilator/include 29 endif 30 else 31 VERILATOR_INC_DIR := /usr/local/share/verilator/include 32 endif 33endif 34 35TOP = TestAccel 36BUILD_NAME = build 37USE_TRACE = 0 38LIBNAME = libhw 39 40vta_dir = $(abspath ../../../../) 41tvm_dir = $(abspath ../../../../../) 42build_dir = $(abspath .)/$(BUILD_NAME) 43 44verilator_opt = --cc 45verilator_opt += +define+RANDOMIZE_GARBAGE_ASSIGN 46verilator_opt += +define+RANDOMIZE_REG_INIT 47verilator_opt += +define+RANDOMIZE_MEM_INIT 48verilator_opt += --x-assign unique 49verilator_opt += --output-split 20000 50verilator_opt += --output-split-cfuncs 20000 51verilator_opt += --top-module ${TOP} 52verilator_opt += -Mdir ${build_dir} 53 54cxx_flags = -O2 -Wall -fPIC -shared 55cxx_flags += -fvisibility=hidden -std=c++11 56cxx_flags += -DVL_TSIM_NAME=V$(TOP) 57cxx_flags += -DVL_PRINTF=printf 58cxx_flags += -DVL_USER_FINISH 59cxx_flags += -DVM_COVERAGE=0 60cxx_flags += -DVM_SC=0 61cxx_flags += -Wno-sign-compare 62cxx_flags += -include V$(TOP).h 63cxx_flags += -I$(build_dir) 64cxx_flags += -I$(VERILATOR_INC_DIR) 65cxx_flags += -I$(VERILATOR_INC_DIR)/vltstd 66cxx_flags += -I$(vta_dir)/include 67cxx_flags += -I$(tvm_dir)/include 68cxx_flags += -I$(tvm_dir)/3rdparty/dlpack/include 69 70cxx_files = $(VERILATOR_INC_DIR)/verilated.cpp 71cxx_files += $(VERILATOR_INC_DIR)/verilated_dpi.cpp 72cxx_files += $(wildcard $(build_dir)/*.cpp) 73cxx_files += $(vta_dir)/hardware/dpi/tsim_device.cc 74 75v_files = $(wildcard $(abspath .)/src/*.v $(vta_dir)/hardware/chisel/src/main/resources/verilog/*.v) 76 77ifneq ($(USE_TRACE), 0) 78 verilator_opt += --trace 79 cxx_flags += -DVM_TRACE=1 80 cxx_flags += -DTSIM_TRACE_FILE=$(build_dir)/$(TOP).vcd 81 cxx_files += $(VERILATOR_INC_DIR)/verilated_vcd_c.cpp 82else 83 cxx_flags += -DVM_TRACE=0 84endif 85 86# The following is to be consistent with cmake 87ifeq ($(shell uname), Darwin) 88 lib_path = $(build_dir)/$(LIBNAME).dylib 89else 90 lib_path = $(build_dir)/$(LIBNAME).so 91endif 92 93default: lib 94 95lib: $(lib_path) 96$(lib_path): $(build_dir)/V$(TOP).cpp 97 g++ $(cxx_flags) $(cxx_files) -o $@ 98 99verilator: $(build_dir)/V$(TOP).cpp 100$(build_dir)/V$(TOP).cpp: $(v_files) | $(build_dir) 101 verilator $(verilator_opt) $(v_files) 102 103$(build_dir): 104 mkdir -p $@ 105 106clean: 107 -rm -rf $(build_dir) 108