Jump to content

Overloading/ Registering sc_export


karandeep963

Recommended Posts

Hello All,

 

I am wandering for overloading sc_export.

 

Lets say at the target side I have 3 exports(same transaction type), so how to implement their write functions?

class abc : public sc_module,
                         public tlm_analysis_if<T> 
{
public:
    // defining port list

       // Analysis Ports
       sc_export<tlm::tlm_analysis_if<T > > exp_1;
    
       sc_export<tlm::tlm_analysis_if<T > > exp_2;

//// In the constructor
        exp_1(*this);
        exp_2(*this);



Declaration:

void write (const T& t){
  // What about implement exp_1
}

void write (const T& t){
// What about exp_2 

}

Please help me how to overload the write function?

 

Thanks,

Karandeep

Link to comment
Share on other sites

You can't use the "implement interface and export" idiom in this case, as you obviously can implement each function only once (for each transaction type).

 

You can use a small wrapper instead:

SC_MODULE(abc)
{
  typedef int T;
  sc_core::sc_export<tlm::tlm_analysis_if<T> > exp_1, exp_2;

  SC_CTOR(abc)
    : exp_1("exp_1")
    , exp_2("exp_2")
    , aw_1(*this,&abc::write_1) // create wrapper for each implementation
    , aw_2(*this,&abc::write_2)  
  {
    exp_1(aw_1); // bind wrappers
    exp_2(aw_2);
  }

private:

  void write_1( const T& ); // implementation for each export
  void write_2( const T& );

  struct analysis_wrapper
    : sc_core::sc_object, tlm::tlm_analysis_if<T>
  {
    typedef void (abc::*write_func)( const T& ); // pointer to member function with implementation

    analysis_wrapper( abc& owner, write_func f )
      : sc_core::sc_object(sc_core::sc_gen_unique_name("analysis_if"))
      , this_(owner), f_(f){}

    void write( const T& v ) { (this_.*f_)(v); } // forward call to registered implementation

   private:
    abc& this_;
    write_func f_;
  };

  analysis_wrapper aw_1, aw_2;
};

Hope that helps,
   Philipp

Link to comment
Share on other sites

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...