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)
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
20 #ident "$Id: getp.c,v 1.7 2004/10/04 01:10:56 steve Exp $"
25 # include <veriuser.h>
26 # include <vpi_user.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;
40 /* get task/func handle */
41 sys_h
= (vpiHandle
)obj
;
42 sys_i
= vpi_iterate(vpiArgument
, sys_h
);
46 if (!(arg_h
= vpi_scan(sys_i
))) { goto out
; }
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 */
58 value
.format
= vpiIntVal
;
59 vpi_get_value(arg_h
, &value
);
60 rtn
= value
.value
.integer
;
63 vpi_free_object(sys_i
);
67 fprintf(pli_trace
, "tf_igetp(n=%d, obj=%p) --> %d\n",
74 PLI_INT32
tf_getp(PLI_INT32 n
)
76 int rtn
= tf_igetp(n
, vpi_handle(vpiSysTfCall
, 0));
82 double tf_igetrealp(PLI_INT32 n
, void *obj
)
84 vpiHandle sys_h
, sys_i
, arg_h
= 0;
90 /* get task/func handle */
91 sys_h
= (vpiHandle
)obj
;
92 sys_i
= vpi_iterate(vpiArgument
, sys_h
);
96 if (!(arg_h
= vpi_scan(sys_i
))) { goto out
; }
100 if (vpi_get(vpiType
, arg_h
) == vpiConstant
&&
101 vpi_get(vpiConstType
, arg_h
) == vpiStringConst
)
105 value
.format
= vpiRealVal
;
106 vpi_get_value(arg_h
, &value
);
107 rtn
= value
.value
.real
;
110 vpi_free_object(sys_i
);
114 fprintf(pli_trace
, "tf_igetrealp(n=%d, obj=%p) --> %f\n",
121 double tf_getrealp(PLI_INT32 n
)
123 double rtn
= tf_igetrealp(n
, vpi_handle(vpiSysTfCall
, 0));
129 char *tf_istrgetp(PLI_INT32 n
, PLI_INT32 fmt
, void *obj
)
131 vpiHandle sys_h
, sys_i
, arg_h
= 0;
137 /* get task/func handle */
138 sys_h
= (vpiHandle
)obj
;
139 sys_i
= vpi_iterate(vpiArgument
, sys_h
);
143 if (!(arg_h
= vpi_scan(sys_i
))) { goto out
; }
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
;
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
);
171 fprintf(pli_trace
, "tf_istrgetp(n=%d, fmt=%c, obj=%p) --> \"%s\"\n",
178 char *tf_strgetp(PLI_INT32 n
, PLI_INT32 fmt
)
180 char *rtn
= tf_istrgetp(n
, fmt
, vpi_handle(vpiSysTfCall
, 0));
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)