Fix for assertion error when expanding macro.
[iverilog.git] / vpi / sys_deposit.c
bloba17f5473740c4ddc3659a3e2cad98fe51a0012dc
1 /*
2 * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
3 * Copyright (c) 2000 Stephan Boettcher <stephan@nevis.columbia.edu>
5 * This source code is free software; you can redistribute it
6 * and/or modify it in source code form under the terms of the GNU
7 * General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ifdef HAVE_CVS_IDENT
21 #ident "$Id: sys_deposit.c,v 1.7 2007/03/14 04:05:51 steve Exp $"
22 #endif
24 # include "vpi_config.h"
26 # include "vpi_user.h"
27 # include <assert.h>
29 static PLI_INT32 sys_deposit_compiletf(PLI_BYTE8 *name)
31 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
32 vpiHandle argv = vpi_iterate(vpiArgument, callh);
33 vpiHandle target, value;
35 /* Check that there are arguments. */
36 if (argv == 0) {
37 vpi_printf("ERROR: %s requires two arguments.\n", name);
38 vpi_control(vpiFinish, 1);
39 return 0;
42 /* Check that there are at least two arguments. */
43 target = vpi_scan(argv); /* This should never be zero. */
44 value = vpi_scan(argv);
45 if (value == 0) {
46 vpi_printf("ERROR: %s requires two arguments.\n", name);
47 vpi_control(vpiFinish, 1);
48 return 0;
51 assert(target);
53 /* Check the targets type. It must be a net or a register. */
54 switch (vpi_get(vpiType, target)) {
55 case vpiNet:
56 case vpiReg:
57 break;
58 default:
59 vpi_printf("ERROR: invalid target type for %s.\n", name);
60 vpi_control(vpiFinish, 1);
61 return 0;
64 /* Check that there is at most two arguments. */
65 target = vpi_scan(argv);
66 if (target != 0) {
67 vpi_printf("ERROR: %s takes at most two arguments.\n", name);
68 vpi_control(vpiFinish, 1);
69 return 0;
72 return 0;
75 static PLI_INT32 sys_deposit_calltf(PLI_BYTE8 *name)
77 vpiHandle callh, argv, target, value;
78 s_vpi_value val;
80 callh = vpi_handle(vpiSysTfCall, 0);
81 argv = vpi_iterate(vpiArgument, callh);
82 target = vpi_scan(argv);
83 assert(target);
84 value = vpi_scan(argv);
85 assert(value);
87 val.format = vpiIntVal;
88 vpi_get_value(value, &val);
90 vpi_put_value(target, &val, 0, vpiNoDelay);
92 vpi_free_object(argv);
93 return 0;
96 void sys_deposit_register()
98 s_vpi_systf_data tf_data;
100 tf_data.type = vpiSysTask;
101 tf_data.tfname = "$deposit";
102 tf_data.calltf = sys_deposit_calltf;
103 tf_data.compiletf = sys_deposit_compiletf;
104 tf_data.sizetf = 0;
105 tf_data.user_data = "$deposit";
106 vpi_register_systf(&tf_data);
111 * $Log: sys_deposit.c,v $
112 * Revision 1.7 2007/03/14 04:05:51 steve
113 * VPI tasks take PLI_BYTE* by the standard.
115 * Revision 1.6 2006/10/30 22:45:37 steve
116 * Updates for Cygwin portability (pr1585922)
118 * Revision 1.5 2004/10/04 01:10:58 steve
119 * Clean up spurious trailing white space.
121 * Revision 1.4 2004/01/21 01:22:53 steve
122 * Give the vip directory its own configure and vpi_config.h
124 * Revision 1.3 2002/08/12 01:35:04 steve
125 * conditional ident string using autoconfig.
127 * Revision 1.2 2001/07/25 03:10:50 steve
128 * Create a config.h.in file to hold all the config
129 * junk, and support gcc 3.0. (Stephan Boettcher)
131 * Revision 1.1 2001/04/26 00:01:33 steve
132 * Support $deposit to a wire or reg.