From 04c373c4366ce49a4549cd662ef4c51bcd575d54 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 12 May 2026 12:16:47 +0200 Subject: [PATCH] =?UTF-8?q?ivl:=20Don=E2=80=99t=20embed=20paths=20in=20gen?= =?UTF-8?q?erated=20.vvp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To satisfy the “don’t embed paths in generated .vvp” goal, add_vpi_module() has been changed so the value recorded into VPI_MODULE_LIST is normalized to a name-only module id (strip directory and .vpi/.vpl suffix), while load_vpi_module(name) still receives the original full/pathful value for loading. This means: - compile-time module loading keeps working from build dirs, - emitted :vpi_module entries are path-independent names. --- main.cc | 23 ++++++++++++++++++++--- vpi_modules.cc | 28 +++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/main.cc b/main.cc index 917e006e9..9ac47b4d6 100644 --- a/main.cc +++ b/main.cc @@ -131,18 +131,35 @@ map flags; char*vpi_module_list = 0; void add_vpi_module(const char*name) { + const char*module_name = strrchr(name, '/'); +#ifdef __MINGW32__ + const char*module_name2 = strrchr(name, '\\'); + if (!module_name || (module_name2 && module_name2 > module_name)) + module_name = module_name2; +#endif + module_name = module_name ? module_name + 1 : name; + + char*module_base = strdup(module_name); + size_t module_len = strlen(module_base); + if (module_len > 4 && strcmp(module_base + module_len - 4, ".vpi") == 0) { + module_base[module_len - 4] = 0; + } else if (module_len > 4 && strcmp(module_base + module_len - 4, ".vpl") == 0) { + module_base[module_len - 4] = 0; + } + if (vpi_module_list == 0) { - vpi_module_list = strdup(name); + vpi_module_list = strdup(module_base); } else { char*tmp = static_cast(realloc(vpi_module_list, strlen(vpi_module_list) - + strlen(name) + + strlen(module_base) + 2)); strcat(tmp, ","); - strcat(tmp, name); + strcat(tmp, module_base); vpi_module_list = tmp; } + free(module_base); flags["VPI_MODULE_LIST"] = vpi_module_list; load_vpi_module(name); } diff --git a/vpi_modules.cc b/vpi_modules.cc index 17a42c69f..92c852c81 100644 --- a/vpi_modules.cc +++ b/vpi_modules.cc @@ -23,6 +23,8 @@ #include "sv_vpi_user.h" #include "ivl_dlfcn.h" +#include + using namespace std; /* The only VPI routines that can be legally called when the functions in @@ -241,11 +243,27 @@ typedef void (*vlog_startup_routines_t)(void); bool load_vpi_module(const char*path) { - ivl_dll_t dll = ivl_dlopen(path, false); - if (dll == 0) { - cerr << "error: Failed to open '" << path << "' because:" << endl; - cerr << " : " << dlerror() << endl; - return false; + ivl_dll_t dll = NULL;; + if (strchr(path, '/') != NULL || strchr(path, '\\') != NULL) { + dll = ivl_dlopen(path, false); + if (dll == 0) { + cerr << "error: Failed to open +++'" << path << "' because:" << endl; + cerr << " : " << dlerror() << endl; + return false; + } + } else { + const char *suffix = ".vpi"; + size_t len = strlen(basedir) + 1 + strlen(path) + strlen(suffix) + 1; + char*tmp = new char[len]; + snprintf(tmp, len, "%s/%s%s", basedir, path, suffix); + dll = ivl_dlopen(tmp, false); + if (dll == 0) { + cerr << "error: Failed to open ---'" << tmp << "' because:" << endl; + cerr << " : " << dlerror() << endl; + delete[] tmp; + return false; + } + delete[] tmp; } #if defined(__MINGW32__) || defined (__CYGWIN__)