2 * Copyright (c) 2001-2003 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: vpi_modules.cc,v 1.18 2004/10/04 01:10:59 steve Exp $"
24 # include "vpi_priv.h"
25 # include "ivl_dlfcn.h"
28 # include <sys/types.h>
29 # include <sys/stat.h>
31 typedef void (*vlog_startup_routines_t
)(void);
34 const char* vpip_module_path
[64] = {
44 unsigned vpip_module_path_cnt
= 0
53 void vpip_load_module(const char*name
)
57 bool export_flag
= false;
61 const char sep
= '\\';
67 buf
[0] = 0; /* terminate the string */
68 if (strchr(name
, sep
)) {
69 /* If the name has at least one directory character in
70 it, then assume it is a complete name, maybe including any
71 possible .vpi suffix. */
75 if (rc
!= 0) { /* did we find a file? */
76 /* no, try with a .vpi suffix too */
78 sprintf(buf
, "%s.vpi", name
);
81 /* Tray alwo with the .vpl suffix. */
84 sprintf(buf
, "%s.vpl", name
);
89 fprintf(stderr
, "%s: Unable to find module file `%s' "
90 "or `%s.vpi'.\n", name
,name
,buf
);
94 strcpy(buf
,name
); /* yes copy the name into the buffer */
100 ; (rc
!= 0) && (idx
< vpip_module_path_cnt
)
103 sprintf(buf
, "%s%c%s.vpi", vpip_module_path
[idx
], sep
, name
);
108 sprintf(buf
, "%s%c%s.vpl",
109 vpip_module_path
[idx
], sep
, name
);
115 fprintf(stderr
, "%s: Unable to find a "
116 "`%s.vpi' module on the search path.\n",
123 /* must have found some file that could possibly be a vpi module
124 * try to open it as a shared object.
126 dll
= ivl_dlopen(buf
, export_flag
);
128 /* hmm, this failed, let the user know what has really gone wrong */
129 fprintf(stderr
,"%s:`%s' failed to open using dlopen() because:\n"
130 " %s.\n",name
,buf
,dlerror());
136 void*table
= ivl_dlsym(dll
, LU
"vlog_startup_routines" TU
);
138 fprintf(stderr
, "%s: no vlog_startup_routines\n", name
);
143 vpi_mode_flag
= VPI_MODE_REGISTER
;
144 vlog_startup_routines_t
*routines
= (vlog_startup_routines_t
*)table
;
145 for (unsigned tmp
= 0 ; routines
[tmp
] ; tmp
+= 1)
147 vpi_mode_flag
= VPI_MODE_NONE
;
151 * $Log: vpi_modules.cc,v $
152 * Revision 1.18 2004/10/04 01:10:59 steve
153 * Clean up spurious trailing white space.
155 * Revision 1.17 2003/10/08 23:09:09 steve
156 * Completely support vvp32 when enabled.
158 * Revision 1.16 2003/10/02 21:30:40 steve
159 * Configure control for the vpi subdirectory.
161 * Revision 1.15 2003/02/16 02:21:20 steve
162 * Support .vpl files as loadable LIBRARIES.
164 * Revision 1.14 2003/02/09 23:33:26 steve
167 * Revision 1.13 2003/01/10 03:06:32 steve
168 * Remove vpithunk, and move libvpi to vvp directory.
170 * Revision 1.12 2002/08/12 01:35:09 steve
171 * conditional ident string using autoconfig.
173 * Revision 1.11 2002/05/18 02:34:11 steve
174 * Add vpi support for named events.
176 * Add vpi_mode_flag to track the mode of the
177 * vpi engine. This is for error checking.
179 * Revision 1.10 2002/03/05 05:31:52 steve
180 * Better linker error messages.
182 * Revision 1.9 2001/10/14 18:42:46 steve
183 * Try appending .vpi to module names with directories.
185 * Revision 1.8 2001/07/30 02:44:05 steve
186 * Cleanup defines and types for mingw compile.
188 * Revision 1.7 2001/07/28 03:29:42 steve
189 * If module name has a /, skip the path search.
191 * Revision 1.6 2001/07/26 03:13:51 steve
192 * Make the -M flag add module search paths.