forked from steveicarus/iverilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_fetch_tfarg.c
130 lines (106 loc) · 3.2 KB
/
a_fetch_tfarg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (c) 2002-2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <vpi_user.h>
#include <acc_user.h>
#include "priv.h"
/*
* acc_fetch_tfarg and friends implemented using VPI interface
*/
double acc_fetch_itfarg(PLI_INT32 n, handle obj)
{
vpiHandle iter, hand = 0;
s_vpi_value value;
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), (int)n, obj, rtn);
}
return rtn;
}
double acc_fetch_tfarg(PLI_INT32 n)
{
return acc_fetch_itfarg_int(n, vpi_handle(vpiSysTfCall,0));
}
PLI_INT32 acc_fetch_itfarg_int(PLI_INT32 n, handle obj)
{
vpiHandle iter, hand = 0;
s_vpi_value value;
int idx = n;
int rtn;
iter = vpi_iterate(vpiArgument, obj);
/* scan to nth argument */
while (idx > 0 && (hand = vpi_scan(iter))) idx--;
if (hand) {
value.format=vpiIntVal;
vpi_get_value(hand, &value);
rtn = value.value.integer;
vpi_free_object(iter);
} else {
rtn = 0;
}
if (pli_trace) {
fprintf(pli_trace, "%s: acc_fetch_itfarg_int(%d, %p) --> %d\n",
vpi_get_str(vpiName, obj), (int)n, obj, rtn);
}
return rtn;
}
PLI_INT32 acc_fetch_tfarg_int(PLI_INT32 n)
{
return acc_fetch_itfarg_int(n, vpi_handle(vpiSysTfCall,0));
}
char *acc_fetch_itfarg_str(PLI_INT32 n, handle obj)
{
vpiHandle iter, hand = 0;
s_vpi_value value;
int idx = n;
char *rtn;
iter = vpi_iterate(vpiArgument, obj);
/* scan to nth argument */
while (idx > 0 && (hand = vpi_scan(iter))) idx -= 1;
if (hand) {
value.format=vpiStringVal;
vpi_get_value(hand, &value);
rtn = __acc_newstring(value.value.str);
vpi_free_object(iter);
} else {
rtn = (char *) 0;
}
if (pli_trace) {
fprintf(pli_trace, "%s: acc_fetch_itfarg_str(%d, %p) --> \"%s\"\n",
vpi_get_str(vpiName, obj),
(int)n, obj, rtn? rtn : "");
}
return rtn;
}
char *acc_fetch_tfarg_str(PLI_INT32 n)
{
return acc_fetch_itfarg_str(n, vpi_handle(vpiSysTfCall,0));
}