Jump to content
VKrishnamurthy

Passing maps within Constructors in SystemC struct

Recommended Posts

Hi Experts,

 

How do I pass "Maps" within constructors while using a SystemC struct? 

I want to instantiate this module 4 times and use 4 different maps for each instance.

 

struct Detector: sc_module
{
  

    SC_CTOR(Detector)
   
    {
     

        for (int i = 0 ; i<10 ; i++)
        {
          in_map= map[0];  // in_map has been declared as private & map is passed on through the constructor
        }

    }
 

 

Thankyou in advance!

Share this post


Link to post
Share on other sites

Hi.

 

You can write your own constructor (see section 5.2.6 in the SystemC LRM IEEE-1666).

SC_MODULE(M)
{
M(sc_module_name n, int a, int 
: sc_module(n)
{}
...
};

Please note that you have to add SC_HAS_PROCESS to your module if it contains any process and ont uses the SC_CTOR macro.

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Hi.

 

You can write your own constructor (see section 5.2.6 in the SystemC LRM IEEE-1666).

SC_MODULE(M)
{
M(sc_module_name n, int a, int 
: sc_module(n)
{}
...
};

Please note that you have to add SC_HAS_PROCESS to your module if it contains any process and ont uses the SC_CTOR macro.

 

Greetings

Ralph

Hello Sir,

If I understand your query correctly, you want to create

a module and pass in a number of Map objects through the

constructor. Is that correct ?

If yes, the scheme is fairly straightforward.

1. Create four Map objects and then pass them in via the

module constructor initialization list -- standard C++

trick.

You have mentioned something about the Map objects being

private. In that case, the above scheme will not work, as

the Maps must be created before being passed in via the

module constructor initialization list. These Maps will

be visible to other modules as well. To make the Maps

private, declare and define them inside your own module

Hope that helps.

 

Share this post


Link to post
Share on other sites

Hi all,
 
Thank you for your responses. I tried it and it works with a normal constructor. But when I try to pass 2D arrays of different dimensions it doesnt work
 
 I have 4 arrays of different dimensions,but the second dimension is fixed as 2. I am trying to take 4 different 2d arrays( of type uint64 )through the constructor and use it in a function during runtime.But I get an error saying that dimensions should be fixed and could not access the values from the arrays.(Using C++ 98)

 


 

The contents of bus_1map are printed out  but further simulation stops . Please help

Share this post


Link to post
Share on other sites

Why are you using C arrays? How about vector or map?

 

e.g.:

std::vector< std::vector< uint64_t > >

 

What do you mean with 'simulation stops'?

Did the simulation end? Is there any error message?

 

The code posted above does not show any processes. Maybe you can post a bit more (minimum working example)?

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Basically, the arrays are present in a simple header file like this:

Therefore I cant use maps or vectors which requires a class/ function . I want different arrays which are in  .h files to be passed on to the constructor so that I can use the array values

 

 

I want the arrays for the function as above.

 

There is no error message. When I try to debug it reaches a C++ stl file pointing to a template function and stops.

Share this post


Link to post
Share on other sites

First:

Since C++11, std::vector allows construction from an initializer list (and std::map as well).

std::vector< std::vector< int > > my_vec = 
{{0,1},{2,3}};

std::map< int, int > my_map = 
{{0,1},{2,3}};

Second:

'and stops' allows a wide range of problems. Infinite Loop? Any exception?

I think,  we can assume that the problem is not in the STL. So, please try to analyze the last portion of user code before the program steps down to the STL function.

 

Third:

if((addr >= laddr) & (addr< uaddr))

 

Do you mean & (bitwise or) or && (logical or) here?

Share this post


Link to post
Share on other sites

First:

Since C++11, std::vector allows construction from an initializer list (and std::map as well).

std::vector< std::vector< int > > my_vec = 
{{0,1},{2,3}};

std::map< int, int > my_map = 
{{0,1},{2,3}};

Second:

'and stops' allows a wide range of problems. Infinite Loop? Any exception?

I think,  we can assume that the problem is not in the STL. So, please try to analyze the last portion of user code before the program steps down to the STL function.

 

Third:

Do you mean & (bitwise or) or && (logical or) here?

First: The problem is Im working on C++ 98.

Second: The user code is perfect as I had tried using with a single array and it worked perfectly fine.

Third: Yes I mean & here.

Share this post


Link to post
Share on other sites

Sorry, but I cannot see other problems in the code you posted.

Could you maybe strip down your design to a minimal example showing the erroneous behaviour?

 

 

PS: 

 

Do you mean & (bitwise or) or && (logical or) here?

I did mean ... & (bitwise and) or && (logical and) ...

Share this post


Link to post
Share on other sites

Hi,

 

Found the reason.The error was due to false values in the array .The values that are stored in the array bus_1map are wrong (or overlapped). Could it be because I am copying the values to the array in the constructor itself?

Or is there an other way to copy the values.

 

I try to do this :

Detector(sc_module_name name,uint64 bus_map[][2],int size ) : sc_module(name), bus_1map(bus_map)

But it shows an error saying:

incompatible types in assignment of ‘sc_dt::uint64 (*)[2]’ to ‘sc_dt::uint64 [0]
     [2]’

 

P.S: The Detector module is instantiated 4 times with different arrays with different values.

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

×