-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_complex_method.cpp
452 lines (352 loc) · 8.97 KB
/
test_complex_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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
#include "sct_assert.h"
#include "systemc.h"
#include <iostream>
using namespace sc_core;
// Record (structure/class) non-module tests
template <unsigned N>
class A : public sc_module {
public:
sc_signal<bool> dummy{"dummy"};
SC_CTOR(A) {
//SC_METHOD(base_record); // partially work, need to support base class ctor
//sensitive << dummy;
SC_METHOD(record_name_coll);
sensitive << dummy;
SC_METHOD(record_local_complex);
sensitive << dummy;
SC_METHOD(record_local_complex2);
sensitive << dummy;
SC_METHOD(record_fcall1);
sensitive << dummy;
SC_METHOD(record_fcall2);
sensitive << dummy;
SC_METHOD(record_fcall3);
sensitive << dummy;
SC_METHOD(record_in_bracket);
sensitive << dummy;
SC_METHOD(record_return1);
sensitive << dummy;
SC_METHOD(record_assign1);
sensitive << dummy;
// Inner records
//SC_METHOD(inner_record1_complex);
//sensitive << dummy;
//SC_METHOD(inner_record2);
//sensitive << dummy;
//SC_METHOD(inner_record3);
//sensitive << dummy;
}
struct Simple {
bool a;
int b;
};
//-----------------------------------------------------------------------------
// Record name collision
Simple g3() {
Simple r;
r.a = true;
return r;
}
void record_name_coll()
{
Simple r = g3();
r.a = false;
}
//-----------------------------------------------------------------------------
struct BaseRec {
int a;
int b = 2;
int c;
BaseRec(int a_) : a(a_) {
c = a + b;
}
};
struct InheritRec : BaseRec {
int d = 4;
int e;
InheritRec() : BaseRec(1) {
e = 5;
}
};
void base_record() {
InheritRec ir;
}
//-----------------------------------------------------------------------------
struct Rec1 {
int x;
sc_int<2> y;
sc_uint<16> var16;
sc_uint<1> flag;
sc_uint<32> var32;
Rec1() : y(1) {
x = 1;
}
};
// Local variables structure/class type
void record_local_complex()
{
Rec1 r1;
Rec1 r2;
Rec1 r3;
r1.x = r1.y + 2;
r2.x = r1.y + r2.y;
r1.var32= 0xFFFF; // 0b111
r2.var32=0xA0A0A0A0;
r3.x = r1.x | r2.x;
r3.flag = r2.flag && (r1.flag || r1.var32[0]);
if (r1.y==0) {
r2.x=r1.x+r2.y*2;
}
for (int i = 0; i<10; i++) {
r2.var16[i] = r1.var32[i*2];
}
}
struct Rec2 {
int x;
sc_uint<32> y;
sc_uint<8> z = 3;
int t{4};
int tt{5};
int s;
Rec2(int x_, int y_) : x(x_) {
if (y_>1) {
y = y_-1;
} else {
if (x_>0){
y = y_+x_;
} else {
y=y_+1;
}
}
}
Rec2() : x(1){
}
};
int f(int i) {return (i+1);}
// Local variables structure/class type
void record_local_complex2()
{
Rec2 c(2,3);
Rec2 d(3,1);
Rec2 e;
c.x = 4;
d.x = c.x + e.x;
sct_assert_const(c.x == 4);
sct_assert_const(c.y == 2);
sct_assert_unknown(c.s);
sct_assert_defined(c.x);
int a = f(1);
}
//-----------------------------------------------------------------------------
// Function with records
void f1(Simple& par) {
bool b = par.a;
par.b = 2;
}
void f1_const(const Simple& par) {
bool b = !par.a;
}
void f2(Simple par) {
bool b = par.a;
par.b = 2;
}
bool f3(Simple& par1, Simple& par2) {
bool b = par1.a;
par2.a = b;
return (par2.a || par1.a);
}
void f3_(Simple par1, Simple par2) {
//bool b = par1.a; // par2 instead of par1 !!!!
//par2.a = b; // par1 instead of par2 !!!!
}
void f3_() {
//bool b = par1.a; // par2 instead of par1 !!!!
//par2.a = b; // par1 instead of par2 !!!!
}
bool f3_2(Simple& par1, Simple& par2) {
seta(par1,true);
seta(par2,false);
return (par1.a | par2.a);
}
void record_fcall1()
{
Simple s;
s.b = 1;
f1(s);
f1_const(s);
sct_assert_read(s.a);
sct_assert_defined(s.b);
}
void record_fcall2()
{
Simple s;
s.b = 1;
f2(s);
}
void seta(Simple& op1){
op1.a=true;
}
void seta(Simple& op1, bool tf){
op1.a = tf;
}
bool f3ref(Simple& par1, Simple& par2) {
bool b = par1.a;
par2.a = b;
return (par2.a || par1.a);
}
bool f3noref(Simple par1, Simple par2) {
bool b = par1.a;
par2.a = b;
return (par2.a || par1.a);
}
Simple rec;
void record_fcall3()
{
rec.a = 1; // rec_a = 1;
int rec_a;
rec_a=5;
sct_assert_const(rec_a==5);
Simple s; Simple r;
Simple s1; Simple s2;
f3_();
bool flag;
bool flag2;
seta(s1);
seta(s2);
//flag = f3noref(s1,s2);
flag = f3ref(s1,s2);
sct_assert_const(flag);
s1.a = 0;
if (rec.a) {
int s1;
int rec_a;
s1 = 1;
rec_a = 10;
sct_assert_const(rec.a == 1);
sct_assert_const(rec_a == 10);
}
sct_assert_const(s1.a==0);
}
//-----------------------------------------------------------------------------
// Function with record in return
Simple g1() {
Simple r;
r.b = 2;
return r;
}
Simple g2() {
Simple r;
r.b = 2;
return (r);
}
void record_in_bracket()
{
Simple s;
(s).b = 1;
}
void record_return1()
{
Simple s = g1();
Simple r = g2();
cout << "s.b = " << s.b << endl;
cout << "r.b = " << r.b << endl;
//assert(s.b==2);
//sct_assert_const(s.b==2);
}
//-----------------------------------------------------------------------------
// Record assignment in declaration and binary operator
void record_assign1()
{
Simple r;
Simple s = r;
r = s;
}
//-----------------------------------------------------------------------------
// Inner structure
struct Inner {
sc_uint<3> x = 1;
sc_uint<32> z = 0xF;
Inner() {}
};
struct Outer {
sc_uint<4> y;
Inner r;
Outer() {
y = 2;
}
};
void inner_record1_complex()
{
Outer o;
Outer o2;
Outer o3;
Outer o4;
o.y = 3;
o2.y = 0x4;
o3.y = o.y | 0x4;
o.r.x = o.y + 4;
o4.r.x = o.y - 1;
o2.r.x = o.r.x;
o3.r.x = o.r.x & o2.r.x ^ o4.r.x;
sc_uint<3> a = o.r.x;
sct_assert_const(o.y == 3);
sct_assert_const(o.r.x == 7);
sct_assert_read(o.y);
sct_assert_defined(o.y);
sct_assert_read(o.r.x);
sct_assert_defined(o.r.x);
}
void inner_record2()
{
Outer o1;
Outer o2;
o1.r.x = 5;
o2.r.x = o1.r.x;
sct_assert_const(o1.r.x == 5);
sct_assert_read(o1.r.x);
sct_assert_defined(o1.r.x);
sct_assert_defined(o2.r.x);
}
// --------------------
struct Inner2 {
sc_uint<3> x = 1;
Inner2(sc_uint<3> x_) : x(x_) {}
Inner2() {}
};
struct Outer2 {
Inner2 r1;
// Inner2 r1{2}; -- not supported yet
Inner2 r2;
Outer2() : r1(2) {
r2.x = 4;
}
};
void inner_record3()
{
Outer2 o1;
Outer2 o2;
o1.r1.x = 5;
o2.r2.x = o1.r1.x;
sct_assert_const(o1.r1.x == 5);
sct_assert_read(o1.r1.x);
sct_assert_defined(o1.r1.x);
sct_assert_defined(o2.r2.x);
}
};
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;
}