Fix for assertion error when expanding macro.
[iverilog.git] / vpi / sys_vcdoff.c
blobd9600b0c932916486d8c626567e22ba7161d6462
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: sys_vcdoff.c,v 1.5 2007/03/14 04:05:52 steve Exp $"
21 #endif
23 # include "sys_priv.h"
26 * This file contains the implementations of the VCD related
27 * functions. These are stub versions
30 # include "vpi_user.h"
31 # include <stdio.h>
32 # include <stdlib.h>
33 # include <string.h>
34 # include <assert.h>
35 # include <time.h>
36 #ifdef HAVE_MALLOC_H
37 # include <malloc.h>
38 #endif
39 # include "vcd_priv.h"
42 static FILE*dump_file = 0;
44 static PLI_INT32 sys_dumpoff_calltf(PLI_BYTE8*name)
46 return 0;
49 static PLI_INT32 sys_dumpon_calltf(PLI_BYTE8*name)
51 return 0;
54 static PLI_INT32 sys_dumpall_calltf(PLI_BYTE8*name)
56 return 0;
59 static void open_dumpfile(const char*path)
61 dump_file = fopen(path, "w");
63 if (dump_file == 0) {
64 vpi_mcd_printf(6,
65 "VCD Error: Unable to open %s for output.\n",
66 path);
67 return;
68 } else {
69 fprintf(dump_file, "VCD Dump suppressed.\n");
73 static PLI_INT32 sys_dumpfile_calltf(PLI_BYTE8*name)
75 char*path;
77 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
78 vpiHandle argv = vpi_iterate(vpiArgument, sys);
79 vpiHandle item;
81 if (argv && (item = vpi_scan(argv))) {
82 s_vpi_value value;
84 if (vpi_get(vpiType, item) != vpiConstant
85 || vpi_get(vpiConstType, item) != vpiStringConst) {
86 vpi_mcd_printf(6,
87 "VCD Error:"
88 " %s parameter must be a string constant\n",
89 name);
90 return 0;
93 value.format = vpiStringVal;
94 vpi_get_value(item, &value);
95 path = strdup(value.value.str);
97 vpi_free_object(argv);
99 } else {
100 path = strdup("dumpfile.vcd");
103 if (dump_file) {
104 fclose(dump_file);
105 dump_file = 0;
108 assert(dump_file == 0);
109 open_dumpfile(path);
111 free(path);
113 return 0;
116 static PLI_INT32 sys_dumpvars_calltf(PLI_BYTE8*name)
118 if (dump_file == 0) {
119 open_dumpfile("dumpfile.vcd");
120 if (dump_file == 0)
121 return 0;
124 return 0;
127 void sys_vcdoff_register()
129 s_vpi_systf_data tf_data;
131 tf_data.type = vpiSysTask;
132 tf_data.tfname = "$dumpall";
133 tf_data.calltf = sys_dumpall_calltf;
134 tf_data.compiletf = 0;
135 tf_data.sizetf = 0;
136 tf_data.user_data = "$dumpall";
137 vpi_register_systf(&tf_data);
139 tf_data.type = vpiSysTask;
140 tf_data.tfname = "$dumpoff";
141 tf_data.calltf = sys_dumpoff_calltf;
142 tf_data.compiletf = 0;
143 tf_data.sizetf = 0;
144 tf_data.user_data = "$dumpoff";
145 vpi_register_systf(&tf_data);
147 tf_data.type = vpiSysTask;
148 tf_data.tfname = "$dumpon";
149 tf_data.calltf = sys_dumpon_calltf;
150 tf_data.compiletf = 0;
151 tf_data.sizetf = 0;
152 tf_data.user_data = "$dumpon";
153 vpi_register_systf(&tf_data);
155 tf_data.type = vpiSysTask;
156 tf_data.tfname = "$dumpfile";
157 tf_data.calltf = sys_dumpfile_calltf;
158 tf_data.compiletf = 0;
159 tf_data.sizetf = 0;
160 tf_data.user_data = "$dumpfile";
161 vpi_register_systf(&tf_data);
163 tf_data.type = vpiSysTask;
164 tf_data.tfname = "$dumpvars";
165 tf_data.calltf = sys_dumpvars_calltf;
166 tf_data.compiletf = sys_vcd_dumpvars_compiletf;
167 tf_data.sizetf = 0;
168 tf_data.user_data = "$dumpvars";
169 vpi_register_systf(&tf_data);
173 * $Log: sys_vcdoff.c,v $
174 * Revision 1.5 2007/03/14 04:05:52 steve
175 * VPI tasks take PLI_BYTE* by the standard.
177 * Revision 1.4 2006/10/30 22:45:38 steve
178 * Updates for Cygwin portability (pr1585922)
180 * Revision 1.3 2004/10/04 01:10:58 steve
181 * Clean up spurious trailing white space.
183 * Revision 1.2 2004/01/21 01:22:53 steve
184 * Give the vip directory its own configure and vpi_config.h
186 * Revision 1.1 2003/03/06 20:04:42 steve
187 * Add means to suppress wveform output