diff --git a/configure.ac b/configure.ac index 67f5c7d15..164d5b304 100644 --- a/configure.ac +++ b/configure.ac @@ -360,32 +360,6 @@ AC_DEFUN([_MY_CXX_CHECK_OPT], _MY_CXX_CHECK_IFELSE($2, $1="$$1 $2") ]) -# _MY_CXX_CHECK_IS_CLANG_VERSION(variable,min-version,max-version) -# Check if the C++ compiler is Clang, with version >= min-version and -# < max-version. Versions are given as 'major.minor.patch'. An empty -# bound means unbounded at that end. -# Set variable to yes or no accordingly. -AC_DEFUN([_MY_CXX_CHECK_IS_CLANG_VERSION], - [AC_MSG_CHECKING([whether $CXX is Clang >= m4_default([$2],[any]) and < m4_default([$3],[any])]) - AC_COMPILE_IFELSE( - [AC_LANG_SOURCE([[ -#if !defined(__clang__) -# error "Not Clang" -#endif -#define _MY_VER(maj, min, pat) ((maj) * 1000000 + (min) * 1000 + (pat)) -#define _MY_CLANG_VER _MY_VER(__clang_major__, __clang_minor__, __clang_patchlevel__) -#if _MY_CLANG_VER < _MY_VER(]]m4_quote(m4_translit(m4_default([$2],[0.0.0]),[.],[,]))[[) -# error "Clang older than min-version" -#endif -#if _MY_CLANG_VER >= _MY_VER(]]m4_quote(m4_translit(m4_default([$3],[99999.0.0]),[.],[,]))[[) -# error "Clang not older than max-version" -#endif -]])], - [$1=yes], - [$1=no]) - AC_MSG_RESULT($$1) - ]) - AC_DEFUN([_MY_CXX_CHECK_CORO_SET], [# _MY_CXX_CHECK_CORO_SET(variable,option) # Check if compiler supports coroutines with specific option. If it does, @@ -471,8 +445,6 @@ AC_DEFUN([_MY_LDLIBS_CHECK_SET], fi ]) -_MY_CXX_CHECK_IS_CLANG_VERSION(CXX_IS_CLANG_18, 18.0.0, 19.0.0) - # Add the coverage flags early as they influence later checks. if test "$CFG_WITH_DEV_GCOV" = "yes"; then CFG_GCOV_CXX="$CXX" @@ -658,13 +630,7 @@ m4_foreach([cflag],[ # CMake will test what flags work itself, so pass all flags through to it CFG_CXX_FLAGS_CMAKE="$CFG_CXX_FLAGS_CMAKE cflag" ]) -if test "$CXX_IS_CLANG_18" = "yes"; then - # Clang 18 only: disable the SLP vectorizer; see verilator/verilator#8379 - _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_ALWAYS,-fno-slp-vectorize) - CFG_CXX_FLAGS_CMAKE="$CFG_CXX_FLAGS_CMAKE -fno-slp-vectorize" -fi AC_SUBST(CFG_CXXFLAGS_NO_UNUSED) -AC_SUBST(CFG_CXXFLAGS_ALWAYS) AC_SUBST(CFG_CXX_FLAGS_CMAKE) # Find multithread linker flags diff --git a/docs/guide/connecting.rst b/docs/guide/connecting.rst index 3d1fafd5d..eb1f997a4 100644 --- a/docs/guide/connecting.rst +++ b/docs/guide/connecting.rst @@ -40,6 +40,30 @@ model: internals, including ``/* verilator public_flat */`` items. +.. _model header include macros: + +Model Header Include Macros +--------------------------- + +Code compiled with the generated :file:`{prefix}.mk`, or with the CMake +``verilate()`` command, gets preprocessor macros that expand to the model +header includes, so user C++ need not hard-code the :vlopt:`--prefix`: + +.. code-block:: C++ + + #include VM_PREFIX_INCLUDE // e.g. + #include VM_PREFIX_INCLUDE_DPI // e.g. + +``VM_PREFIX_INCLUDE_DPI`` is defined only when Verilator generates the +:file:`{prefix}__Dpi.h` header, which is the case for designs with DPI and +also for public-signal access such as :vlopt:`--public-flat-rw`. Using it +otherwise is a compile-time error. + +A target built from several models defines each macro once, naming the +first model, as one target has one set of preprocessor definitions. Code +that must reach a second model's header names it directly. + + .. _porting from pre 4.210: Model interface changes in version 4.210 @@ -207,6 +231,9 @@ command line, or the link), you'd then: #include "Vour__Dpi.h" int add(int a, int b) { return a+b; } +Rather than hard-coding the prefix, ``#include VM_PREFIX_INCLUDE_DPI`` may +be used instead; see :ref:`Model Header Include Macros`. + DPI System Task/Functions ------------------------- diff --git a/include/verilated.mk.in b/include/verilated.mk.in index 542ea001e..0c6dbb33d 100644 --- a/include/verilated.mk.in +++ b/include/verilated.mk.in @@ -38,8 +38,6 @@ CFG_CXXFLAGS_STD = @CFG_CXXFLAGS_STD@ CFG_CXXFLAGS_STD_NEWEST = @CFG_CXXFLAGS_STD_NEWEST@ # Compiler flags to use to turn off unused and generated code warnings, such as -Wno-div-by-zero CFG_CXXFLAGS_NO_UNUSED = @CFG_CXXFLAGS_NO_UNUSED@ -# Compiler flags to always use -CFG_CXXFLAGS_ALWAYS = @CFG_CXXFLAGS_ALWAYS@ # Compiler flags that turn on extra warnings CFG_CXXFLAGS_WEXTRA = @CFG_CXXFLAGS_WEXTRA@ # Compiler flags that enable coroutine support @@ -100,7 +98,16 @@ VK_CPPFLAGS_ALWAYS += \ -DVM_TRACE_SAIF=$(VM_TRACE_SAIF) \ -DVM_VPI=$(VM_VPI) \ $(CFG_CXXFLAGS_NO_UNUSED) \ - $(CFG_CXXFLAGS_ALWAYS) \ + +# Left undefined when there is no generated model, so misuse fails at compile time +ifneq ($(VM_PREFIX_INCLUDE),) + VK_CPPFLAGS_ALWAYS += -DVM_PREFIX_INCLUDE="$(VM_PREFIX_INCLUDE)" +endif + +# Left undefined when the design has no DPI, so misuse fails at compile time +ifneq ($(VM_PREFIX_INCLUDE_DPI),) + VK_CPPFLAGS_ALWAYS += -DVM_PREFIX_INCLUDE_DPI="$(VM_PREFIX_INCLUDE_DPI)" +endif ifeq ($(CFG_WITH_CCWARN),yes) # Local... Else don't burden users VK_CPPFLAGS_WALL += -Wall $(CFG_CXXFLAGS_WEXTRA) -Werror diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index 891f0b6fd..3a3e560f2 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -664,10 +664,17 @@ public: of.putSet("VM_SC_TARGET_ARCH", V3Options::getenvSYSTEMC_ARCH()); of.puts("\n### Vars...\n"); - of.puts("# Design prefix (from --prefix)\n"); - of.putSet("VM_PREFIX", v3Global.opt.prefix()); of.puts("# Module prefix (from --prefix)\n"); of.putSet("VM_MODPREFIX", v3Global.opt.modPrefix()); + of.puts("# Design prefix (from --prefix)\n"); + of.putSet("VM_PREFIX", v3Global.opt.prefix()); + of.puts("# Design header include, for '#include VM_PREFIX_INCLUDE' (from --prefix)\n"); + of.putSet("VM_PREFIX_INCLUDE", "<" + v3Global.opt.prefix() + ".h>"); + if (v3Global.dpi()) { + of.puts("# DPI header include, for '#include VM_PREFIX_INCLUDE_DPI';" + " undefined if no DPI\n"); + of.putSet("VM_PREFIX_INCLUDE_DPI", "<" + v3Global.opt.prefix() + "__Dpi.h>"); + } of.puts("# User CFLAGS (from -CFLAGS on Verilator command line)\n"); of.puts("VM_USER_CFLAGS = \\\n"); diff --git a/src/V3EmitMkJson.cpp b/src/V3EmitMkJson.cpp index 042787ea8..a63eed840 100644 --- a/src/V3EmitMkJson.cpp +++ b/src/V3EmitMkJson.cpp @@ -94,6 +94,7 @@ class V3EmitMkJsonEmitter final { .putList("ldflags", v3Global.opt.ldLibs()) .put("system_c", v3Global.opt.systemC()) .put("coverage", v3Global.opt.coverage()) + .put("dpi", v3Global.dpi()) .put("use_timing", v3Global.usesTiming()) .put("threads", v3Global.opt.threads()) .put("trace", v3Global.opt.trace()) diff --git a/test_regress/CMakeLists.txt b/test_regress/CMakeLists.txt index 5934287ba..704c38d82 100644 --- a/test_regress/CMakeLists.txt +++ b/test_regress/CMakeLists.txt @@ -137,6 +137,5 @@ target_compile_definitions( PRIVATE "TEST_OBJ_DIR=${CMAKE_CURRENT_BINARY_DIR}" "VM_PREFIX=${TEST_PREFIX}" - "VM_PREFIX_INCLUDE=<${TEST_PREFIX}.h>" "${TEST_NAME_UC}" ) diff --git a/test_regress/Makefile_obj b/test_regress/Makefile_obj index b7c6c5af1..f5ffe64fb 100644 --- a/test_regress/Makefile_obj +++ b/test_regress/Makefile_obj @@ -30,7 +30,6 @@ CPPFLAGS += -DVL_DEBUG=1 # Needed by tracing routines CPPFLAGS += -DTEST_OBJ_DIR=$(TEST_OBJ_DIR) CPPFLAGS += -DVM_PREFIX=$(VM_PREFIX) -CPPFLAGS += -DVM_PREFIX_INCLUDE="<$(VM_PREFIX).h>" CPPFLAGS += -DVM_PREFIX_ROOT_INCLUDE="<$(VM_PREFIX)___024root.h>" CPPFLAGS += $(CPPFLAGS_DRIVER) CPPFLAGS += $(CPPFLAGS_DRIVER2) diff --git a/test_regress/t/t_dpi_accessors.cpp b/test_regress/t/t_dpi_accessors.cpp index 6c034d0f1..18b7228ae 100644 --- a/test_regress/t/t_dpi_accessors.cpp +++ b/test_regress/t/t_dpi_accessors.cpp @@ -12,7 +12,7 @@ //************************************************************************* #include "Vt_dpi_accessors.h" -#include "Vt_dpi_accessors__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #include diff --git a/test_regress/t/t_dpi_arg_inout_type.cpp b/test_regress/t/t_dpi_arg_inout_type.cpp index 8f67abf3d..0684b562f 100644 --- a/test_regress/t/t_dpi_arg_inout_type.cpp +++ b/test_regress/t/t_dpi_arg_inout_type.cpp @@ -23,7 +23,7 @@ #include "svdpi.h" #if defined(VERILATOR) // Verilator -# include "Vt_dpi_arg_inout_type__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI typedef long long sv_longint_t; typedef unsigned long long sv_longint_unsigned_t; # define NO_SHORTREAL diff --git a/test_regress/t/t_dpi_arg_inout_unpack.cpp b/test_regress/t/t_dpi_arg_inout_unpack.cpp index d1cb24965..e3ace43af 100644 --- a/test_regress/t/t_dpi_arg_inout_unpack.cpp +++ b/test_regress/t/t_dpi_arg_inout_unpack.cpp @@ -25,7 +25,7 @@ #include "svdpi.h" #if defined(VERILATOR) // Verilator -# include "Vt_dpi_arg_inout_unpack__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI typedef long long sv_longint_t; typedef unsigned long long sv_longint_unsigned_t; # define NO_SHORTREAL diff --git a/test_regress/t/t_dpi_arg_input_type.cpp b/test_regress/t/t_dpi_arg_input_type.cpp index 1b565fc8d..9ee3bee5d 100644 --- a/test_regress/t/t_dpi_arg_input_type.cpp +++ b/test_regress/t/t_dpi_arg_input_type.cpp @@ -23,7 +23,7 @@ #include "svdpi.h" #if defined(VERILATOR) // Verilator -# include "Vt_dpi_arg_input_type__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI typedef long long sv_longint_t; typedef unsigned long long sv_longint_unsigned_t; # define NO_SHORTREAL diff --git a/test_regress/t/t_dpi_arg_input_unpack.cpp b/test_regress/t/t_dpi_arg_input_unpack.cpp index 1ec2c3ed9..8e98c2938 100644 --- a/test_regress/t/t_dpi_arg_input_unpack.cpp +++ b/test_regress/t/t_dpi_arg_input_unpack.cpp @@ -25,7 +25,7 @@ #include "svdpi.h" #if defined(VERILATOR) // Verilator -# include "Vt_dpi_arg_input_unpack__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI typedef long long sv_longint_t; typedef unsigned long long sv_longint_unsigned_t; typedef const void** sv_chandle_array_ptr_t; diff --git a/test_regress/t/t_dpi_arg_output_type.cpp b/test_regress/t/t_dpi_arg_output_type.cpp index a9092561d..24430f3d1 100644 --- a/test_regress/t/t_dpi_arg_output_type.cpp +++ b/test_regress/t/t_dpi_arg_output_type.cpp @@ -23,7 +23,7 @@ #include "svdpi.h" #if defined(VERILATOR) // Verilator -# include "Vt_dpi_arg_output_type__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI typedef long long sv_longint_t; typedef unsigned long long sv_longint_unsigned_t; # define NO_SHORTREAL diff --git a/test_regress/t/t_dpi_arg_output_unpack.cpp b/test_regress/t/t_dpi_arg_output_unpack.cpp index 22ae61241..eafe892f6 100644 --- a/test_regress/t/t_dpi_arg_output_unpack.cpp +++ b/test_regress/t/t_dpi_arg_output_unpack.cpp @@ -25,7 +25,7 @@ #include "svdpi.h" #if defined(VERILATOR) // Verilator -# include "Vt_dpi_arg_output_unpack__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI typedef long long sv_longint_t; typedef unsigned long long sv_longint_unsigned_t; # define NO_SHORTREAL diff --git a/test_regress/t/t_dpi_context_c.cpp b/test_regress/t/t_dpi_context_c.cpp index 9ca792a0c..3a58bd086 100644 --- a/test_regress/t/t_dpi_context_c.cpp +++ b/test_regress/t/t_dpi_context_c.cpp @@ -17,11 +17,7 @@ // clang-format off #if defined(VERILATOR) -# ifdef T_DPI_CONTEXT_NOOPT -# include "Vt_dpi_context_noopt__Dpi.h" -# else -# include "Vt_dpi_context__Dpi.h" -# endif +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_decl.cpp b/test_regress/t/t_dpi_decl.cpp index 5cf783a39..eea64595c 100644 --- a/test_regress/t/t_dpi_decl.cpp +++ b/test_regress/t/t_dpi_decl.cpp @@ -8,7 +8,7 @@ // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 // //************************************************************************* -#include "Vt_dpi_decl__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI char* func(const char* arg) { static char str[] = "abc"; diff --git a/test_regress/t/t_dpi_display_c.cpp b/test_regress/t/t_dpi_display_c.cpp index b93fa7f1c..638c4fe2e 100644 --- a/test_regress/t/t_dpi_display_c.cpp +++ b/test_regress/t/t_dpi_display_c.cpp @@ -17,7 +17,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_display__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_export_c.cpp b/test_regress/t/t_dpi_export_c.cpp index cbc479f04..39e0669cc 100644 --- a/test_regress/t/t_dpi_export_c.cpp +++ b/test_regress/t/t_dpi_export_c.cpp @@ -19,11 +19,7 @@ //====================================================================== #if defined(VERILATOR) -#ifdef T_DPI_EXPORT_NOOPT -#include "Vt_dpi_export_noopt__Dpi.h" -#else -#include "Vt_dpi_export__Dpi.h" -#endif +#include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) #include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_export_context2_bad.cpp b/test_regress/t/t_dpi_export_context2_bad.cpp index b597865e6..e39b912f1 100644 --- a/test_regress/t/t_dpi_export_context2_bad.cpp +++ b/test_regress/t/t_dpi_export_context2_bad.cpp @@ -11,7 +11,7 @@ //====================================================================== -#include "Vt_dpi_export_context2_bad__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI //====================================================================== diff --git a/test_regress/t/t_dpi_export_context_bad.cpp b/test_regress/t/t_dpi_export_context_bad.cpp index c563f0f8a..fa5e7bd5b 100644 --- a/test_regress/t/t_dpi_export_context_bad.cpp +++ b/test_regress/t/t_dpi_export_context_bad.cpp @@ -13,7 +13,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_export_context_bad__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_export_scope_bad.cpp b/test_regress/t/t_dpi_export_scope_bad.cpp index 0fba1bce5..f49f83ba3 100644 --- a/test_regress/t/t_dpi_export_scope_bad.cpp +++ b/test_regress/t/t_dpi_export_scope_bad.cpp @@ -10,7 +10,7 @@ //====================================================================== -#include "Vt_dpi_export_scope_bad__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #ifdef NEED_EXTERNS extern "C" { diff --git a/test_regress/t/t_dpi_export_scope_flat.cpp b/test_regress/t/t_dpi_export_scope_flat.cpp index d444e9fda..f49f83ba3 100644 --- a/test_regress/t/t_dpi_export_scope_flat.cpp +++ b/test_regress/t/t_dpi_export_scope_flat.cpp @@ -10,7 +10,7 @@ //====================================================================== -#include "Vt_dpi_export_scope_flat__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #ifdef NEED_EXTERNS extern "C" { diff --git a/test_regress/t/t_dpi_if_cond_c.cpp b/test_regress/t/t_dpi_if_cond_c.cpp index 0e0324a41..63ed843e7 100644 --- a/test_regress/t/t_dpi_if_cond_c.cpp +++ b/test_regress/t/t_dpi_if_cond_c.cpp @@ -21,7 +21,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_if_cond__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(NC) diff --git a/test_regress/t/t_dpi_imp_gen_c.cpp b/test_regress/t/t_dpi_imp_gen_c.cpp index 79bd06c16..f767813c5 100644 --- a/test_regress/t/t_dpi_imp_gen_c.cpp +++ b/test_regress/t/t_dpi_imp_gen_c.cpp @@ -18,7 +18,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_imp_gen__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_import_c.cpp b/test_regress/t/t_dpi_import_c.cpp index 52bcb2d1f..b671d52ef 100644 --- a/test_regress/t/t_dpi_import_c.cpp +++ b/test_regress/t/t_dpi_import_c.cpp @@ -18,7 +18,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_import__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_inline_new.cpp b/test_regress/t/t_dpi_inline_new.cpp index 869e2bec1..e1e2d7d0b 100644 --- a/test_regress/t/t_dpi_inline_new.cpp +++ b/test_regress/t/t_dpi_inline_new.cpp @@ -6,7 +6,7 @@ // Include the Verilator-generated DPI header so the C prototype matches // the SystemVerilog import expectations. -#include "Vt_dpi_inline_new__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #ifdef __cplusplus extern "C" { diff --git a/test_regress/t/t_dpi_lib_c.cpp b/test_regress/t/t_dpi_lib_c.cpp index 688cb5d65..352d30419 100644 --- a/test_regress/t/t_dpi_lib_c.cpp +++ b/test_regress/t/t_dpi_lib_c.cpp @@ -22,7 +22,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_lib__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(NC) diff --git a/test_regress/t/t_dpi_open_c.cpp b/test_regress/t/t_dpi_open_c.cpp index 01bd870fd..3adc602f3 100644 --- a/test_regress/t/t_dpi_open_c.cpp +++ b/test_regress/t/t_dpi_open_c.cpp @@ -22,7 +22,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_open__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(NC) diff --git a/test_regress/t/t_dpi_open_elem_c.cpp b/test_regress/t/t_dpi_open_elem_c.cpp index 2f4f24f51..35e59f74e 100644 --- a/test_regress/t/t_dpi_open_elem_c.cpp +++ b/test_regress/t/t_dpi_open_elem_c.cpp @@ -22,7 +22,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_open_elem__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(NC) diff --git a/test_regress/t/t_dpi_open_oob_bad_c.cpp b/test_regress/t/t_dpi_open_oob_bad_c.cpp index 4444a9654..24473edf6 100644 --- a/test_regress/t/t_dpi_open_oob_bad_c.cpp +++ b/test_regress/t/t_dpi_open_oob_bad_c.cpp @@ -22,7 +22,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_open_oob_bad__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #else # error "Unknown simulator for DPI test" #endif diff --git a/test_regress/t/t_dpi_open_query.cpp b/test_regress/t/t_dpi_open_query.cpp index 435562b86..b177b8e58 100644 --- a/test_regress/t/t_dpi_open_query.cpp +++ b/test_regress/t/t_dpi_open_query.cpp @@ -13,7 +13,7 @@ // clang-format off #if defined(VERILATOR) // Verilator -# include "Vt_dpi_open_query__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) // VCS # include "../vc_hdrs.h" #elif defined(NCSC) // NC diff --git a/test_regress/t/t_dpi_open_vecval_c.cpp b/test_regress/t/t_dpi_open_vecval_c.cpp index e808239b2..fdd9424f2 100644 --- a/test_regress/t/t_dpi_open_vecval_c.cpp +++ b/test_regress/t/t_dpi_open_vecval_c.cpp @@ -22,7 +22,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_open_vecval__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(NC) diff --git a/test_regress/t/t_dpi_openfirst_c.cpp b/test_regress/t/t_dpi_openfirst_c.cpp index 97283a5b1..022745c30 100644 --- a/test_regress/t/t_dpi_openfirst_c.cpp +++ b/test_regress/t/t_dpi_openfirst_c.cpp @@ -22,7 +22,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_openfirst__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(NC) diff --git a/test_regress/t/t_dpi_qw_c.cpp b/test_regress/t/t_dpi_qw_c.cpp index 3bd07a405..61f881b6b 100644 --- a/test_regress/t/t_dpi_qw_c.cpp +++ b/test_regress/t/t_dpi_qw_c.cpp @@ -17,7 +17,7 @@ //====================================================================== #ifdef VERILATOR -#include "Vt_dpi_qw__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #else extern "C" { extern void set_value(const svBitVecVal* v); diff --git a/test_regress/t/t_dpi_result_type.cpp b/test_regress/t/t_dpi_result_type.cpp index 2be445490..82a752491 100644 --- a/test_regress/t/t_dpi_result_type.cpp +++ b/test_regress/t/t_dpi_result_type.cpp @@ -17,7 +17,7 @@ // clang-format off #if defined(VERILATOR) // Verilator -# include "Vt_dpi_result_type__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI typedef long long sv_longint_t; typedef unsigned long long sv_longint_unsigned_t; # define NO_SHORTREAL diff --git a/test_regress/t/t_dpi_shortcircuit_c.cpp b/test_regress/t/t_dpi_shortcircuit_c.cpp index 00607cd3b..1a7ca6c8a 100644 --- a/test_regress/t/t_dpi_shortcircuit_c.cpp +++ b/test_regress/t/t_dpi_shortcircuit_c.cpp @@ -18,13 +18,7 @@ // clang-format off #if defined(VERILATOR) -# if defined(T_DPI_SHORTCIRCUIT) -# include "Vt_dpi_shortcircuit__Dpi.h" -# elif defined(T_DPI_SHORTCIRCUIT2) -# include "Vt_dpi_shortcircuit2__Dpi.h" -# else -# error "Unknown test" -# endif +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_string_c.cpp b/test_regress/t/t_dpi_string_c.cpp index fcf284699..03a893abc 100644 --- a/test_regress/t/t_dpi_string_c.cpp +++ b/test_regress/t/t_dpi_string_c.cpp @@ -18,7 +18,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_string__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_sys_c.cpp b/test_regress/t/t_dpi_sys_c.cpp index 16553ca92..e67858095 100644 --- a/test_regress/t/t_dpi_sys_c.cpp +++ b/test_regress/t/t_dpi_sys_c.cpp @@ -17,7 +17,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_sys__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_threads_c.cpp b/test_regress/t/t_dpi_threads_c.cpp index 09c61822c..2313cb75a 100644 --- a/test_regress/t/t_dpi_threads_c.cpp +++ b/test_regress/t/t_dpi_threads_c.cpp @@ -20,11 +20,7 @@ // clang-format off #if defined(VERILATOR) -# ifdef T_DPI_THREADS_COLLIDE -# include "Vt_dpi_threads_collide__Dpi.h" -# else -# include "Vt_dpi_threads__Dpi.h" -# endif +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_dpi_vams.cpp b/test_regress/t/t_dpi_vams.cpp index aacbaf9d6..32c4d17db 100644 --- a/test_regress/t/t_dpi_vams.cpp +++ b/test_regress/t/t_dpi_vams.cpp @@ -14,7 +14,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_dpi_vams__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_embed1_c.cpp b/test_regress/t/t_embed1_c.cpp index d04d5b375..6004ef794 100644 --- a/test_regress/t/t_embed1_c.cpp +++ b/test_regress/t/t_embed1_c.cpp @@ -18,7 +18,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_embed1__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_flag_ldflags_c.cpp b/test_regress/t/t_flag_ldflags_c.cpp index 276801399..32798e273 100644 --- a/test_regress/t/t_flag_ldflags_c.cpp +++ b/test_regress/t/t_flag_ldflags_c.cpp @@ -17,7 +17,7 @@ // clang-format off #if defined(VERILATOR) -# include "Vt_flag_ldflags__Dpi.h" +# include VM_PREFIX_INCLUDE_DPI #else # error "Unknown simulator for DPI test" #endif diff --git a/test_regress/t/t_flag_lib_dpi.cpp b/test_regress/t/t_flag_lib_dpi.cpp index ca49b5b9c..c8e8bd701 100644 --- a/test_regress/t/t_flag_lib_dpi.cpp +++ b/test_regress/t/t_flag_lib_dpi.cpp @@ -7,7 +7,7 @@ // //************************************************************************* -#include "Vt_flag_lib_dpi__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #include diff --git a/test_regress/t/t_func_wide_out_c.cpp b/test_regress/t/t_func_wide_out_c.cpp index 5f80aa1b3..e528066fe 100644 --- a/test_regress/t/t_func_wide_out_c.cpp +++ b/test_regress/t/t_func_wide_out_c.cpp @@ -18,13 +18,7 @@ // clang-format off #if defined(VERILATOR) -# ifdef T_FUNC_WIDE_OUT -# include "Vt_func_wide_out__Dpi.h" -# elif defined(T_FUNC_WIDE_OUT_NOINL) -# include "Vt_func_wide_out_noinl__Dpi.h" -# else -# error "Unknown test" -# endif +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #else diff --git a/test_regress/t/t_nba_assign_on_rhs.py b/test_regress/t/t_nba_assign_on_rhs.py index eafe7e6e5..0e433f0d6 100755 --- a/test_regress/t/t_nba_assign_on_rhs.py +++ b/test_regress/t/t_nba_assign_on_rhs.py @@ -15,4 +15,7 @@ test.compile() test.execute() +# Hosts the no-DPI case for VM_PREFIX_INCLUDE_DPI; keep this design free of DPI and public +test.file_grep_not(test.obj_dir + "/" + test.vm_prefix + ".mk", r'VM_PREFIX_INCLUDE_DPI') + test.passes() diff --git a/test_regress/t/t_opt_dead.cpp b/test_regress/t/t_opt_dead.cpp index 3714dbfb7..9e7260ba2 100644 --- a/test_regress/t/t_opt_dead.cpp +++ b/test_regress/t/t_opt_dead.cpp @@ -5,6 +5,6 @@ // SPDX-License-Identifier: CC0-1.0 //************************************************************************* -#include "Vt_opt_dead__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI void dpii_Keep() {} diff --git a/test_regress/t/t_opt_lift_expr.cpp b/test_regress/t/t_opt_lift_expr.cpp index 20e7905b7..d72efe6d5 100644 --- a/test_regress/t/t_opt_lift_expr.cpp +++ b/test_regress/t/t_opt_lift_expr.cpp @@ -9,7 +9,7 @@ // //************************************************************************* -#include "Vt_opt_lift_expr__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" svLogic impure_0() { return sv_0; } diff --git a/test_regress/t/t_order_dpi_export_1.cpp b/test_regress/t/t_order_dpi_export_1.cpp index 9f2fab1bf..9f514e0c2 100644 --- a/test_regress/t/t_order_dpi_export_1.cpp +++ b/test_regress/t/t_order_dpi_export_1.cpp @@ -10,7 +10,7 @@ //************************************************************************* #include -#include +#include VM_PREFIX_INCLUDE_DPI #include int main(int argc, char* argv[]) { diff --git a/test_regress/t/t_order_dpi_export_2.cpp b/test_regress/t/t_order_dpi_export_2.cpp index c50f725d3..77d24060e 100644 --- a/test_regress/t/t_order_dpi_export_2.cpp +++ b/test_regress/t/t_order_dpi_export_2.cpp @@ -10,7 +10,7 @@ //************************************************************************* #include -#include +#include VM_PREFIX_INCLUDE_DPI #include void toggle_other_clk(svBit val) { set_other_clk(val); } diff --git a/test_regress/t/t_order_dpi_export_3.cpp b/test_regress/t/t_order_dpi_export_3.cpp index 61ef97f38..d89494652 100644 --- a/test_regress/t/t_order_dpi_export_3.cpp +++ b/test_regress/t/t_order_dpi_export_3.cpp @@ -10,7 +10,7 @@ //************************************************************************* #include -#include +#include VM_PREFIX_INCLUDE_DPI #include void toggle_other_clk(svBit val) { set_other_clk(val); } diff --git a/test_regress/t/t_order_dpi_export_4.cpp b/test_regress/t/t_order_dpi_export_4.cpp index 5f0e16dbe..7967fe493 100644 --- a/test_regress/t/t_order_dpi_export_4.cpp +++ b/test_regress/t/t_order_dpi_export_4.cpp @@ -10,7 +10,7 @@ //************************************************************************* #include -#include +#include VM_PREFIX_INCLUDE_DPI #include void toggle_other_clk(svBit val) { set_other_clk(val); } diff --git a/test_regress/t/t_order_dpi_export_5.cpp b/test_regress/t/t_order_dpi_export_5.cpp index 2977049f5..a7715b672 100644 --- a/test_regress/t/t_order_dpi_export_5.cpp +++ b/test_regress/t/t_order_dpi_export_5.cpp @@ -10,7 +10,7 @@ //************************************************************************* #include -#include +#include VM_PREFIX_INCLUDE_DPI #include int main(int argc, char* argv[]) { diff --git a/test_regress/t/t_order_dpi_export_6.cpp b/test_regress/t/t_order_dpi_export_6.cpp index 8e54d032c..3af35034e 100644 --- a/test_regress/t/t_order_dpi_export_6.cpp +++ b/test_regress/t/t_order_dpi_export_6.cpp @@ -10,7 +10,7 @@ //************************************************************************* #include -#include +#include VM_PREFIX_INCLUDE_DPI #include void toggle_other_clk(svBit val) { set_other_clk(val); } diff --git a/test_regress/t/t_order_dpi_export_7.cpp b/test_regress/t/t_order_dpi_export_7.cpp index 73043298b..df49048e7 100644 --- a/test_regress/t/t_order_dpi_export_7.cpp +++ b/test_regress/t/t_order_dpi_export_7.cpp @@ -10,7 +10,7 @@ //************************************************************************* #include -#include +#include VM_PREFIX_INCLUDE_DPI #include int main(int argc, char* argv[]) { diff --git a/test_regress/t/t_order_dpi_export_8.cpp b/test_regress/t/t_order_dpi_export_8.cpp index 28626f656..dc36b5838 100644 --- a/test_regress/t/t_order_dpi_export_8.cpp +++ b/test_regress/t/t_order_dpi_export_8.cpp @@ -9,7 +9,7 @@ // //************************************************************************* -#include +#include VM_PREFIX_INCLUDE_DPI #include void call_set_x(svBit val) { set_x(val); } diff --git a/test_regress/t/t_protect_ids_c.cpp b/test_regress/t/t_protect_ids_c.cpp index 9a52816b9..c0c6e5304 100644 --- a/test_regress/t/t_protect_ids_c.cpp +++ b/test_regress/t/t_protect_ids_c.cpp @@ -18,11 +18,7 @@ // clang-format off #if defined(VERILATOR) -# ifdef T_PROTECT_IDS_KEY -# include "Vt_protect_ids_key__Dpi.h" -# else -# include "Vt_protect_ids__Dpi.h" -# endif +# include VM_PREFIX_INCLUDE_DPI #elif defined(VCS) # include "../vc_hdrs.h" #elif defined(CADENCE) diff --git a/test_regress/t/t_vm_prefix_include_cmake.py b/test_regress/t/t_vm_prefix_include_cmake.py new file mode 100755 index 000000000..7952af20f --- /dev/null +++ b/test_regress/t/t_vm_prefix_include_cmake.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of either the GNU Lesser General Public License Version 3 +# or the Perl Artistic License Version 2.0. +# SPDX-FileCopyrightText: 2026 Wilson Snyder +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('vlt') +test.top_filename = "t/t_dpi_decl.v" + +test.compile(v_flags2=["t/t_dpi_decl.cpp"], verilator_make_gmake=False, verilator_make_cmake=True) + +test.execute() + +test.passes() diff --git a/test_regress/t/t_vpi_const_type.cpp b/test_regress/t/t_vpi_const_type.cpp index fb3109432..60d12ae32 100644 --- a/test_regress/t/t_vpi_const_type.cpp +++ b/test_regress/t/t_vpi_const_type.cpp @@ -22,7 +22,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_const_type.h" -#include "Vt_vpi_const_type__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_escape.cpp b/test_regress/t/t_vpi_escape.cpp index 929c30109..bd40dfc5d 100644 --- a/test_regress/t/t_vpi_escape.cpp +++ b/test_regress/t/t_vpi_escape.cpp @@ -20,7 +20,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_escape.h" -#include "Vt_vpi_escape__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_get.cpp b/test_regress/t/t_vpi_get.cpp index 93e957cea..0671e17e1 100644 --- a/test_regress/t/t_vpi_get.cpp +++ b/test_regress/t/t_vpi_get.cpp @@ -22,7 +22,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_get.h" -#include "Vt_vpi_get__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_memory.cpp b/test_regress/t/t_vpi_memory.cpp index 4518a2ac4..07aa92f68 100644 --- a/test_regress/t/t_vpi_memory.cpp +++ b/test_regress/t/t_vpi_memory.cpp @@ -22,7 +22,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_memory.h" -#include "Vt_vpi_memory__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_module.cpp b/test_regress/t/t_vpi_module.cpp index 169088f84..7ecf8aada 100644 --- a/test_regress/t/t_vpi_module.cpp +++ b/test_regress/t/t_vpi_module.cpp @@ -22,7 +22,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_module.h" -#include "Vt_vpi_module__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_module_empty.cpp b/test_regress/t/t_vpi_module_empty.cpp index 652a6a5a0..71692babc 100644 --- a/test_regress/t/t_vpi_module_empty.cpp +++ b/test_regress/t/t_vpi_module_empty.cpp @@ -22,7 +22,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_module_empty.h" -#include "Vt_vpi_module_empty__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_multidim.cpp b/test_regress/t/t_vpi_multidim.cpp index 60250f5f7..0e8fb36d5 100644 --- a/test_regress/t/t_vpi_multidim.cpp +++ b/test_regress/t/t_vpi_multidim.cpp @@ -22,7 +22,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_multidim.h" -#include "Vt_vpi_multidim__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_package.cpp b/test_regress/t/t_vpi_package.cpp index 409d78f6a..244a347bf 100644 --- a/test_regress/t/t_vpi_package.cpp +++ b/test_regress/t/t_vpi_package.cpp @@ -22,7 +22,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_package.h" -#include "Vt_vpi_package__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_param.cpp b/test_regress/t/t_vpi_param.cpp index 29cd0511f..345d34534 100644 --- a/test_regress/t/t_vpi_param.cpp +++ b/test_regress/t/t_vpi_param.cpp @@ -25,7 +25,7 @@ #ifdef T_VPI_PARAM #include "Vt_vpi_param.h" -#include "Vt_vpi_param__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #elif defined(T_VPI_PUBLIC_PARAMS) #include "Vt_vpi_public_params.h" #else diff --git a/test_regress/t/t_vpi_public_depth.cpp b/test_regress/t/t_vpi_public_depth.cpp index 61f9c4dea..bda78c499 100644 --- a/test_regress/t/t_vpi_public_depth.cpp +++ b/test_regress/t/t_vpi_public_depth.cpp @@ -22,15 +22,7 @@ #include "verilated_vpi.h" #include VM_PREFIX_INCLUDE -#ifdef T_VPI_PUBLIC_DEPTH -#include "Vt_vpi_public_depth__Dpi.h" -#elif defined(T_VPI_PUBLIC_DEPTH_OFF) -#include "Vt_vpi_public_depth_off__Dpi.h" -#elif defined(T_VPI_PUBLIC_OFF) -#include "Vt_vpi_public_off__Dpi.h" -#else -#error "Bad test" -#endif +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #endif diff --git a/test_regress/t/t_vpi_release_dup_bad_c.cpp b/test_regress/t/t_vpi_release_dup_bad_c.cpp index 62ea5781b..68aca8bda 100644 --- a/test_regress/t/t_vpi_release_dup_bad_c.cpp +++ b/test_regress/t/t_vpi_release_dup_bad_c.cpp @@ -15,7 +15,7 @@ #include //#include "verilated.h" -#include "Vt_vpi_release_dup_bad__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI //====================================================================== diff --git a/test_regress/t/t_vpi_time_cb.cpp b/test_regress/t/t_vpi_time_cb.cpp index 1aa0da70c..901cc65c4 100644 --- a/test_regress/t/t_vpi_time_cb.cpp +++ b/test_regress/t/t_vpi_time_cb.cpp @@ -14,7 +14,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_time_cb.h" -#include "Vt_vpi_time_cb__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #include diff --git a/test_regress/t/t_vpi_unimpl.cpp b/test_regress/t/t_vpi_unimpl.cpp index 359089492..ae6fd91fb 100644 --- a/test_regress/t/t_vpi_unimpl.cpp +++ b/test_regress/t/t_vpi_unimpl.cpp @@ -13,7 +13,7 @@ #include "verilated_vcd_c.h" #include "Vt_vpi_unimpl.h" -#include "Vt_vpi_unimpl__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" // No verilated_vpi.h, make sure can link without it diff --git a/test_regress/t/t_vpi_var.cpp b/test_regress/t/t_vpi_var.cpp index 6fa71bfda..3529257e5 100644 --- a/test_regress/t/t_vpi_var.cpp +++ b/test_regress/t/t_vpi_var.cpp @@ -20,19 +20,8 @@ #include "verilated_vcd_c.h" #include "verilated_vpi.h" -#ifdef T_VPI_VAR2 -#include "Vt_vpi_var2.h" -#include "Vt_vpi_var2__Dpi.h" -#elif defined(T_VPI_VAR3) -#include "Vt_vpi_var3.h" -#include "Vt_vpi_var3__Dpi.h" -#elif defined(T_VPI_FORCEABLE_VAR) -#include "Vt_vpi_forceable_var.h" -#include "Vt_vpi_forceable_var__Dpi.h" -#else -#include "Vt_vpi_var.h" -#include "Vt_vpi_var__Dpi.h" -#endif +#include VM_PREFIX_INCLUDE +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" diff --git a/test_regress/t/t_vpi_zero_time_cb.cpp b/test_regress/t/t_vpi_zero_time_cb.cpp index 82b742ccc..1bde145af 100644 --- a/test_regress/t/t_vpi_zero_time_cb.cpp +++ b/test_regress/t/t_vpi_zero_time_cb.cpp @@ -20,7 +20,7 @@ #include "verilated_vpi.h" #include "Vt_vpi_zero_time_cb.h" -#include "Vt_vpi_zero_time_cb__Dpi.h" +#include VM_PREFIX_INCLUDE_DPI #include "svdpi.h" #include diff --git a/test_regress/t/trace_lib_as_top_common.py b/test_regress/t/trace_lib_as_top_common.py index 97508b877..58661339f 100644 --- a/test_regress/t/trace_lib_as_top_common.py +++ b/test_regress/t/trace_lib_as_top_common.py @@ -31,8 +31,7 @@ def run(test, *, verilator_flags2=()): ] flags.extend(verilator_flags2) - cflags = (f'-DVM_PREFIX={test.vm_prefix} ' - f"-DVM_PREFIX_INCLUDE='<{test.vm_prefix}.h>' ") + cflags = f'-DVM_PREFIX={test.vm_prefix} ' # Compile and run without lib-create test.compile(verilator_flags2=[test.pli_filename] + flags + diff --git a/verilator-config.cmake.in b/verilator-config.cmake.in index 33f09a03a..a12b7aa02 100644 --- a/verilator-config.cmake.in +++ b/verilator-config.cmake.in @@ -468,6 +468,7 @@ function(verilate TARGET) json_get_list(JOPTIONS_LDFLAGS "${MANIFEST}" options ldflags) json_get_bool(JOPTIONS_SYSTEM_C "${MANIFEST}" options system_c) json_get_bool(JOPTIONS_COVERAGE "${MANIFEST}" options coverage) + json_get_bool(JOPTIONS_DPI "${MANIFEST}" options dpi) json_get_bool(JOPTIONS_USE_TIMING "${MANIFEST}" options use_timing) json_get_int(JOPTIONS_THREADS "${MANIFEST}" options threads) json_get_bool(JOPTIONS_TRACE_FST "${MANIFEST}" options trace_fst) @@ -505,6 +506,8 @@ function(verilate TARGET) "set(${VERILATE_PREFIX}_SC ${JOPTIONS_SYSTEM_C})\n" "# Coverage output mode? 0/1 (from --coverage)\n" "set(${VERILATE_PREFIX}_COVERAGE ${JOPTIONS_COVERAGE})\n" + "# DPI generated? 0/1\n" + "set(${VERILATE_PREFIX}_DPI ${JOPTIONS_DPI})\n" "# Timing mode? 0/1\n" "set(${VERILATE_PREFIX}_TIMING ${JOPTIONS_USE_TIMING})\n" "# Threaded output mode? 1/N threads (from --threads)\n" @@ -741,6 +744,23 @@ function(verilate TARGET) VM_TRACE_FST=$> VM_TRACE_SAIF=$> ) + # verilate() may be called repeatedly on one target, each call with its own + # prefix, so only the first model defines these; redefining them would warn + # (error under -Werror) on every translation unit of the target + get_target_property(VERILATE_DEFINITIONS ${TARGET} COMPILE_DEFINITIONS) + if(NOT VERILATE_DEFINITIONS MATCHES "(^|;)VM_PREFIX_INCLUDE=") + target_compile_definitions( + ${TARGET} + PRIVATE "VM_PREFIX_INCLUDE=<${VERILATE_PREFIX}.h>" + ) + if(${VERILATE_PREFIX}_DPI) + # Left undefined when the design has no DPI, so misuse fails at compile time + target_compile_definitions( + ${TARGET} + PRIVATE "VM_PREFIX_INCLUDE_DPI=<${VERILATE_PREFIX}__Dpi.h>" + ) + endif() + endif() target_link_libraries(${TARGET} PUBLIC ${${VERILATE_PREFIX}_USER_LDLIBS})