| 1 |
# Copyright cocotb contributors |
| 2 |
# Copyright (c) 2014 Potential Ventures Ltd |
| 3 |
# Licensed under the Revised BSD License, see LICENSE for details. |
| 4 |
# SPDX-License-Identifier: BSD-3-Clause |
| 5 |
|
| 6 |
TOPLEVEL_LANG ?= vhdl |
| 7 |
|
| 8 |
ifneq ($(or $(filter-out $(TOPLEVEL_LANG),vhdl),$(VERILOG_SOURCES)),) |
| 9 |
|
| 10 |
$(COCOTB_RESULTS_FILE): |
| 11 |
@echo "Skipping simulation as only VHDL is supported on simulator=$(SIM)" |
| 12 |
|
| 13 |
else |
| 14 |
|
| 15 |
CMD_BIN := ghdl |
| 16 |
|
| 17 |
ifdef GHDL_BIN_DIR |
| 18 |
CMD := $(shell :; command -v $(GHDL_BIN_DIR)/$(CMD_BIN) 2>/dev/null) |
| 19 |
else |
| 20 |
# auto-detect bin dir from system path |
| 21 |
CMD := $(shell :; command -v $(CMD_BIN) 2>/dev/null) |
| 22 |
GHDL_BIN_DIR := $(shell dirname $(CMD)) |
| 23 |
endif |
| 24 |
|
| 25 |
ifdef RTL_LIBRARY |
| 26 |
$(warning Using RTL_LIBRARY is deprecated, please use TOPLEVEL_LIBRARY instead.) |
| 27 |
TOPLEVEL_LIBRARY ?= $(RTL_LIBRARY) |
| 28 |
else |
| 29 |
TOPLEVEL_LIBRARY ?= work |
| 30 |
endif |
| 31 |
GHDL_ARGS ?= |
| 32 |
GHDL_ARGS += $(EXTRA_ARGS) |
| 33 |
|
| 34 |
# On Windows add GHDL lib folder to PATH to find libraries |
| 35 |
ifeq ($(OS),Msys) |
| 36 |
export PATH := $(GHDL_BIN_DIR)/../lib:$(PATH) |
| 37 |
endif |
| 38 |
|
| 39 |
GHDL_RUN_ARGS ?= |
| 40 |
|
| 41 |
ifeq ($(shell $(CMD) --version | grep -q mcode; echo $$?),0) |
| 42 |
ifneq ($(COCOTB_HDL_TIMEPRECISION),) |
| 43 |
# Convert the time precision to a format string supported by GHDL, if |
| 44 |
# possible. |
| 45 |
# GHDL only supports setting the time precision if the mcode backend is |
| 46 |
# used, using the --time-resolution argument causes GHDL to error out |
| 47 |
# otherwise. |
| 48 |
# https://ghdl.github.io/ghdl/using/InvokingGHDL.html#cmdoption-ghdl-time-resolution |
| 49 |
ifeq ($(COCOTB_HDL_TIMEPRECISION),1fs) |
| 50 |
GHDL_TIME_RESOLUTION=fs |
| 51 |
else ifeq ($(COCOTB_HDL_TIMEPRECISION),1ps) |
| 52 |
GHDL_TIME_RESOLUTION=ps |
| 53 |
else ifeq ($(COCOTB_HDL_TIMEPRECISION),1us) |
| 54 |
GHDL_TIME_RESOLUTION=us |
| 55 |
else ifeq ($(COCOTB_HDL_TIMEPRECISION),1ms) |
| 56 |
GHDL_TIME_RESOLUTION=ms |
| 57 |
else ifeq ($(COCOTB_HDL_TIMEPRECISION),1s) |
| 58 |
GHDL_TIME_RESOLUTION=sec |
| 59 |
else |
| 60 |
$(error GHDL only supports the following values for COCOTB_HDL_TIMEPRECISION: 1fs, 1ps, 1us, 1ms, 1s) |
| 61 |
endif |
| 62 |
|
| 63 |
GHDL_RUN_ARGS += --time-resolution=$(GHDL_TIME_RESOLUTION) |
| 64 |
endif |
| 65 |
endif |
| 66 |
|
| 67 |
.PHONY: analyse |
| 68 |
|
| 69 |
# Compilation phase |
| 70 |
analyse: $(VHDL_SOURCES) $(CUSTOM_COMPILE_DEPS) | $(SIM_BUILD) |
| 71 |
$(foreach SOURCES_VAR, $(filter VHDL_SOURCES_%, $(.VARIABLES)), \ |
| 72 |
$(CMD) -i $(GHDL_ARGS) $(COMPILE_ARGS) --workdir=$(SIM_BUILD) --work=$(SOURCES_VAR:VHDL_SOURCES_%=%) $($(SOURCES_VAR)) && ) \ |
| 73 |
$(CMD) -i $(GHDL_ARGS) $(COMPILE_ARGS) --workdir=$(SIM_BUILD) --work=$(TOPLEVEL_LIBRARY) $(VHDL_SOURCES) && \ |
| 74 |
$(CMD) -m $(GHDL_ARGS) $(COMPILE_ARGS) --workdir=$(SIM_BUILD) -P$(SIM_BUILD) --work=$(TOPLEVEL_LIBRARY) $(COCOTB_TOPLEVEL) $(ARCH) |
| 75 |
|
| 76 |
$(COCOTB_RESULTS_FILE): analyse $(CUSTOM_SIM_DEPS) |
| 77 |
$(RM) $(COCOTB_RESULTS_FILE) |
| 78 |
|
| 79 |
COCOTB_TEST_MODULES=$(call deprecate,MODULE,COCOTB_TEST_MODULES) COCOTB_TESTCASE=$(call deprecate,TESTCASE,COCOTB_TESTCASE) COCOTB_TEST_FILTER=$(COCOTB_TEST_FILTER) COCOTB_TOPLEVEL=$(call deprecate,TOPLEVEL,COCOTB_TOPLEVEL) TOPLEVEL_LANG=$(TOPLEVEL_LANG) \ |
| 80 |
$(SIM_CMD_PREFIX) $(CMD) -r $(GHDL_ARGS) $(GHDL_RUN_ARGS) --workdir=$(SIM_BUILD) -P$(SIM_BUILD) --work=$(TOPLEVEL_LIBRARY) $(COCOTB_TOPLEVEL) $(ARCH) --vpi=$(shell $(PYTHON_BIN) -m cocotb_tools.config --lib-name-path vpi ghdl) $(SIM_ARGS) $(call deprecate,PLUSARGS,COCOTB_PLUSARGS) $(SIM_CMD_SUFFIX) |
| 81 |
|
| 82 |
$(call check_results) |
| 83 |
|
| 84 |
endif |