-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_member_record1.cpp
105 lines (80 loc) · 2.25 KB
/
test_member_record1.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
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
#include "sct_assert.h"
#include "systemc.h"
// Record with member record, which has methods and fields
class A : public sc_module {
public:
sc_in_clk clk;
sc_signal<bool> nrst;
sc_signal<int> sig{"sig"};
SC_CTOR(A) {
SC_METHOD(mem_record1); sensitive << sig;
SC_CTHREAD(mem_record2, clk.pos());
async_reset_signal_is(nrst, 0);
}
template <unsigned BitSize>
struct Base {
static const unsigned SIZE = BitSize;
typedef sc_uint<SIZE> Bits_t;
Base(const int& par) : b(par) {}
bool a;
Bits_t b;
auto getB(unsigned offset) {
return (b + offset);
}
};
struct Simple : Base<8> {
using BaseT = Base<8>;
sc_uint<4> c;
Simple(const int& par) : BaseT(par) {}
auto getB(unsigned offset) {
return BaseT::getB(offset);
}
};
struct Complex {
Base<8> b;
Simple s;
Complex(const int& par) : b(par+1), s(par+2) {}
auto getB1(unsigned offset) {
return b.getB(offset);
}
auto getB2(unsigned offset) {
return s.getB(offset);
}
};
void mem_record1()
{
Complex c(sig.read());
int l = c.getB1(1) + c.getB2(2);
c.b.a = true;
c.b.b = sig.read();
c.s.b = 42;
c.s.c = l;
l = c.b.b - c.s.c;
}
Complex mc{42};
void mem_record2() {
Complex cc(11);
cc.s.a = false;
wait();
while(true) {
mc.b.b = sig.read();
cc.s.c = mc.b.b;
int l = mc.getB1(1);
l = cc.getB1(1);
wait();
}
}
};
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;
}