During integration of a systemC virtual platform often it is desirable to traverse deep down the hierarchy of systemC and find out type of each systemC components. More over we can also get the hande of exact types by trying out dynamic cast operation on to it. Presenting a sample class to show case the concept of hierarchy scanning. This can be further utilized to build complex utilities. For example using this I was able to build a text based systemC pin connector.
//Source Code
class scan_hierarchy_t
{
public:
scan_hierarchy_t(const char * file_name)
{
hierarchy_scan_fp = fopen(file_name,"w");
}
void scan(sc_object* obj)
{
if(hierarchy_scan_fp)
{
scan_hierarchy(obj);
}
}
private:
void scan_hierarchy(sc_object* obj)
{
std::vector<sc_object*> children = obj->get_child_objects();
for (unsigned i = 0; i < children.size(); i++ )
{
if( children[i] )
{
fprintf(hierarchy_scan_fp,"Name:%s,Type:%s\n",children[i]->name(),children[i]->kind());
scan_hierarchy( children[i] );
}
}
fflush(hierarchy_scan_fp);
}
private:
FILE * hierarchy_scan_fp;
};
No comments:
Post a Comment