1 | #include "systemc.h" |
---|
2 | #include <iostream> |
---|
3 | #include <fstream> |
---|
4 | #include <vector> |
---|
5 | |
---|
6 | #define ASSERT(x) { if (!(x)) { \ |
---|
7 | cerr << "ASSERT : " #x \ |
---|
8 | << " in function '" << __FUNCTION__ \ |
---|
9 | << "'\n"; exit (-1); \ |
---|
10 | } \ |
---|
11 | } |
---|
12 | |
---|
13 | |
---|
14 | using namespace std; |
---|
15 | |
---|
16 | struct D : sc_module |
---|
17 | { |
---|
18 | D (sc_module_name) |
---|
19 | { |
---|
20 | } |
---|
21 | }; |
---|
22 | |
---|
23 | struct C : sc_module |
---|
24 | { |
---|
25 | C (sc_module_name) |
---|
26 | { |
---|
27 | } |
---|
28 | }; |
---|
29 | |
---|
30 | struct B : sc_module |
---|
31 | { |
---|
32 | D d1; |
---|
33 | D d2; |
---|
34 | C c; |
---|
35 | B (sc_module_name) : d1("d1"), d2("d2"), c("c") |
---|
36 | { |
---|
37 | } |
---|
38 | }; |
---|
39 | |
---|
40 | struct A : sc_module |
---|
41 | { |
---|
42 | B b; |
---|
43 | C c; |
---|
44 | A (sc_module_name) : b("b"), c("c") |
---|
45 | { |
---|
46 | } |
---|
47 | }; |
---|
48 | |
---|
49 | struct top_level1 : sc_module |
---|
50 | { |
---|
51 | A a; |
---|
52 | D d; |
---|
53 | top_level1(sc_module_name) : a("a"), d("d") |
---|
54 | { |
---|
55 | } |
---|
56 | }; |
---|
57 | |
---|
58 | struct top_level2 : sc_module |
---|
59 | { |
---|
60 | B b1; |
---|
61 | B b2; |
---|
62 | C c; |
---|
63 | top_level2(sc_module_name) : b1("b1"), b2("b2"), c("c") |
---|
64 | { |
---|
65 | } |
---|
66 | }; |
---|
67 | |
---|
68 | void |
---|
69 | dump_hierarchy (ostream &o, sc_object *obj) |
---|
70 | { |
---|
71 | const std::vector<sc_object*> &children = obj->get_child_objects(); |
---|
72 | for (unsigned i = 0; i < children.size(); i++) |
---|
73 | if (children[i]) |
---|
74 | dump_hierarchy (o,children[i]); |
---|
75 | o << obj->name () << " " << obj->kind() << endl; |
---|
76 | } |
---|
77 | |
---|
78 | void |
---|
79 | dump_hierarchy (ostream &o, const std::vector<sc_object*> &obj_list) |
---|
80 | { |
---|
81 | for (unsigned i = 0; i < obj_list.size(); i++) |
---|
82 | dump_hierarchy(o, obj_list[i]); |
---|
83 | } |
---|
84 | |
---|
85 | int |
---|
86 | sc_main (int argc, char ** argv) |
---|
87 | { |
---|
88 | if (argc < 2) |
---|
89 | { |
---|
90 | cerr << "Usage : " << argv[0] << " <filename>\n"; |
---|
91 | exit (-1); |
---|
92 | } |
---|
93 | |
---|
94 | sc_clock clk("clock"); |
---|
95 | top_level1 top1("top1"); |
---|
96 | top_level2 top2("top2"); |
---|
97 | |
---|
98 | ofstream o; |
---|
99 | o.open (argv[1],ios::out | ios::trunc); |
---|
100 | if (o.is_open () == false) |
---|
101 | { |
---|
102 | cerr << "Unable to open '" << argv[1] << "'.\n"; |
---|
103 | return 1; |
---|
104 | } |
---|
105 | |
---|
106 | sc_start(0); |
---|
107 | dump_hierarchy (o,sc_get_top_level_objects()); |
---|
108 | |
---|
109 | ASSERT(sc_find_object("top2.b1" ) == &top2.b1 ); |
---|
110 | ASSERT(sc_find_object("top2.b1.d1" ) == &top2.b1.d1 ); |
---|
111 | ASSERT(sc_find_object("top2.b1.d2" ) == &top2.b1.d2 ); |
---|
112 | ASSERT(sc_find_object("top2.b1.c" ) == &top2.b1.c ); |
---|
113 | ASSERT(sc_find_object("top2.b2" ) == &top2.b2 ); |
---|
114 | ASSERT(sc_find_object("top2.c" ) == &top2.c ); |
---|
115 | ASSERT(sc_find_object("top1.a" ) == &top1.a ); |
---|
116 | ASSERT(sc_find_object("top1.d" ) == &top1.d ); |
---|
117 | ASSERT(sc_find_object("top1.a.b" ) == &top1.a.b ); |
---|
118 | ASSERT(sc_find_object("top1.a.b.d1") == &top1.a.b.d1); |
---|
119 | ASSERT(sc_find_object("top1.a.b.d2") == &top1.a.b.d2); |
---|
120 | ASSERT(sc_find_object("top1.a.b.c" ) == &top1.a.b.c ); |
---|
121 | ASSERT(sc_find_object("top1.a.c" ) == &top1.a.c ); |
---|
122 | ASSERT(sc_find_object("top1.c" ) == NULL ); |
---|
123 | ASSERT(sc_find_object("top1" )->get_parent_object() == NULL); |
---|
124 | ASSERT(sc_find_object("top1.a" )->get_parent_object() == &top1); |
---|
125 | ASSERT(sc_find_object("top1.a.b" )->get_parent_object() == &top1.a); |
---|
126 | ASSERT(sc_find_object("top1.a.b.d2")->get_parent_object() == &top1.a.b); |
---|
127 | ASSERT(sc_find_object("top1.d" )->get_parent_object() == &top1); |
---|
128 | ASSERT(sc_find_object("top2.b1" )->get_parent_object() == &top2); |
---|
129 | ASSERT(sc_find_object("top2.b2" )->get_parent_object() == &top2); |
---|
130 | ASSERT(sc_find_object("top2.c" )->get_parent_object() == &top2); |
---|
131 | ASSERT(sc_find_object("top2.b1.c" )->get_parent_object() == &top2.b1); |
---|
132 | #if 0 |
---|
133 | o << sc_find_object("top2.b1.d1")->name() << endl; |
---|
134 | o << sc_find_object("top2.b1.d2")->name() << endl; |
---|
135 | o << sc_find_object("top2.b1.c")->name() << endl; |
---|
136 | o << sc_find_object("top2.b2")->name() << endl; |
---|
137 | o << sc_find_object("top2.c")->name() << endl; |
---|
138 | o << sc_find_object("top1.a")->name() << endl; |
---|
139 | o << sc_find_object("top1.d")->name() << endl; |
---|
140 | o << sc_find_object("top1.a.b")->name() << endl; |
---|
141 | o << sc_find_object("top1.a.b.d1")->name() << endl; |
---|
142 | o << sc_find_object("top1.a.b.d2")->name() << endl; |
---|
143 | o << sc_find_object("top1.a.b.c")->name() << endl; |
---|
144 | o << sc_find_object("top1.a.c")->name() << endl; |
---|
145 | if (sc_find_object("top1.c") == NULL) |
---|
146 | o << "top1.c not found.\n"; |
---|
147 | else |
---|
148 | o << "top1.c found.\n"; |
---|
149 | o << sc_find_object("top2.b1.c")->get_parent_object()->name () << endl; |
---|
150 | o << sc_find_object("top1.a")->get_parent_object()->name () << endl; |
---|
151 | if (top1.get_parent_object() == NULL) |
---|
152 | o << "top1 has no parent.\n"; |
---|
153 | else |
---|
154 | o << "top1 has a parent.\n"; |
---|
155 | #endif |
---|
156 | |
---|
157 | o.close (); |
---|
158 | |
---|
159 | return 0; |
---|
160 | } |
---|
161 | |
---|