-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_mif_const2.cpp
145 lines (119 loc) · 2.95 KB
/
test_mif_const2.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
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
#include <systemc.h>
// Constants and static constants in MIF instance and MIF array,
// accessed from MIF and parent METHOD
struct mod_if : public sc_module, sc_interface
{
sc_in_clk clk{"clk"};
sc_in<int> in;
sc_signal<int> t;
static const unsigned A = 42;
static const unsigned AA = 42;
static const unsigned AAA = 42;
const unsigned B = 43;
static const unsigned C = 44;
static const unsigned D = 45;
static const unsigned N = C;
static const unsigned M = N+1;
SC_CTOR(mod_if)
{
SC_METHOD(mifProc);
sensitive << in;
}
void mifProc()
{
unsigned i = N + A + B;
if (M) {
t = i;
}
}
};
struct mod_if2 : public sc_module, sc_interface
{
sc_in_clk clk{"clk"};
sc_in<int> in;
sc_signal<int> t;
static const unsigned A = 52;
static constexpr unsigned B = 53;
const unsigned C = 54;
SC_CTOR(mod_if2)
{
SC_METHOD(mifProc);
sensitive << in;
}
void mifProc()
{
const unsigned L = 56;
unsigned i = B + C + L;
t = i;
}
};
SC_MODULE(Top)
{
sc_in_clk clk{"clk"};
mod_if minst{"minst"};
mod_if* pminst;
mod_if2* aminst[2];
sc_signal<int> s;
sc_signal<int> t;
SC_CTOR(Top) {
pminst = new mod_if("pminst");
minst.clk(clk);
minst.in(s);
pminst->clk(clk);
pminst->in(s);
aminst[0] = new mod_if2("aminst0");
aminst[1] = new mod_if2("aminst1");
aminst[0]->clk(clk);
aminst[0]->in(s);
aminst[1]->clk(clk);
aminst[1]->in(s);
SC_METHOD(topProc);
sensitive << s;
SC_METHOD(topProcPtr);
sensitive << s;
SC_METHOD(topProcArr);
sensitive << s;
}
void topProc()
{
unsigned i;
i = (minst.B == 43) ? mod_if::A : 1;
i = mod_if::AA;
i = minst.AAA;
if (mod_if::C) {
t = i + mod_if::D;
}
}
sc_signal<int> t1;
void topProcPtr()
{
unsigned i;
if (pminst->B == 43) {
int i = (*pminst).A + pminst->AA;
}
t1 = i;
}
sc_signal<int> t2;
void topProcArr()
{
unsigned i;
if (aminst[0]->B) {
int i = aminst[0]->A + aminst[1]->B + aminst[1]->C;
}
t2 = i;
}
};
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;
}