[55] | 1 | |
---|
[1] | 2 | #include <iostream> |
---|
| 3 | #include <fstream> |
---|
| 4 | #include <vector> |
---|
| 5 | |
---|
[55] | 6 | #include "systemc.h" |
---|
| 7 | #include "test.h" |
---|
[1] | 8 | |
---|
| 9 | |
---|
| 10 | using namespace std; |
---|
| 11 | |
---|
[55] | 12 | struct D : sc_module { |
---|
| 13 | D(sc_module_name) {} |
---|
[1] | 14 | }; |
---|
| 15 | |
---|
[55] | 16 | |
---|
| 17 | |
---|
| 18 | struct C : sc_module { |
---|
| 19 | C(sc_module_name) {} |
---|
[1] | 20 | }; |
---|
| 21 | |
---|
[55] | 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") {} |
---|
[1] | 28 | }; |
---|
| 29 | |
---|
[55] | 30 | |
---|
| 31 | struct A : sc_module { |
---|
| 32 | B b; |
---|
| 33 | C c; |
---|
| 34 | A(sc_module_name) : b("b"), c("c") {} |
---|
[1] | 35 | }; |
---|
| 36 | |
---|
[55] | 37 | |
---|
| 38 | struct top_level1 : sc_module { |
---|
| 39 | A a; |
---|
| 40 | D d; |
---|
| 41 | top_level1(sc_module_name) : a("a"), d("d") {} |
---|
[1] | 42 | }; |
---|
| 43 | |
---|
[55] | 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") {} |
---|
[1] | 50 | }; |
---|
| 51 | |
---|
[55] | 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; |
---|
[1] | 61 | } |
---|
| 62 | |
---|
[55] | 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 | } |
---|
[1] | 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
[55] | 71 | int sc_main (int argc, char ** argv) { |
---|
| 72 | if (argc < 2) { |
---|
| 73 | cerr << "Usage : " << argv[0] << " <filename>\n"; |
---|
| 74 | exit(-1); |
---|
| 75 | } |
---|
[1] | 76 | |
---|
[60] | 77 | // Setup number of threads open-mp to 1 with the macro threads_omp() |
---|
| 78 | threads_omp(); |
---|
| 79 | |
---|
[55] | 80 | sc_clock clk("clock"); |
---|
| 81 | top_level1 top1("top1"); |
---|
| 82 | top_level2 top2("top2"); |
---|
[1] | 83 | |
---|
[55] | 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 | } |
---|
[1] | 90 | |
---|
[55] | 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; |
---|
[1] | 121 | } |
---|
| 122 | |
---|
[55] | 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 | |
---|