Clean up warnings for round() function declaration.
[iverilog.git] / libveriuser / getp.c
blob5e074bdd88a4bcdc53eb126c3be56c95d7ed6c5e
1 /* vi:sw=6
2 * Copyright (c) 2002,2003 Michael Ruff (mruff at chiaro.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: getp.c,v 1.7 2004/10/04 01:10:56 steve Exp $"
21 #endif
23 # include <assert.h>
24 # include <ctype.h>
25 # include <veriuser.h>
26 # include <vpi_user.h>
27 # include "priv.h"
30 * tf_getp and friends, implemented using VPI interface
32 PLI_INT32 tf_igetp(PLI_INT32 n, void *obj)
34 vpiHandle sys_h, sys_i, arg_h = 0;
35 s_vpi_value value;
36 int rtn = 0;
38 assert(n > 0);
40 /* get task/func handle */
41 sys_h = (vpiHandle)obj;
42 sys_i = vpi_iterate(vpiArgument, sys_h);
44 /* find nth arg */
45 while (n > 0) {
46 if (!(arg_h = vpi_scan(sys_i))) { goto out; }
47 n--;
50 /* If it is a constant string, return a pointer to it else int value */
51 if (vpi_get(vpiType, arg_h) == vpiConstant &&
52 vpi_get(vpiConstType, arg_h) == vpiStringConst)
54 value.format = vpiStringVal;
55 vpi_get_value(arg_h, &value);
56 rtn = (int) value.value.str; /* Oh my */
57 } else {
58 value.format = vpiIntVal;
59 vpi_get_value(arg_h, &value);
60 rtn = value.value.integer;
63 vpi_free_object(sys_i);
65 out:
66 if (pli_trace) {
67 fprintf(pli_trace, "tf_igetp(n=%d, obj=%p) --> %d\n",
68 n, obj, rtn);
71 return rtn;
74 PLI_INT32 tf_getp(PLI_INT32 n)
76 int rtn = tf_igetp(n, vpi_handle(vpiSysTfCall, 0));
78 return rtn;
82 double tf_igetrealp(PLI_INT32 n, void *obj)
84 vpiHandle sys_h, sys_i, arg_h = 0;
85 s_vpi_value value;
86 double rtn = 0.0;
88 assert(n > 0);
90 /* get task/func handle */
91 sys_h = (vpiHandle)obj;
92 sys_i = vpi_iterate(vpiArgument, sys_h);
94 /* find nth arg */
95 while (n > 0) {
96 if (!(arg_h = vpi_scan(sys_i))) { goto out; }
97 n--;
100 if (vpi_get(vpiType, arg_h) == vpiConstant &&
101 vpi_get(vpiConstType, arg_h) == vpiStringConst)
103 rtn = 0.0;
104 } else {
105 value.format = vpiRealVal;
106 vpi_get_value(arg_h, &value);
107 rtn = value.value.real;
110 vpi_free_object(sys_i);
112 out:
113 if (pli_trace) {
114 fprintf(pli_trace, "tf_igetrealp(n=%d, obj=%p) --> %f\n",
115 n, obj, rtn);
118 return rtn;
121 double tf_getrealp(PLI_INT32 n)
123 double rtn = tf_igetrealp(n, vpi_handle(vpiSysTfCall, 0));
125 return rtn;
129 char *tf_istrgetp(PLI_INT32 n, PLI_INT32 fmt, void *obj)
131 vpiHandle sys_h, sys_i, arg_h = 0;
132 s_vpi_value value;
133 char *rtn = 0;
135 assert(n > 0);
137 /* get task/func handle */
138 sys_h = (vpiHandle)obj;
139 sys_i = vpi_iterate(vpiArgument, sys_h);
141 /* find nth arg */
142 while (n > 0) {
143 if (!(arg_h = vpi_scan(sys_i))) { goto out; }
144 n--;
147 if (vpi_get(vpiType, arg_h) == vpiConstant &&
148 vpi_get(vpiConstType, arg_h) == vpiStringConst)
150 value.format = vpiStringVal;
151 vpi_get_value(arg_h, &value);
152 rtn = value.value.str;
153 } else {
154 value.format = -1;
155 switch (tolower(fmt)) {
156 case 'b': value.format = vpiBinStrVal; break;
157 case 'o': value.format = vpiOctStrVal; break;
158 case 'd': value.format = vpiDecStrVal; break;
159 case 'h': value.format = vpiHexStrVal; break;
161 if (value.format > 0) {
162 vpi_get_value(arg_h, &value);
163 rtn = value.value.str;
167 vpi_free_object(sys_i);
169 out:
170 if (pli_trace) {
171 fprintf(pli_trace, "tf_istrgetp(n=%d, fmt=%c, obj=%p) --> \"%s\"\n",
172 n, fmt, obj, rtn);
175 return rtn;
178 char *tf_strgetp(PLI_INT32 n, PLI_INT32 fmt)
180 char *rtn = tf_istrgetp(n, fmt, vpi_handle(vpiSysTfCall, 0));
182 return rtn;
186 * $Log: getp.c,v $
187 * Revision 1.7 2004/10/04 01:10:56 steve
188 * Clean up spurious trailing white space.
190 * Revision 1.6 2003/06/17 16:55:07 steve
191 * 1) setlinebuf() for vpi_trace
192 * 2) Addes error checks for trace file opens
193 * 3) removes now extraneous flushes
194 * 4) fixes acc_next() bug
196 * Revision 1.5 2003/05/30 04:22:13 steve
197 * Add tf_strgetp functions.
199 * Revision 1.4 2003/05/29 03:46:21 steve
200 * Add tf_getp/putp support for integers
201 * and real valued arguments.
203 * Add tf_mipname function.
205 * Revision 1.3 2003/03/15 05:42:39 steve
206 * free argument iterators.
208 * Revision 1.2 2002/08/12 01:35:02 steve
209 * conditional ident string using autoconfig.
211 * Revision 1.1 2002/06/07 02:58:59 steve
212 * Add a bunch of acc/tf functions. (mruff)