iverilog/libveriuser/a_fetch_tfarg.c

170 lines
4.3 KiB
C
Raw Normal View History

/* vi:sw=6
2003-06-13 21:23:41 +02:00
* Copyright (c) 2002,2003 Michael Ruff (mruff at chiaro.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
2003-06-13 21:23:41 +02:00
#ident "$Id: a_fetch_tfarg.c,v 1.7 2003/06/13 19:23:42 steve Exp $"
#endif
#include <vpi_user.h>
#include <acc_user.h>
#include "priv.h"
/*
2003-06-13 21:23:41 +02:00
* acc_fetch_tfarg and friends implemented using VPI interface
*/
2003-06-13 21:23:41 +02:00
double acc_fetch_itfarg(PLI_INT32 n, handle obj)
{
2003-06-13 21:23:41 +02:00
vpiHandle iter, hand = 0;
s_vpi_value value;
2003-06-13 21:23:41 +02:00
int idx = n;
double rtn;
iter = vpi_iterate(vpiArgument, obj);
/* scan to nth argument */
while (idx > 0 && (hand = vpi_scan(iter))) idx--;
if (hand) {
value.format=vpiRealVal;
vpi_get_value(hand, &value);
rtn = value.value.real;
vpi_free_object(iter);
} else {
rtn = 0.0;
}
if (pli_trace) {
fprintf(pli_trace, "%s: acc_fetch_itfarg(%d, %p) --> %f\n",
vpi_get_str(vpiName, obj), n, obj, rtn);
}
return rtn;
}
double acc_fetch_tfarg(int n)
{
vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
return acc_fetch_itfarg_int(n, hand);
}
PLI_INT32 acc_fetch_itfarg_int(PLI_INT32 n, handle obj)
{
vpiHandle iter, hand = 0;
s_vpi_value value;
int idx = n;
int rtn;
2003-06-13 21:23:41 +02:00
iter = vpi_iterate(vpiArgument, obj);
/* scan to nth argument */
2003-06-13 21:23:41 +02:00
while (idx > 0 && (hand = vpi_scan(iter))) idx--;
2003-06-13 21:23:41 +02:00
if (hand) {
value.format=vpiIntVal;
2003-06-13 21:23:41 +02:00
vpi_get_value(hand, &value);
rtn = value.value.integer;
2003-06-13 21:23:41 +02:00
vpi_free_object(iter);
} else {
rtn = 0;
}
if (pli_trace) {
2003-06-13 21:23:41 +02:00
fprintf(pli_trace, "%s: acc_fetch_itfarg_int(%d, %p) --> %d\n",
vpi_get_str(vpiName, obj), n, obj, rtn);
}
return rtn;
}
2003-06-13 21:23:41 +02:00
PLI_INT32 acc_fetch_tfarg_int(PLI_INT32 n)
{
vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
return acc_fetch_itfarg_int(n, hand);
}
char *acc_fetch_itfarg_str(PLI_INT32 n, handle obj)
{
2003-06-13 21:23:41 +02:00
vpiHandle iter, hand = 0;
s_vpi_value value;
int idx = n;
2003-06-13 21:23:41 +02:00
char *rtn;
2003-06-13 21:23:41 +02:00
iter = vpi_iterate(vpiArgument, obj);
/* scan to nth argument */
2003-06-13 21:23:41 +02:00
while (idx > 0 && (hand = vpi_scan(iter))) idx -= 1;
2003-06-13 21:23:41 +02:00
if (hand) {
value.format=vpiStringVal;
2003-06-13 21:23:41 +02:00
vpi_get_value(hand, &value);
rtn = __acc_newstring(value.value.str);
2003-06-13 21:23:41 +02:00
vpi_free_object(iter);
} else {
rtn = (char *) 0;
}
if (pli_trace) {
2003-06-13 21:23:41 +02:00
fprintf(pli_trace, "%s: acc_fetch_itfarg_str(%d, %p) --> \"%s\"\n",
vpi_get_str(vpiName, obj),
n, obj, rtn? rtn : "");
}
return rtn;
}
2003-06-13 21:23:41 +02:00
char *acc_fetch_tfarg_str(PLI_INT32 n)
{
vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
return acc_fetch_itfarg_str(n, hand);
}
/*
* $Log: a_fetch_tfarg.c,v $
2003-06-13 21:23:41 +02:00
* Revision 1.7 2003/06/13 19:23:42 steve
* Add a bunch more PLI1 routines.
*
* Revision 1.6 2003/05/18 00:16:35 steve
* Add PLI_TRACE tracing of PLI1 modules.
*
* Add tf_isetdelay and friends, and add
* callback return values for acc_vcl support.
*
2003-03-14 05:58:50 +01:00
* Revision 1.5 2003/03/14 04:58:50 steve
* Free the iterator when Im done.
*
* Revision 1.4 2003/03/13 04:35:09 steve
* Add a bunch of new acc_ and tf_ functions.
*
* Revision 1.3 2003/02/17 06:39:47 steve
* Add at least minimal implementations for several
* acc_ functions. Add support for standard ACC
* string handling.
*
* Add the _pli_types.h header file to carry the
* IEEE1364-2001 standard PLI type declarations.
*
* Revision 1.2 2002/08/12 01:35:02 steve
* conditional ident string using autoconfig.
*
* Revision 1.1 2002/06/07 02:58:58 steve
* Add a bunch of acc/tf functions. (mruff)
*
*/