Handle nil parameter overrides
[iverilog.git] / cadpli / cadpli.c
blob02b6462c165f987ae956624fec37563af86553d9
1 /*
2 * Copyright (c) 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: cadpli.c,v 1.7 2004/09/10 00:15:45 steve Exp $"
21 #endif
23 # include <vpi_user.h>
24 # include <veriuser.h>
25 # include <stdlib.h>
26 #ifdef HAVE_MALLOC_H
27 # include <malloc.h>
28 #endif
29 # include <string.h>
30 # include <assert.h>
31 # include "ivl_dlfcn.h"
33 typedef void* (*funcvp)(void);
35 static void thunker_register(void)
37 struct t_vpi_vlog_info vlog_info;
38 void*mod;
39 void*boot;
40 struct t_tfcell*tf;
41 int idx;
43 vpi_get_vlog_info(&vlog_info);
45 for (idx = 0 ; idx < vlog_info.argc ; idx += 1) {
46 char*module, *cp, *bp;
47 if (strncmp("-cadpli=", vlog_info.argv[idx], 8) != 0)
48 continue;
50 cp = vlog_info.argv[idx] + 8;
51 assert(cp);
53 bp = strchr(cp, ':');
54 assert(bp);
56 module = malloc(bp-cp+1);
57 strncpy(module, cp, bp-cp);
58 module[bp-cp] = 0;
60 mod = ivl_dlopen(module);
61 if (mod == 0) {
62 vpi_printf("%s link: %s\n", vlog_info.argv[idx], dlerror());
63 free(module);
64 continue;
67 bp += 1;
68 boot = ivl_dlsym(mod, bp);
69 if (boot == 0) {
70 vpi_printf("%s: Symbol %s not found.\n",
71 vlog_info.argv[idx], bp);
72 free(module);
73 continue;
76 free(module);
77 assert(boot);
79 tf = (*((funcvp)boot))();
80 assert(tf);
82 veriusertfs_register_table(tf);
86 void (*vlog_startup_routines[])() = {
87 thunker_register,
93 * $Log: cadpli.c,v $
94 * Revision 1.7 2004/09/10 00:15:45 steve
95 * Remove bad casts.
97 * Revision 1.6 2004/09/05 21:19:51 steve
98 * Better type safety.
100 * Revision 1.5 2003/08/26 16:26:02 steve
101 * ifdef idents correctly.
103 * Revision 1.4 2003/04/30 01:28:06 steve
104 * Remove veriusertfs stuf.
106 * Revision 1.3 2003/02/22 04:04:38 steve
107 * Only include malloc.h if it is present.
109 * Revision 1.2 2003/02/17 00:01:25 steve
110 * Use a variant of ivl_dlfcn to do dynamic loading
111 * from within the cadpli module.
113 * Change the +cadpli flag to -cadpli, to keep the
114 * plusargs namespace clear.
116 * Revision 1.1 2003/02/16 02:23:54 steve
117 * Add the cadpli interface module.