-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_mif_array_const_unkwn.cpp
196 lines (167 loc) · 4.18 KB
/
test_mif_array_const_unkwn.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
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
//
// Created by mmoiseev on 06/14/19.
//
#include "sct_assert.h"
#include <systemc.h>
// Array of modular interface with member variables and member constants
// generated as @localparam
struct mod_if : public sc_module, sc_interface
{
sc_signal<sc_uint<4>> s {"s"};
sc_uint<4> v; // localparam
unsigned w;
const unsigned c;
const unsigned d = 1;
mod_if(const sc_module_name& name, unsigned par) :
sc_module(name), c(par), v(par), w(par)
{}
sc_uint<4> getV() {
auto ll = v;
wait();
return ll;
};
};
struct mod_if2 : public sc_module, sc_interface
{
sc_signal<sc_uint<4>> s {"s"};
sc_uint<4> v; // localparam
SC_HAS_PROCESS(mod_if2);
mod_if2(const sc_module_name& name, unsigned par) :
sc_module(name), v(par)
{
SC_METHOD(mod_meth); sensitive << s;
}
sc_signal<int> t0;
void mod_meth() {
auto ll = v;
t0 = ll;
}
};
SC_MODULE(Top) {
sc_in_clk clk{"clk"};
sc_signal<bool> rst;
sc_signal<int> t;
sc_vector<mod_if> minsts{"minsts", 2, [](const char* name, size_t i)
{return new mod_if(name, i);}};
sc_vector<mod_if2> minsts2{"minsts2", 2, [](const char* name, size_t i)
{return new mod_if2(name, i+1);}};
mod_if minst{"minst", 1};
mod_if* pinst;
SC_CTOR(Top) {
pinst = new mod_if("mod_if", 1);
SC_METHOD(usedef_method); sensitive << t;
//SC_CTHREAD(usedef_thread, clk.pos());
//async_reset_signal_is(rst, true);
SC_METHOD(const_meth); sensitive << t;
SC_METHOD(record); sensitive << t;
SC_METHOD(record_array); sensitive << t;
SC_METHOD(record_array_def); sensitive << t;
}
// No @localparam for @w
sc_signal<int> t1;
void usedef_method()
{
int j = t.read();
int l = minst.v + minst.w;
if (j) {
minst.w = 1;
}
l = pinst->v + pinst->w;
if (j) {
pinst->w = 1;
}
l = minsts[1].v + minsts[1].v;
if (j) {
minsts[j].w = 1;
}
l = minsts2[j].v;
t1 = l;
}
sc_signal<int> t2;
void usedef_thread()
{
wait();
while (true) {
int l = minst.getV();
t2 = l;
wait();
}
}
sc_signal<int> t3;
void const_meth() {
int j = t.read();
if (minsts[j].c) {
j++;
}
if (minsts[j].d) {
j--;
}
t3 = j;
}
struct Simple {
bool a = false;
int b = 42;
};
Simple rec;
void record() {
int i = rec.b;
if (i) {
++i;
}
if (t.read()) rec.b = 1;
sct_assert_unknown(rec.b);
}
Simple arr[3];
sc_signal<int> t4;
void record_array() {
int k;
int j = t.read();
int i1 = arr[1].b;
int i2 = arr[j].b;
if (arr[1].b) {
k = 1;
}
if (arr[j].b) {
k = 2;
}
k = i1 ? 3 : 4;
k = i2 ? 5 : 6;
t4 = k;
}
Simple marr[3];
Simple narr[3];
sc_signal<int> t5;
void record_array_def() {
int k;
int j = t.read();
if (marr[1].b) {
k = 1;
}
if (narr[1].b) {
k = 2;
}
if (marr[j].b) {
k = 3;
}
if (narr[j].b) {
k = 4;
}
marr[0].b = 0;
narr[j].b = 0;
t5 = k;
}
};
int sc_main(int argc, char **argv)
{
sc_clock clk {"clk", sc_time(1, SC_NS)};
Top top{"top"};
top.clk(clk);
sc_start();
return 0;
}