[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gEDA: VPI in Icarus Verilog
Stephen Williams wrote:
> mjarabek@istop.com said:
> > I added a call to `dlerror()' and discovered the real error.
>
> I have the same problem. I'd gladly apply a patch to fix this:-)
Patch attached. Enjoy.
--
--------------------------------------------------
Mike Jarabek
FPGA/ASIC Designer
http://www.doncaster.on.ca/~mjarabek
--------------------------------------------------
--- vpi_modules.cc.orig Mon Mar 4 20:09:17 2002
+++ vpi_modules.cc Mon Mar 4 20:15:09 2002
@@ -27,4 +27,6 @@
# include <stdio.h>
# include <string.h>
+# include <sys/types.h>
+# include <sys/stat.h>
typedef void (*vlog_startup_routines_t)(void);
@@ -42,4 +44,8 @@
void vpip_load_module(const char*name)
{
+ struct stat sb;
+ int rc;
+ char buf[4096];
+
#ifdef __MINGW32__
const char sep = '\\';
@@ -49,39 +55,56 @@
ivl_dll_t dll = 0;
-
+ buf[0] = 0; /* terminate the string */
if (strchr(name, sep)) {
/* If the name has at least one directory character in
- it, then assume it is a complete name, including any
+ it, then assume it is a complete name, maybe including any
possble .vpi suffix. */
- dll = ivl_dlopen(name);
+ rc = stat(name, &sb);
- if (dll == 0) {
- char buf[4096];
+ if (rc != 0) { /* did we find a file? */
+ /* no, try with a .vpi suffix too */
sprintf(buf, "%s.vpi", name);
- dll = ivl_dlopen(buf);
+ rc = stat(buf, &sb);
- if (dll == 0) {
- fprintf(stderr, "%s: Unable to link module\n", name);
+ if (rc != 0) {
+ fprintf(stderr, "%s: Unable to find module file `%s' "
+ "or `%s.vpi'.\n", name,name,buf);
return;
}
+ } else {
+ strcpy(buf,name); /* yes copy the name into the buffer */
}
} else {
+ rc = -1;
for (unsigned idx = 0
- ; (dll == 0) && (idx < vpip_module_path_cnt)
+ ; (rc != 0) && (idx < vpip_module_path_cnt)
; idx += 1) {
- char buf[4096];
sprintf(buf, "%s%c%s.vpi", vpip_module_path[idx], sep, name);
- dll = ivl_dlopen(buf);
+ rc = stat(buf,&sb);
}
- if (dll == 0) {
+ if (rc != 0) {
fprintf(stderr, "%s: Unable to find a "
- "%s.vpi module\n", name, name);
+ "`%s.vpi' module on the search path.\n",
+ name, name);
return;
}
}
+
+ /* must have found some file that could possibly be a vpi module
+ * try to open it as a shared object.
+ */
+ dll = ivl_dlopen(buf);
+ if(dll==0) {
+ /* hmm, this failed, let the user know what has really gone wrong */
+ fprintf(stderr,"%s:`%s' failed to open using dlopen() because:\n"
+ " %s.\n",name,buf,dlerror());
+
+ return;
+ }
+
void *regsub = ivl_dlsym(dll, LU "vpi_register_sim" TU);