ivl: Don’t embed paths in generated .vvp

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.
This commit is contained in:
Ralf Habacker 2026-05-12 12:16:47 +02:00
parent 8977c4902b
commit 04c373c436
2 changed files with 43 additions and 8 deletions

23
main.cc
View File

@ -131,18 +131,35 @@ map<string,const char*> 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<char*>(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);
}

View File

@ -23,6 +23,8 @@
#include "sv_vpi_user.h"
#include "ivl_dlfcn.h"
#include <string.h>
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__)