Jump to content

Object Oriented programming using SystemC


ashwathgan

Recommended Posts

Hi

 

From what I have seen, SystemC throws error while attempting to use Inheritance/polymorphism.

 

For example

 

I have a Task 

 

SC_MODULE(Task)

{

sc_in<bool> in;

sc_in<bool> out;

 

void cliamResource()

{....}

 

void claimMemory()

{......}

 

 

SC_CTOR(Task)

{}

};

 

Like Wise i have a Resource Module :

 

And then I have number of C++ classes( class A, class B which defines each function I am using).

 

But I am not able to inherit these normal c++ classes like 

 

SC_MODULE(Task) : public A            \\ where A is a Class A

{};

 

 

Can anyone help me how t sort this out (or) Is it possible to inherit C++ classes ??

 

I have a error like : class or struct definition is missing

 

 

Thanks

Link to comment
Share on other sites

Thank a lot sir, 

 

It worked, but I have a small issue with the constructor

 

For example I have a Base class and I derive it in a SystemC Module as follows:

 

Class Base

{

int h;

 

void some_function()

{.....

}

 

and then I have my derived class of SystemC as follows:

 

class TaskA : public sc_module, public base 

{

 

sc-in<bool> a;

sc_out<bool> b;

 

Base b; // Instantiating a object from base Class

 

...

 

....

 

 

SC_CTOR(TaskA) : b ("base")

{

}

 

};

 

 

ERROR: No Default Constructor exists for "base" class. if its is normal c++, I can sort it out, but Im unable to figure out wat to do with this SC_CTOR macro.

 

 

 

 

Thanks 

 

Link to comment
Share on other sites

Hi,

 

This is the macro:

 

#define SC_CTOR(user_module_name)                                             \
    typedef user_module_name SC_CURRENT_USER_MODULE;                          \
    user_module_name( ::sc_core::sc_module_name )

 

you can use a standard constructor instead of the macro:

 

typedef TaskA SC_CURRENT_USER_MODULE;

TaskA(sc_core::sc_module_name name)
    : sc_module (name),
      b ("base")
{
}

 

For your error:

 

When you declare a non-default constructor for a class, the compiler does not generate a default one anymore. So you have to provide your own.

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