-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_array_record_meth.cpp
136 lines (109 loc) · 2.88 KB
/
test_array_record_meth.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
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
#include <systemc.h>
// Record local variable and member in MIF array
struct mod_if : public sc_module, sc_interface
{
sc_signal<bool> s {"s"};
SC_CTOR(mod_if)
{
// TODO: Fix me, see #158
//SC_METHOD(useDefBug);
//sensitive << s;
SC_METHOD(memRecMeth);
sensitive << s;
// TODO: Fix me, see #158
SC_METHOD(memRecArrMeth);
sensitive << s;
}
struct Inner {
int c;
};
struct Simple {
bool a;
sc_uint<4> b[3];
Inner rec;
Inner rec_arr[2];
};
struct NotSimple {
Inner rec_arr[2];
Inner rec_oth_arr[2];
};
// ---------------------------------------------------------------------------
// Incorrect result of @getFirstArrayElementForAny() --
// return t[1].rec_arr[0].c instead of t[0].rec_arr[0].c
struct UDSimple {
Inner rec_arr[2];
};
UDSimple t[2];
void useDefBug()
{
t[1].rec_arr[1].c = 30;
}
// ---------------------------------------------------------------------------
// Member record
Simple r;
Simple rr;
NotSimple f;
sc_signal<int> t0;
void memRecMeth()
{
int minst_r_b[2];
minst_r_b[0] = 0; // name conflict with @r.b
r.b[0] = 1;
r.rec.c = 2;
rr.a = s.read();
rr.b[2] = 3;
rr.rec_arr[1].c = 4;
f.rec_arr[1].c = 5;
f.rec_oth_arr[1].c = 6;
int i = f.rec_arr[0].c + rr.rec_arr[0].c + r.b[1];
t0 = i;
}
// Member record array
Simple w[2];
NotSimple ww[3];
sc_signal<int> t1;
void memRecArrMeth()
{
w[0].a = s.read();
w[0].b[1] = 10;
w[1].rec.c = 20;
w[0].rec_arr[1].c = 30;
// TODO: Uncomment after #158 fixed
/*int sum = 0;
for (int i = 0; i < 3; ++i) {
ww[i].rec_arr[1].c = i;
sum += ww[i].rec_oth_arr[1].c;
}*/
int sum = 0;
for (int i = 0; i < 2; ++i) {
ww[0].rec_arr[i].c = i;
sum += ww[0].rec_oth_arr[i].c;
}
sc_uint<4> x = w[0].rec_arr[1].c + ww[0].rec_oth_arr[0].c;
t1 = x + sum;
// TODO: Uncomment after #158 fixed
//sc_uint<4> y = w[1].rec_arr[1].c + ww[2].rec_oth_arr[0].c;
}
};
SC_MODULE(Top)
{
mod_if* minst[2];
SC_CTOR(Top)
{
for (int i = 0; i < 2; i++) {
minst[i] = new mod_if("mod_if");
}
}
};
int sc_main(int argc, char **argv)
{
Top top{"top"};
sc_start();
return 0;
}