VKrishnamurthy Posted January 27, 2015 Report Share Posted January 27, 2015 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! Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted January 27, 2015 Report Share Posted January 27, 2015 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 VKrishnamurthy 1 Quote Link to comment Share on other sites More sharing options...
dakupoto Posted January 28, 2015 Report Share Posted January 28, 2015 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. VKrishnamurthy 1 Quote Link to comment Share on other sites More sharing options...
VKrishnamurthy Posted January 29, 2015 Author Report Share Posted January 29, 2015 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 Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted January 29, 2015 Report Share Posted January 29, 2015 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 sumit_tuwien 1 Quote Link to comment Share on other sites More sharing options...
VKrishnamurthy Posted January 29, 2015 Author Report Share Posted January 29, 2015 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. Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted January 29, 2015 Report Share Posted January 29, 2015 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? Quote Link to comment Share on other sites More sharing options...
VKrishnamurthy Posted January 29, 2015 Author Report Share Posted January 29, 2015 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. Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted January 29, 2015 Report Share Posted January 29, 2015 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) ... Quote Link to comment Share on other sites More sharing options...
VKrishnamurthy Posted January 29, 2015 Author Report Share Posted January 29, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.