Changeset 55 for sources/test_regression/16062005b/system.cpp
- Timestamp:
- May 28, 2013, 11:17:14 AM (11 years ago)
- Location:
- sources/test_regression/16062005b
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
sources/test_regression/16062005b/system.cpp
r1 r55 1 #include "systemc.h" 1 2 2 #include <iostream> 3 3 #include <fstream> 4 4 #include <vector> 5 5 6 #define ASSERT(x) { if (!(x)) { \ 7 cerr << "ASSERT : " #x \ 8 << " in function '" << __FUNCTION__ \ 9 << "'\n"; exit (-1); \ 10 } \ 11 } 12 6 #include "systemc.h" 7 #include "test.h" 13 8 14 9 using namespace std; 15 10 16 struct D : sc_module 17 { 18 D (sc_module_name) 19 { 20 } 11 12 struct intramoldu : sc_module { 13 sc_signal<long> reg_long; 14 intramoldu(sc_module_name n) {} 21 15 }; 22 16 23 struct C : sc_module 24 { 25 C (sc_module_name) 26 { 27 } 17 18 19 struct moldu : sc_module { 20 sc_in<bool> i_bool; 21 sc_in<int > i_int; 22 sc_in<sc_int<17> > i_sc_int17; 23 sc_out<int > o_int; 24 sc_out<sc_uint<38> > o_sc_uint38; 25 sc_signal<sc_lv<8> > reg_lv8; 26 sc_signal<int> reg_int; 27 sc_signal<unsigned int> reg_uint; 28 sc_signal<sc_uint<3> > reg_sc_uint3; 29 sc_signal<sc_int<31> > reg_sc_int31; 30 sc_in_clk i_clk; 31 intramoldu microarchitecture; 32 moldu(sc_module_name n) : 33 i_bool ("i_bool"), 34 i_int ("i_int"), 35 i_sc_int17 ("i_sc_int17"), 36 o_int ("o_int"), 37 o_sc_uint38("o_sc_uint38"), 38 reg_lv8 ("reg_lv8"), 39 reg_int ("reg_int"), 40 reg_uint ("reg_uint"), 41 reg_sc_uint3 ("reg_sc_uint3"), 42 reg_sc_int31 ("reg_sc_int31"), 43 microarchitecture ("intern_module_of_moldu") {} 28 44 }; 29 45 30 struct B : sc_module31 {32 D d1;33 D d2;34 C c;35 B (sc_module_name) : d1("d1"), d2("d2"), c("c")36 {37 }38 };39 46 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; 47 void dump_objects (ofstream & o, const vector<sc_object *> & obj_list) { 48 for (unsigned i = 0; i < obj_list.size(); i++) { 49 const sc_object * obj = obj_list[i]; 50 if (obj == NULL) { 51 o << "\nError : NULL pointer in objects list !\n"; 52 } 53 else { 54 o << ((i != 0) ? ", " : "") << obj->name(); 55 } 56 } 57 o << "\n"; 76 58 } 77 59 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]); 60 61 int sc_main (int argc, char ** argv) { 62 if (argc < 2) { 63 cerr << "Usage : " << argv[0] << " <filename>\n"; 64 exit(-1); 65 } 66 67 ofstream o; 68 o.open (argv[1], ios::out | ios::trunc); 69 if (!o.is_open()) { 70 cerr << "Unable to open '" << argv[1] << "'.\n"; 71 return 1; 72 } 73 74 sc_clock s_clk("s_clk"); 75 sc_signal<bool> s_bool; 76 sc_signal<int> s_int; 77 sc_signal< sc_int<17> > s_sc_int17; 78 sc_signal< sc_uint<38> > s_sc_uint38; 79 moldu m("m"); 80 intramoldu microarchitecture("top_level_module"); 81 m.i_clk(s_clk); 82 m.i_bool(s_bool); 83 m.i_int(s_int); 84 m.i_sc_int17(s_sc_int17); 85 m.o_int(s_int); 86 m.o_sc_uint38(s_sc_uint38); 87 88 sc_start(sc_time(0, sc_core::SC_NS)); 89 o << "Top level :\n"; 90 dump_objects(o, sc_get_top_level_objects()); 91 o << "\nChild of \"m\" :\n"; 92 dump_objects(o, m.get_child_objects()); 93 o << "\nChild of \"m.intern_module_of_moldu\" :\n"; 94 dump_objects(o, m.microarchitecture.get_child_objects()); 95 o << "\nChild of \"top_level_module\" :\n"; 96 dump_objects(o, microarchitecture.get_child_objects()); 97 98 o.close(); 99 100 return 0; 83 101 } 84 102 85 int86 sc_main (int argc, char ** argv)87 {88 if (argc < 2)89 {90 cerr << "Usage : " << argv[0] << " <filename>\n";91 exit (-1);92 }93 103 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 } 104 /* 105 # Local Variables: 106 # tab-width: 4; 107 # c-basic-offset: 4; 108 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 109 # indent-tabs-mode: nil; 110 # End: 111 # 112 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 113 */ 105 114 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 0133 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 else148 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 else154 o << "top1 has a parent.\n";155 #endif156 157 o.close ();158 159 return 0;160 }161
Note: See TracChangeset
for help on using the changeset viewer.