Jump to content
ruwan2

It can have two constructors in a SC_MODULE?

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,
 
 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@apfitch

Hello Sir,

Sir can you please tell me how would i make objects and how would i pass arguments in these constructors.

or if you could provide me any link where i can read about parameterized constructor of systemc.    

regards,

jatin

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×