2009-12-10 21:48:24 +01:00
|
|
|
/*
|
2020-12-04 00:55:22 +01:00
|
|
|
* Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.com)
|
2002-06-07 04:58:58 +02:00
|
|
|
*
|
|
|
|
|
* 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-06-07 04:58:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <vpi_user.h>
|
|
|
|
|
#include <acc_user.h>
|
2003-02-17 07:39:47 +01:00
|
|
|
#include "priv.h"
|
2002-06-07 04:58:58 +02:00
|
|
|
|
|
|
|
|
/*
|
2003-06-13 21:23:41 +02:00
|
|
|
* acc_fetch_tfarg and friends implemented using VPI interface
|
2002-06-07 04:58:58 +02:00
|
|
|
*/
|
2003-06-13 21:23:41 +02:00
|
|
|
double acc_fetch_itfarg(PLI_INT32 n, handle obj)
|
2002-06-07 04:58:58 +02:00
|
|
|
{
|
2003-06-13 21:23:41 +02:00
|
|
|
vpiHandle iter, hand = 0;
|
2002-06-07 04:58:58 +02:00
|
|
|
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);
|
2004-10-04 03:10:51 +02:00
|
|
|
rtn = value.value.real;
|
2003-06-13 21:23:41 +02:00
|
|
|
vpi_free_object(iter);
|
|
|
|
|
} else {
|
|
|
|
|
rtn = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pli_trace) {
|
|
|
|
|
fprintf(pli_trace, "%s: acc_fetch_itfarg(%d, %p) --> %f\n",
|
2009-12-10 21:48:24 +01:00
|
|
|
vpi_get_str(vpiName, obj), (int)n, obj, rtn);
|
2003-06-13 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
double acc_fetch_tfarg(PLI_INT32 n)
|
2003-06-13 21:23:41 +02:00
|
|
|
{
|
2020-12-04 00:55:22 +01:00
|
|
|
return acc_fetch_itfarg_int(n, cur_instance);
|
2003-06-13 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PLI_INT32 acc_fetch_itfarg_int(PLI_INT32 n, handle obj)
|
|
|
|
|
{
|
|
|
|
|
vpiHandle iter, hand = 0;
|
|
|
|
|
s_vpi_value value;
|
|
|
|
|
int idx = n;
|
2002-06-07 04:58:58 +02:00
|
|
|
int rtn;
|
|
|
|
|
|
2003-06-13 21:23:41 +02:00
|
|
|
iter = vpi_iterate(vpiArgument, obj);
|
2002-06-07 04:58:58 +02:00
|
|
|
|
|
|
|
|
/* scan to nth argument */
|
2003-06-13 21:23:41 +02:00
|
|
|
while (idx > 0 && (hand = vpi_scan(iter))) idx--;
|
2002-06-07 04:58:58 +02:00
|
|
|
|
2003-06-13 21:23:41 +02:00
|
|
|
if (hand) {
|
2002-06-07 04:58:58 +02:00
|
|
|
value.format=vpiIntVal;
|
2003-06-13 21:23:41 +02:00
|
|
|
vpi_get_value(hand, &value);
|
2004-10-04 03:10:51 +02:00
|
|
|
rtn = value.value.integer;
|
2003-06-13 21:23:41 +02:00
|
|
|
vpi_free_object(iter);
|
2002-06-07 04:58:58 +02:00
|
|
|
} else {
|
|
|
|
|
rtn = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-18 02:16:35 +02:00
|
|
|
if (pli_trace) {
|
2003-06-13 21:23:41 +02:00
|
|
|
fprintf(pli_trace, "%s: acc_fetch_itfarg_int(%d, %p) --> %d\n",
|
2009-12-10 21:48:24 +01:00
|
|
|
vpi_get_str(vpiName, obj), (int)n, obj, rtn);
|
2003-05-18 02:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
2002-06-07 04:58:58 +02:00
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-13 21:23:41 +02:00
|
|
|
PLI_INT32 acc_fetch_tfarg_int(PLI_INT32 n)
|
|
|
|
|
{
|
2020-12-04 00:55:22 +01:00
|
|
|
return acc_fetch_itfarg_int(n, cur_instance);
|
2003-06-13 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *acc_fetch_itfarg_str(PLI_INT32 n, handle obj)
|
2002-06-07 04:58:58 +02:00
|
|
|
{
|
2003-06-13 21:23:41 +02:00
|
|
|
vpiHandle iter, hand = 0;
|
2002-06-07 04:58:58 +02:00
|
|
|
s_vpi_value value;
|
2003-03-13 05:35:09 +01:00
|
|
|
int idx = n;
|
2003-06-13 21:23:41 +02:00
|
|
|
char *rtn;
|
2002-06-07 04:58:58 +02:00
|
|
|
|
2003-06-13 21:23:41 +02:00
|
|
|
iter = vpi_iterate(vpiArgument, obj);
|
2002-06-07 04:58:58 +02:00
|
|
|
|
|
|
|
|
/* scan to nth argument */
|
2003-06-13 21:23:41 +02:00
|
|
|
while (idx > 0 && (hand = vpi_scan(iter))) idx -= 1;
|
2002-06-07 04:58:58 +02:00
|
|
|
|
2003-06-13 21:23:41 +02:00
|
|
|
if (hand) {
|
2002-06-07 04:58:58 +02:00
|
|
|
value.format=vpiStringVal;
|
2003-06-13 21:23:41 +02:00
|
|
|
vpi_get_value(hand, &value);
|
2003-02-17 07:39:47 +01:00
|
|
|
rtn = __acc_newstring(value.value.str);
|
2003-06-13 21:23:41 +02:00
|
|
|
vpi_free_object(iter);
|
2002-06-07 04:58:58 +02:00
|
|
|
} else {
|
|
|
|
|
rtn = (char *) 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-18 02:16:35 +02:00
|
|
|
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),
|
2009-12-10 21:48:24 +01:00
|
|
|
(int)n, obj, rtn? rtn : "");
|
2003-05-18 02:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
2002-06-07 04:58:58 +02:00
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-13 21:23:41 +02:00
|
|
|
char *acc_fetch_tfarg_str(PLI_INT32 n)
|
|
|
|
|
{
|
2020-12-04 00:55:22 +01:00
|
|
|
return acc_fetch_itfarg_str(n, cur_instance);
|
2003-06-13 21:23:41 +02:00
|
|
|
}
|