Jump to content

It can have two constructors in a SC_MODULE?


ruwan2

Recommended Posts

Hi,

 

A class can have several constructors. Can a module have two constructors? I try to do that, but it fails. I don't know whether it is allowed or the code

is wrong:

 

 

 

 

#include <systemc.h>
 
SC_MODULE(myclk) {
 
  sc_in<bool>  reset, sig; 
  sc_in<bool>  input_valid;        
  sc_in<bool>    CLK; 
 
  SC_CTOR(myclk)
     {      
         SC_METHOD(outp);
         sensitive << CLK.pos();
     }
    
  SC_CTOR(myclk, sig)
     {      
         input_valid = sig;
         SC_METHOD(outq);
         sensitive << CLK.pos();
     }  
     
     
     
  void outp();
  void outq(sc_signal<bool>, sc_signal<bool>);
};
 
 
The error message is:
 
 
# In file included from clk_g_head.cpp:2:
# myclk.h:18:21: error: macro "SC_CTOR" passed 2 arguments, but takes just 1
# In file included from clk_g_head.cpp:2:
# myclk.h:18: error: function definition does not declare parameters
# In file included from myclk.cpp:37:
# myclk.h:18:21: error: macro "SC_CTOR" passed 2 arguments, but takes just 1
# In file included from myclk.cpp:37:
# myclk.h:18: error: function definition does not declare parameters
# ** Error: (sccom-6142) Compilation failed.
# ** Error: C:/modeltech_10.1c/win32/sccom failed.
# Error in macro C:\Users\Jeff\modelsim_systemC\clk_gen\run1.do line 25
# C:/modeltech_10.1c/win32/sccom failed.
#     while executing
# "sccom -g myclk.cpp clk_g_head.cpp"
 
 
I do not find the answer after to look it on the manual.
 
Thanks,
 
 
Link to comment
Share on other sites

Yes, but you need to write the constructors yourself (don't use the SC_CTOR macro). Something like

#include "systemc.h"
SC_MODULE(mod) {

   int i;

   mod(sc_module_name nm) : sc_module(nm) {

      // ...

   }

   mod(sc_module_name nm, int i_) : sc_module(nm), i(i_) {
      // ...
   }

};

If you use SC_THREAD or SC_METHOD you must also include the SC_HAS_PROCESS macro.

 

Try looking up SC_HAS_PROCESS in 1666-2011 and you should find an example near there,

 

regards

Alan

Link to comment
Share on other sites

  • 3 years later...

Alan's code snippet already shows you how to write constructors with additional arguments. The only thing, which is omitted in the snippet, but mentioned in his post is the necessary call to the SC_HAS_PROCESS macro with the name of the module class as argument so that you can use SC_THREADs and SC_METHODs in your module. I tend to write it just in front of the declaration of the first constructor. Thus, Alan's example would look like:

#include "systemc.h"
SC_MODULE(mod) {

   int i;

   SC_HAS_PROCESS(mod)

   mod(sc_module_name nm) : sc_module(nm) {

      // ...

   }

   mod(sc_module_name nm, int i_) : sc_module(nm), i(i_) {
      // ...
   }

};

You can find more information in clause 5.2.6 to 5.2.8 of IEEE Std 1666-2011.

I suggest that you read an introductory book on SystemC, e.g., "SystemC from the Ground Up" by David Black and Jack Donovan. Also, get familiar with C++:

https://isocpp.org/get-started

 

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