Fix for assertion error when expanding macro.
[iverilog.git] / vpip / vpi_systask.c
blob392d5243c42867013bba8b5d727e7a871a258dcf
1 /*
2 * Copyright (c) 1999 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_systask.c,v 1.5 2002/08/12 01:35:06 steve Exp $"
21 #endif
23 # include "vpi_priv.h"
24 # include <stdlib.h>
25 # include <assert.h>
27 static vpiHandle systask_handle(int type, vpiHandle ref)
29 struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
30 assert((ref->vpi_type->type_code == vpiSysTaskCall)
31 || (ref->vpi_type->type_code == vpiSysFuncCall));
33 switch (type) {
34 case vpiScope:
35 return &rfp->scope->base;
36 default:
37 assert(0);
38 return 0;
43 * the iter function only supports getting an iterator of the
44 * arguments. This works equally well for tasks and functions.
46 static vpiHandle systask_iter(int type, vpiHandle ref)
48 struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
49 assert((ref->vpi_type->type_code == vpiSysTaskCall)
50 || (ref->vpi_type->type_code == vpiSysFuncCall));
52 if (rfp->nargs == 0)
53 return 0;
55 return vpip_make_iterator(rfp->nargs, rfp->args);
58 static const struct __vpirt vpip_systask_rt = {
59 vpiSysTaskCall,
64 systask_handle,
65 systask_iter
68 const struct __vpirt *vpip_get_systask_rt(void)
70 return &vpip_systask_rt;
74 * A value *can* be put to a vpiSysFuncCall object. This is how the
75 * return value is set. The value that is given should be converted to
76 * bits and set into the return value bit array.
78 static vpiHandle sysfunc_put_value(vpiHandle ref, p_vpi_value val,
79 p_vpi_time t, int flag)
81 long tmp;
82 int idx;
84 struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
85 assert(ref->vpi_type->type_code == vpiSysFuncCall);
87 /* There *must* be a return value array. */
88 assert(rfp->res);
89 assert(rfp->nres > 0);
91 /* XXXX For now, only support very specific formats. */
92 assert(val->format == vpiIntVal);
94 /* This fills the result bits with the signed value of the
95 integer. This automagically extends the sign bit by nature
96 of how the >> works in C. */
97 tmp = val->value.integer;
98 for (idx = 0 ; idx < rfp->nres ; idx += 1) {
99 rfp->res[idx] = (tmp&1) ? St1 : St0;
100 tmp >>= 1;
103 return 0;
106 static const struct __vpirt vpip_sysfunc_rt = {
107 vpiSysFuncCall,
111 sysfunc_put_value,
113 systask_iter
116 const struct __vpirt *vpip_get_sysfunc_rt(void)
118 return &vpip_sysfunc_rt;
122 * $Log: vpi_systask.c,v $
123 * Revision 1.5 2002/08/12 01:35:06 steve
124 * conditional ident string using autoconfig.
126 * Revision 1.4 2001/09/30 16:45:10 steve
127 * Fix some Cygwin DLL handling. (Venkat Iyer)
129 * Revision 1.3 2001/05/22 02:14:47 steve
130 * Update the mingw build to not require cygwin files.
132 * Revision 1.2 2001/05/20 15:09:40 steve
133 * Mingw32 support (Venkat Iyer)
135 * Revision 1.1 2001/03/14 19:27:44 steve
136 * Rearrange VPI support libraries.
138 * Revision 1.9 2000/11/01 03:19:36 steve
139 * Add the general $time system function.
141 * Revision 1.8 2000/10/28 00:51:42 steve
142 * Add scope to threads in vvm, pass that scope
143 * to vpi sysTaskFunc objects, and add vpi calls
144 * to access that information.
146 * $display displays scope in %m (PR#1)
148 * Revision 1.7 2000/10/06 23:11:39 steve
149 * Replace data references with function calls. (Venkat)
151 * Revision 1.6 2000/09/30 03:20:48 steve
152 * Cygwin port changes from Venkat
154 * Revision 1.5 2000/05/07 18:20:08 steve
155 * Import MCD support from Stephen Tell, and add
156 * system function parameter support to the IVL core.
158 * Revision 1.4 2000/05/04 03:37:59 steve
159 * Add infrastructure for system functions, move
160 * $time to that structure and add $random.
162 * Revision 1.3 2000/02/23 02:56:56 steve
163 * Macintosh compilers do not support ident.
165 * Revision 1.2 1999/12/15 04:01:14 steve
166 * Add the VPI implementation of $readmemh.
168 * Revision 1.1 1999/10/28 00:47:25 steve
169 * Rewrite vvm VPI support to make objects more
170 * persistent, rewrite the simulation scheduler
171 * in C (to interface with VPI) and add VPI support
172 * for callbacks.