1 | |
---|
2 | #include <iostream> |
---|
3 | #include <fstream> |
---|
4 | #include <vector> |
---|
5 | |
---|
6 | #include "systemc.h" |
---|
7 | #include "test.h" |
---|
8 | |
---|
9 | |
---|
10 | using namespace std; |
---|
11 | |
---|
12 | struct D : sc_module { |
---|
13 | D(sc_module_name) {} |
---|
14 | }; |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | struct C : sc_module { |
---|
19 | C(sc_module_name) {} |
---|
20 | }; |
---|
21 | |
---|
22 | |
---|
23 | struct B : sc_module { |
---|
24 | D d1; |
---|
25 | D d2; |
---|
26 | C c; |
---|
27 | B(sc_module_name) : d1("d1"), d2("d2"), c("c") {} |
---|
28 | }; |
---|
29 | |
---|
30 | |
---|
31 | struct A : sc_module { |
---|
32 | B b; |
---|
33 | C c; |
---|
34 | A(sc_module_name) : b("b"), c("c") {} |
---|
35 | }; |
---|
36 | |
---|
37 | |
---|
38 | struct top_level1 : sc_module { |
---|
39 | A a; |
---|
40 | D d; |
---|
41 | top_level1(sc_module_name) : a("a"), d("d") {} |
---|
42 | }; |
---|
43 | |
---|
44 | |
---|
45 | struct top_level2 : sc_module { |
---|
46 | B b1; |
---|
47 | B b2; |
---|
48 | C c; |
---|
49 | top_level2(sc_module_name) : b1("b1"), b2("b2"), c("c") {} |
---|
50 | }; |
---|
51 | |
---|
52 | |
---|
53 | void dump_hierarchy(ostream & o, sc_object * obj) { |
---|
54 | const vector<sc_object *> & children = obj->get_child_objects(); |
---|
55 | for (unsigned i = 0; i < children.size(); i++) { |
---|
56 | if (children[i]) { |
---|
57 | dump_hierarchy(o, children[i]); |
---|
58 | } |
---|
59 | } |
---|
60 | o << obj->name() << " " << obj->kind() << endl; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | void dump_hierarchy (ostream & o, const vector<sc_object *> & obj_list) { |
---|
65 | for (unsigned i = 0; i < obj_list.size(); i++) { |
---|
66 | dump_hierarchy(o, obj_list[i]); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | int sc_main (int argc, char ** argv) { |
---|
72 | if (argc < 2) { |
---|
73 | cerr << "Usage : " << argv[0] << " <filename>\n"; |
---|
74 | exit(-1); |
---|
75 | } |
---|
76 | |
---|
77 | // Setup number of threads open-mp to 1 with the macro threads_omp() |
---|
78 | threads_omp(); |
---|
79 | |
---|
80 | sc_clock clk("clock"); |
---|
81 | top_level1 top1("top1"); |
---|
82 | top_level2 top2("top2"); |
---|
83 | |
---|
84 | ofstream o; |
---|
85 | o.open(argv[1],ios::out | ios::trunc); |
---|
86 | if (!o.is_open()) { |
---|
87 | cerr << "Unable to open '" << argv[1] << "'.\n"; |
---|
88 | return 1; |
---|
89 | } |
---|
90 | |
---|
91 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
92 | dump_hierarchy(o, sc_get_top_level_objects()); |
---|
93 | |
---|
94 | ASSERT(sc_find_object("top2.b1" ) == &top2.b1 ); |
---|
95 | ASSERT(sc_find_object("top2.b1.d1" ) == &top2.b1.d1 ); |
---|
96 | ASSERT(sc_find_object("top2.b1.d2" ) == &top2.b1.d2 ); |
---|
97 | ASSERT(sc_find_object("top2.b1.c" ) == &top2.b1.c ); |
---|
98 | ASSERT(sc_find_object("top2.b2" ) == &top2.b2 ); |
---|
99 | ASSERT(sc_find_object("top2.c" ) == &top2.c ); |
---|
100 | ASSERT(sc_find_object("top1.a" ) == &top1.a ); |
---|
101 | ASSERT(sc_find_object("top1.d" ) == &top1.d ); |
---|
102 | ASSERT(sc_find_object("top1.a.b" ) == &top1.a.b ); |
---|
103 | ASSERT(sc_find_object("top1.a.b.d1") == &top1.a.b.d1); |
---|
104 | ASSERT(sc_find_object("top1.a.b.d2") == &top1.a.b.d2); |
---|
105 | ASSERT(sc_find_object("top1.a.b.c" ) == &top1.a.b.c ); |
---|
106 | ASSERT(sc_find_object("top1.a.c" ) == &top1.a.c ); |
---|
107 | ASSERT(sc_find_object("top1.c" ) == NULL ); |
---|
108 | ASSERT(sc_find_object("top1" )->get_parent_object() == NULL); |
---|
109 | ASSERT(sc_find_object("top1.a" )->get_parent_object() == &top1); |
---|
110 | ASSERT(sc_find_object("top1.a.b" )->get_parent_object() == &top1.a); |
---|
111 | ASSERT(sc_find_object("top1.a.b.d2")->get_parent_object() == &top1.a.b); |
---|
112 | ASSERT(sc_find_object("top1.d" )->get_parent_object() == &top1); |
---|
113 | ASSERT(sc_find_object("top2.b1" )->get_parent_object() == &top2); |
---|
114 | ASSERT(sc_find_object("top2.b2" )->get_parent_object() == &top2); |
---|
115 | ASSERT(sc_find_object("top2.c" )->get_parent_object() == &top2); |
---|
116 | ASSERT(sc_find_object("top2.b1.c" )->get_parent_object() == &top2.b1); |
---|
117 | |
---|
118 | o.close(); |
---|
119 | |
---|
120 | return 0; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | /* |
---|
125 | # Local Variables: |
---|
126 | # tab-width: 4; |
---|
127 | # c-basic-offset: 4; |
---|
128 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
129 | # indent-tabs-mode: nil; |
---|
130 | # End: |
---|
131 | # |
---|
132 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
133 | */ |
---|
134 | |
---|