plusarg.c
4.39 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <stdio.h>
#include "acc_user.h"
#include "vcsuser.h"
#define VCS
int getstr_plusarg_check(void)
{
int param_err = FALSE ;
s_tfnodeinfo string_reg ;
if (tf_nump() != 2) {
tf_error("illegal number of arguments") ;
param_err = TRUE ;
}
else {
if (tf_typep(1) != tf_string) {
tf_error("<plusarg_string> parameter must be a literal string");
param_err = TRUE ;
}
if (tf_typep(2) != tf_readwrite) {
tf_error("<string_reg> parameter must be writtable") ;
param_err = TRUE ;
}
/* commented out because of incompatibility with vcs 2.0
else {
tf_nodeinfo(2, &string_reg) ;
if (string_reg.node_type != tf_reg_node) {
tf_error("<string_reg> must be a verilog reg") ;
param_err = TRUE ;
}
if ((string_reg.node_vec_size & 0x7) != 0) {
tf_error("<string_reg> size must be a multiple of 8 bits (byte)") ;
param_err = TRUE ;
}
}
*/
}
if (param_err)
tf_error("usage: $getstr$plusarg(<startarg_string>,<vararg_string_reg>)") ;
return(!param_err) ;
}
int getstr_plusarg_call(void)
{
int status = -1 ;
char *startarg ;
char *vararg ;
s_tfexprinfo e ;
int reg_chars, not_done, group, i, length, tmp, j ;
#ifdef VCS
if (!getstr_plusarg_check()) {
tf_putp(0, status) ;
return(status) ;
}
#endif
startarg = (char *)tf_getp(1) ;
if ((vararg = mc_scan_plusargs(startarg)) != NULL) {
tf_exprinfo(2, &e) ;
reg_chars = (e.expr_vec_size >> 3) ;
if ((length = strlen(vararg)) > reg_chars)
tf_warning("$getstr$plusarg: string \"%s\" too long to put into <vararg_string_reg>", vararg) ;
else {
bzero((char *)e.expr_value_p, e.expr_ngroups * sizeof(struct t_vecval)) ;
if (vararg[0] != 0) {
not_done = 1 ;
group = 0 ;
i = length - 1 ;
while (group < e.expr_ngroups) {
tmp = 0 ;
j = 0 ;
while ((i >= 0) && j++ < 4) {
((char *)&tmp)[4-j] = vararg[i] ;
not_done = (i-- >= 0) ;
}
if (not_done) {
e.expr_value_p[group].avalbits = tmp ;
}
else {
e.expr_value_p[group].avalbits = 0 ;
}
group += 1 ;
}
status = 1 ;
}
else
status = 0 ;
tf_propagatep(2) ;
}
}
tf_putp(0, status) ;
return(status) ;
}
#ifndef VCS
int getnum_plusarg_size(void)
{
return(32) ;
}
#endif
int getnum_plusarg_check(void)
{
int param_err = FALSE ;
s_tfnodeinfo vararg_num_reg ;
if (tf_nump() != 2) {
tf_error("illegal number of arguments") ;
param_err = TRUE ;
}
else {
if (tf_typep(1) != tf_string) {
tf_error("<plusarg_string> parameter must be a literal string");
param_err = TRUE ;
}
if (tf_typep(2) != tf_readwrite) {
tf_error("<vararg_num_reg> parameter must be writtable") ;
param_err = TRUE ;
}
/* Commented out because of incompatibility with vcs 2.0
else {
tf_nodeinfo(2, &vararg_num_reg) ;
if (vararg_num_reg.node_type != tf_reg_node) {
tf_error("<vararg_num_reg> must be a verilog reg") ;
param_err = TRUE ;
}
}
*/
}
if (param_err)
tf_error("usage: $getnum$plusarg(<startarg_string>,<vararg_num_reg>)") ;
return(!param_err) ;
}
int getnum_plusarg_call(void)
{
int status = -1 ;
char *startarg ;
char *vararg ;
int num ;
#ifdef VCS
if (!getnum_plusarg_check()) {
tf_putp(0, status) ;
return(status) ;
}
#endif
startarg = (char *)tf_getp(1) ;
if ((vararg = mc_scan_plusargs(startarg)) != NULL) {
if (vararg[0] == 0)
status = 0 ;
else {
if (sscanf(vararg, "%i", (int *)&num) == 1) {
tf_putp(2, num) ;
status = 1 ;
}
else
status = -1 ;
}
}
tf_putp(0, status) ;
return(status) ;
}