-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_chan_const_field.cpp
146 lines (111 loc) · 3.1 KB
/
test_chan_const_field.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 "sct_assert.h"
#include "systemc.h"
#include <iostream>
using namespace sc_core;
// Record (structure/class) with constant and static constant fields used
// as channel type
const int G = 44;
namespace ns {
const int GN = 45;
}
const unsigned W = 5;
typedef sc_uint<W> WType_t;
enum E: uint8_t {
eVal0 = 0,
eVal1 = 1,
eVal2 = 2
};
// ----------------------------------------------------------------------------
struct LRec {
int y;
inline LRec(int par) : y(par) {}
bool operator == (const LRec& other) {
return (y == other.y);
}
inline friend std::ostream& operator<< (std::ostream& os, const LRec &obj) {
return os;
}
};
// ----------------------------------------------------------------------------
struct Rec {
//const int C = 42; -- error reported OK
static const int S = 43;
int x;
//Rec& operator = (const Rec& other) {x = other.x; return *this;}
int f(int par) {
const int L = 41;
static const int SL = 42;
return (par+L+SL);
}
inline E getE(uint8_t par) const {
return E(par);
}
inline LRec getL(int par) {
LRec lrec(par);
return lrec;
}
bool operator == (const Rec& other) {
return (x == other.x);
}
};
inline ::std::ostream& operator << (::std::ostream& os, const Rec& s) {
return os;
}
namespace sc_core {
void sc_trace(sc_trace_file* , const Rec&, const std::string&) {}
}
// ----------------------------------------------------------------------------
class A : public sc_module {
public:
sc_in_clk clk{"clk"};
sc_signal<bool> nrst{"nrst"};
sc_signal<int> s{"s"};
sc_signal<Rec> rs{"rs"};
sc_vector<sc_signal<Rec>> rv{"rv", 2};
SC_CTOR(A) {
SC_METHOD(record_channel_meth); sensitive << s << rs;
SC_METHOD(record_channel_arr_meth); sensitive << rv[0] << rv[1] << s;
}
// ----------------------------------------------------------------------------
sc_signal<int> t0;
void record_channel_meth() {
Rec r;
Rec t;
r = t;
t0 = r.x + r.S + Rec::S;
r = rs.read();
t0 = r.f(r.x + G + ns::GN);
r = rs;
rs.write(r);
rs = r;
int x = rs.read().x;
t0 = x + r.x;
LRec l = r.getL(s.read());
t0 = l.y;
t0 = r.getE(s.read());
WType_t i = r.x;
t0 = i;
}
sc_signal<int> t1;
void record_channel_arr_meth() {
Rec r = rv[0];
if (rv[1].read().x == 1) {
r = rv[s.read()];
}
Rec t(rv[1]);
}
};
int sc_main(int argc, char *argv[])
{
sc_clock clk("clk", 1 , SC_NS);
A a_mod{"a_mod"};
a_mod.clk(clk);
sc_start();
return 0;
}