Fix the debugger to finish correctly.
[iverilog.git] / vvp / vpi_modules.cc
blob30532d83a279f8284e2257321b87aa5e394be7e9
1 /*
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)
8 * any later version.
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
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: vpi_modules.cc,v 1.18 2004/10/04 01:10:59 steve Exp $"
21 #endif
23 # include "config.h"
24 # include "vpi_priv.h"
25 # include "ivl_dlfcn.h"
26 # include <stdio.h>
27 # include <string.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] = {
35 #ifdef MODULE_DIR1
36 MODULE_DIR1,
37 #endif
38 #ifdef MODULE_DIR2
39 MODULE_DIR2,
40 #endif
44 unsigned vpip_module_path_cnt = 0
45 #ifdef MODULE_DIR1
46 + 1
47 #endif
48 #ifdef MODULE_DIR2
49 + 1
50 #endif
53 void vpip_load_module(const char*name)
55 struct stat sb;
56 int rc;
57 bool export_flag = false;
58 char buf[4096];
60 #ifdef __MINGW32__
61 const char sep = '\\';
62 #else
63 const char sep = '/';
64 #endif
66 ivl_dll_t dll = 0;
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. */
72 export_flag = false;
73 rc = stat(name, &sb);
75 if (rc != 0) { /* did we find a file? */
76 /* no, try with a .vpi suffix too */
77 export_flag = false;
78 sprintf(buf, "%s.vpi", name);
79 rc = stat(buf, &sb);
81 /* Tray alwo with the .vpl suffix. */
82 if (rc != 0) {
83 export_flag = true;
84 sprintf(buf, "%s.vpl", name);
85 rc = stat(buf, &sb);
88 if (rc != 0) {
89 fprintf(stderr, "%s: Unable to find module file `%s' "
90 "or `%s.vpi'.\n", name,name,buf);
91 return;
93 } else {
94 strcpy(buf,name); /* yes copy the name into the buffer */
97 } else {
98 rc = -1;
99 for (unsigned idx = 0
100 ; (rc != 0) && (idx < vpip_module_path_cnt)
101 ; idx += 1) {
102 export_flag = false;
103 sprintf(buf, "%s%c%s.vpi", vpip_module_path[idx], sep, name);
104 rc = stat(buf,&sb);
106 if (rc != 0) {
107 export_flag = true;
108 sprintf(buf, "%s%c%s.vpl",
109 vpip_module_path[idx], sep, name);
110 rc = stat(buf,&sb);
114 if (rc != 0) {
115 fprintf(stderr, "%s: Unable to find a "
116 "`%s.vpi' module on the search path.\n",
117 name, name);
118 return;
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);
127 if(dll==0) {
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());
132 return;
136 void*table = ivl_dlsym(dll, LU "vlog_startup_routines" TU);
137 if (table == 0) {
138 fprintf(stderr, "%s: no vlog_startup_routines\n", name);
139 ivl_dlclose(dll);
140 return;
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)
146 (routines[tmp])();
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
165 * Spelling fixes.
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.