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__)