112855Sgabeblack@google.com#include <systemc> 212855Sgabeblack@google.com#include <cstring> 312855Sgabeblack@google.comusing namespace sc_core; 412855Sgabeblack@google.comusing namespace sc_dt; 512855Sgabeblack@google.comusing std::cout; 612855Sgabeblack@google.comusing std::endl; 712855Sgabeblack@google.com 812855Sgabeblack@google.com// 10) sc_find_object, sc_get_top_level_objects 912855Sgabeblack@google.com 1012855Sgabeblack@google.comstatic int object_count = 0; 1112855Sgabeblack@google.com 1212855Sgabeblack@google.comvoid recurse_hierarchy(sc_object* obj) 1312855Sgabeblack@google.com{ 1412855Sgabeblack@google.com ++ object_count; 1512855Sgabeblack@google.com std::vector<sc_object*> children = obj->get_child_objects(); 1612855Sgabeblack@google.com for (std::vector<sc_object*>::iterator i = children.begin(); i != children.end(); i++) 1712855Sgabeblack@google.com recurse_hierarchy(*i); 1812855Sgabeblack@google.com} 1912855Sgabeblack@google.com 2012855Sgabeblack@google.comSC_MODULE(M) 2112855Sgabeblack@google.com{ 2212855Sgabeblack@google.com SC_CTOR(M) 2312855Sgabeblack@google.com : sig("sig") 2412855Sgabeblack@google.com { 2512855Sgabeblack@google.com SC_THREAD(T); 2612855Sgabeblack@google.com } 2712855Sgabeblack@google.com void T() 2812855Sgabeblack@google.com { 2912855Sgabeblack@google.com } 3012855Sgabeblack@google.com sc_signal<int> sig; 3112855Sgabeblack@google.com}; 3212855Sgabeblack@google.com 3312855Sgabeblack@google.comSC_MODULE(Top) 3412855Sgabeblack@google.com{ 3512855Sgabeblack@google.com M *m; 3612855Sgabeblack@google.com SC_CTOR(Top) 3712855Sgabeblack@google.com { 3812855Sgabeblack@google.com m = new M("m"); 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com sc_object* obj; 4112855Sgabeblack@google.com obj = sc_find_object(""); 4212855Sgabeblack@google.com sc_assert(obj == 0); 4312855Sgabeblack@google.com obj = sc_find_object("foo"); 4412855Sgabeblack@google.com sc_assert(obj == 0); 4512855Sgabeblack@google.com obj = sc_find_object("top.m.foo"); 4612855Sgabeblack@google.com sc_assert(obj == 0); 4712855Sgabeblack@google.com obj = sc_find_object("top"); 4812855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_module") == 0); 4912855Sgabeblack@google.com obj = sc_find_object("top.m"); 5012855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_module") == 0); 5112855Sgabeblack@google.com obj = sc_find_object("top.m.sig"); 5212855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_signal") == 0); 5312855Sgabeblack@google.com obj = sc_find_object("top.m.T"); 5412855Sgabeblack@google.com sc_assert(sc_process_handle(obj).valid()); 5512855Sgabeblack@google.com sc_assert(strcmp(sc_process_handle(obj).name(), "top.m.T") == 0); 5612855Sgabeblack@google.com 5712855Sgabeblack@google.com object_count = 0; 5812855Sgabeblack@google.com recurse_hierarchy(m); 5912855Sgabeblack@google.com sc_assert(object_count == 3); 6012855Sgabeblack@google.com } 6112855Sgabeblack@google.com}; 6212855Sgabeblack@google.com 6312855Sgabeblack@google.comint sc_main(int argc, char* argv[]) 6412855Sgabeblack@google.com{ 6512855Sgabeblack@google.com cout << "Should be silent..." << endl; 6612855Sgabeblack@google.com 6712855Sgabeblack@google.com std::vector<sc_object*> tops = sc_get_top_level_objects(); 6812855Sgabeblack@google.com sc_assert(tops.size() == 0); 6912855Sgabeblack@google.com 7012855Sgabeblack@google.com Top top("top"); 7112855Sgabeblack@google.com 7212855Sgabeblack@google.com tops = sc_get_top_level_objects(); 7312855Sgabeblack@google.com sc_assert(tops.size() == 1); 7412855Sgabeblack@google.com sc_assert(strcmp(tops[0]->name(), "top") == 0); 7512855Sgabeblack@google.com 7612855Sgabeblack@google.com M m2("m2"); 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com tops = sc_get_top_level_objects(); 7912855Sgabeblack@google.com sc_assert(tops.size() == 2); 8012855Sgabeblack@google.com sc_assert(strcmp(tops[0]->name(), "top") == 0); 8112855Sgabeblack@google.com sc_assert(strcmp(tops[1]->name(), "m2") == 0); 8212855Sgabeblack@google.com 8312855Sgabeblack@google.com sc_signal<int> sig("sig2"); 8412855Sgabeblack@google.com 8512855Sgabeblack@google.com tops = sc_get_top_level_objects(); 8612855Sgabeblack@google.com sc_assert(tops.size() == 3); 8712855Sgabeblack@google.com sc_assert(strcmp(tops[0]->name(), "top") == 0); 8812855Sgabeblack@google.com sc_assert(strcmp(tops[1]->name(), "m2") == 0); 8912855Sgabeblack@google.com sc_assert(strcmp(tops[2]->name(), "sig2") == 0); 9012855Sgabeblack@google.com 9112855Sgabeblack@google.com sc_object* obj; 9212855Sgabeblack@google.com obj = sc_find_object(""); 9312855Sgabeblack@google.com sc_assert(obj == 0); 9412855Sgabeblack@google.com obj = sc_find_object("foo"); 9512855Sgabeblack@google.com sc_assert(obj == 0); 9612855Sgabeblack@google.com obj = sc_find_object("top.m.foo"); 9712855Sgabeblack@google.com sc_assert(obj == 0); 9812855Sgabeblack@google.com obj = sc_find_object("top"); 9912855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_module") == 0); 10012855Sgabeblack@google.com obj = sc_find_object("sig2"); 10112855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_signal") == 0); 10212855Sgabeblack@google.com obj = sc_find_object("m2"); 10312855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_module") == 0); 10412855Sgabeblack@google.com obj = sc_find_object("top.m"); 10512855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_module") == 0); 10612855Sgabeblack@google.com obj = sc_find_object("top.m.sig"); 10712855Sgabeblack@google.com sc_assert(strcmp(obj->kind(), "sc_signal") == 0); 10812855Sgabeblack@google.com obj = sc_find_object("top.m.T"); 10912855Sgabeblack@google.com sc_assert(sc_process_handle(obj).valid()); 11012855Sgabeblack@google.com sc_assert(strcmp(sc_process_handle(obj).name(), "top.m.T") == 0); 11112855Sgabeblack@google.com 11212855Sgabeblack@google.com object_count = 0; 11312855Sgabeblack@google.com recurse_hierarchy(tops[0]); 11412855Sgabeblack@google.com sc_assert(object_count == 4); 11512855Sgabeblack@google.com 11612855Sgabeblack@google.com sc_start(); 11712855Sgabeblack@google.com 11812855Sgabeblack@google.com cout << endl << "Success" << endl; 11912855Sgabeblack@google.com return 0; 12012855Sgabeblack@google.com} 121