Jump to content

Recommended Posts

Posted

Hi,

 

In my design I have one module instantiated 3 level down the hierarchy from sc_main. And I want to get the full hierarchical path inside that module as I have to generate different files based on the full hierarchy path.

 

To do that I have used-

 

sc_module(my_module)

{

 

const char *instance_name;

 

sc_has_process(my_module);

 

my_module(sc_module_name name) : sc_module(name)
{
instance_name = name;
 
 
 
}
 
 
};
 
 
By doing this at "instance_name" I am getting only one level hierarchy, not the full hierarchy. Can you inform me how to get full hierarchy path inside any module?
 
 
Posted

Hello,

SystemC has built-in method to get hierarchical name of objects of classes derived from sc_object (including sc_modules):

 

const char* name() const;
Member function name shall return the hierarchical name of the sc_object instance in the object
hierarchy.
 
 
You can check LRM 5.16.5 : name, basename, and kind.
Posted

Hello Roman,

 

But how to use it inside code? Can you give example for this?

 

 

Somewhere I had see that sc_module_name also gives instance name. I have used it in my code and it also giving one level hierarchy, but not the full hierarchy starting from top.

 

And I need full hierarchy starting from top i.e. sc_main in my code.

Posted

Just call a method name() of the object you need to get hierarchical name:

#include "systemc.h"

SC_MODULE(submod) {
   sc_in <bool> some_in_port{ "some_in_port" };
   SC_CTOR(submod) {}
};

SC_MODULE(topmod) {
   submod submod_inst0{ "submod_inst0" };
   submod submod_inst1{ "submod_inst1" };
   sc_signal <bool> some_sig0{ "some_sig0" };
   sc_signal <bool> some_sig1{ "some_sig1" };

   SC_CTOR(topmod) {
      submod_inst0.some_in_port(some_sig0);
      submod_inst1.some_in_port(some_sig1);
      SC_THREAD(test_thread);
   }

   void test_thread() {
      cout << name() << endl;
      cout << submod_inst0.name() << endl;
      cout << submod_inst1.some_in_port.name() << endl;
      cout << some_sig0.name() << endl;
      sc_stop();
   }
};


int sc_main(int, char**) {
   topmod topmod_inst{ "topmod_inst" };
   sc_start();
   return 0;
}

Output:

        SystemC 2.3.1-Accellera --- Mar 24 2016 23:58:05
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED
topmod_inst
topmod_inst.submod_inst0
topmod_inst.submod_inst1.some_in_port
topmod_inst.some_sig0

Info: /OSCI/SystemC: Simulation stopped by user.
Posted

Hello Roman,

 

Thanks for the information.

 

I have identified the issue. Previously I used like below-

 

sc_module(my_module)

{

 

const char *instance_name;

 

sc_has_process(my_module);

 

my_module(sc_module_name name) : sc_module(name)
{
instance_name = name;
 
 
 
}
 
 
};
 
Now I have changed my code like below-

sc_module(my_module)

{

 

const char *instance_name;

const char *instance_name_full;

 

sc_has_process(my_module);

 

my_module(sc_module_name name_) : sc_module(name_)
{
instance_name = name_;
instance_name_full = name();
 
}
 
 
};
 
Now I am getting result as-
 
instance_name = only one level hierarchy i.e. the instance of this module only
instance_name_full = full hierarchy starting from the instance taken inside sc_main
 
Now I am able to use instance_name_full inside my code as I am getting full hierarchy.
 
Thanks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...