ViVo Posted October 22, 2017 Report Posted October 22, 2017 i wrote very simple template module (select_unit.h) with vector as one of its 3rd argument. i encounter difficulty instantiating it in the upper "floor" (up_mod.h). the marked red code should be the definition of std::vector of unsigned integers (template's 3rd parameter in select_unit module). the compiler complains for const 3rd argument..., how should i define the vector? any help would be appreciated. V. select_unit.h template <unsigned w_bus,unsigned w_sel, std::vector<unsigned> &sel_bits> SC_MODULE(select_unit) { /* -----------Input Ports--------------------------------------------------------- */ sc_in <sc_uint<w_bus>> in ; /* -----------Output Ports-------------------------------------------------------- */ sc_out <sc_uint<w_sel>> out ; /* -----------Input/Output Ports-------------------------------------------------- */ /* -----------Local Signal Declarations------------------------------------------- */ /* -----------Internal modules / variables---------------------------------------- */ /* -----------Methods------------------------------------------------------------- */ void thread0(void) ; /* -----------Constructor--------------------------------------------------------- */ SC_CTOR(select_unit) : in("in"), out("out") { ... } } ; template <unsigned w_bus,unsigned w_sel,std::vector<unsigned> &sel_bits> void select_unit<w_bus, w_sel, sel_bits>::thread0(void) { ... } up_mod.h SC_MODULE(up_mod) { /* -----------Input Ports--------------------------------------------------------- */ /* -----------Output Ports-------------------------------------------------------- */ /* -----------Input/Output Ports-------------------------------------------------- */ /* -----------Local Signal Declarations------------------------------------------- */ /* -----------Internal modules/variables------------------------------------------ */ ... std::vector<unsigned> bits2mnt; select_unit<U0_WIDTH, 18, bits2mnt> *select0 ; /* -----------Constructor----------------------------------------------- ---------- */ SC_CTOR(up_mod) { ... /* -----------Initialize Sub Modules------------------------------------------ */ select0 = new select_unit<U0_WIDTH, 18, bits2mnt> ; } } Quote
Roman Popov Posted October 22, 2017 Report Posted October 22, 2017 Templates are compile time feature in C++. So you can't use values that are not compile-time constants as non-type template parameters. Instead use a constructor parameter to pass arguments: SC_HAS_PROCESS(select_unit); select_unit(::sc_core::sc_module_name name, std::vector<unsigned> &sbits) : sel_bits(sbits) { /*...*/ } std::vector<unsigned> &sel_bits; Quote
ViVo Posted November 5, 2017 Author Report Posted November 5, 2017 Hello Roman, thank you very much for your help.. i revised my code style upon your inputs.. As 1st step, i'm converting to the "recommended" sytle tammed in the "SystemC from the ground up" book. As shown in the attached files... The problem is that i get lots of errors saying: "template is illigal". Can i use this code style with parameterized module-type? BR, V basic_process_ex.cpp basic_process_ex.h main.cpp Quote
Roman Popov Posted November 6, 2017 Report Posted November 6, 2017 On 11/5/2017 at 5:54 AM, ViVo said: Hello Roman, As 1st step, i'm converting to the "recommended" sytle tammed in the "SystemC from the ground up" book. As shown in the attached files... The problem is that i get lots of errors saying: "template is illigal". Your code compiles w/o any errors on my machine with g++. SC_HAS_PROCESS macro is not required, since you have used SC_CTOR. I recommend to look how SC_MODULE, SC_CTOR, SC_HAS_PROCESS and SC_THREAD are expanded to understand what each one is doing. Quote
ViVo Posted November 11, 2017 Author Report Posted November 11, 2017 So, windows is not functioning well ? i'm searching for stable environment for systemc, windows isn't sufficient ? what should i do ? V Quote
Roman Popov Posted November 12, 2017 Report Posted November 12, 2017 19 hours ago, ViVo said: So, windows is not functioning well ? i'm searching for stable environment for systemc, windows isn't sufficient ? what should i do ? V On Windows both Visual Studio and MinGW work well with SystemC. Since your question is not about SystemC, but rather about C++ language, I recommend to extract minimal code sample and ask in C++ community. For example on https://stackoverflow.com/ Quote
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.