-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_member_func_method.cpp
195 lines (150 loc) · 3.83 KB
/
test_member_func_method.cpp
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
#include "sct_assert.h"
#include "systemc.h"
using namespace sc_core;
// Local record array member call tests
template <unsigned N>
class A : public sc_module {
public:
sc_signal<sc_uint<2>> sig;
sc_signal<bool> dummy{"dummy"};
SC_CTOR(A)
{
SC_METHOD(record_meth0);
sensitive << sig;
SC_METHOD(record_meth1);
sensitive << sig;
SC_METHOD(record_meth2);
sensitive << sig;
SC_METHOD(record_meth2a);
sensitive << sig;
SC_METHOD(record_meth2b);
sensitive << sig;
SC_METHOD(record_meth3);
sensitive << sig;
SC_METHOD(record_multi_calls);
sensitive << sig;
}
struct Simple {
bool a;
void setA(bool par) {
a = par;
}
bool getA() {
return a;
}
bool localVar(bool par) {
bool l;
l = par || a;
return l;
}
};
void record_meth0()
{
Simple s[2];
s[1].setA(true);
sct_assert_const(s[1].a);
sc_uint<2> i = sig;
s[i].setA(false);
sct_assert_unknown(s[1].a);
sct_assert_array_defined(s[0].a);
}
// Call method for record array with determinable/non-determinable index
sc_signal<int> t0;
void record_meth1()
{
Simple s[2];
s[1].setA(true);
bool b = s[1].getA();
sct_assert_const(s[1].a);
sct_assert_unknown(s[0].a);
sc_uint<2> i = sig;
s[i].setA(false);
b = s[i].getA();
t0 = b;
sct_assert_unknown(s[1].a);
sct_assert_read(s[0].a);
sct_assert_array_defined(s[0].a);
}
// Call method for record array in loop
void record_meth2()
{
Simple s[2][3];
bool b = true;
for (int i = 0; i < 2; i++) {
s[i][1].setA(i);
b = b && s[i][1].getA(); // Special case, no function call here
}
}
void record_meth2a()
{
Simple s[2];
bool b = false;
for (int i = 0; i < 2; i++) {
s[i].setA(i);
b = b || s[i].getA();
}
}
// No @getA() call here as b is already true
void record_meth2b()
{
Simple s[2];
bool b = true;
for (int i = 0; i < 2; i++) {
s[i].setA(i);
b = b || s[i].getA();
}
}
// Call method with local variable
sc_signal<int> t1;
void record_meth3()
{
Simple s[2];
bool b = s[1].localVar(1);
sct_assert_unknown(s[1].a);
sct_assert_const(b);
sc_uint<2> i = sig;
b = s[i].localVar(0);
t1 = b;
sct_assert_unknown(b);
sct_assert_read(s[0].a);
sct_assert_register(s[0].a);
}
int f(int par) {
int l;
l = par + 1;
return l;
}
// Multiple method calls
sc_signal<int> t2;
void record_multi_calls()
{
Simple s[2];
sc_uint<2> i = sig;
bool b = s[i].localVar(true);
sct_assert_unknown(b);
int j = f(4);
s[i].setA(i);
s[i+1].setA( f(5) );
sct_assert_unknown(s[1].a);
auto res = f(6);
t2 = res;
sct_assert_array_defined(s[0].a);
}
};
class B_top : public sc_module {
public:
A<1> a_mod{"a_mod"};
SC_CTOR(B_top) {
}
};
int sc_main(int argc, char *argv[]) {
B_top b_mod{"b_mod"};
sc_start();
return 0;
}