Jump to content
JorgeAbarca

write different types of data in a custom port

Recommended Posts

Hi, 

 

i am creating a new port for a specific purpose, it works very well with the most of datatypes, but i got an error trying to support sc_logic. in this example the behavior is if my_event is detected a write is forced. but if it is an sc_logic I forced sc_logic_z but if it is other datatype I force 0. my intention is to detect if the object is sc_logic or not using typeid(T).name(), what in my operative system is "N5sc_dt8sc_logicE" , but i am getting this error: 

In file included from ./main.cpp:42:0:
./port_new.h: In instantiation of ‘void sc_out_new<T>::write(T) [with T = double]’:
./stage1.cpp:67:15:   required from here
./port_upf.h:194:8: error: no match for ‘operator=’ (operand types are ‘sc_core::sc_out<double>’ and ‘const sc_dt::sc_logic’)
     out=SC_LOGIC_Z;

 

any idea about how i can write both types using the same class ???

 

my module: 

struct numgen : sc_module {
    sc_out_new<double> out1;      //output 1
    sc_out_new<sc_logic> out2;

 

...

}

 

 


     

my class: 

Template<typename T>

class sc_out_new : public sc_channel
{

...

 

    SC_HAS_PROCESS(sc_out_new);
    sc_in_upf(const sc_module_name& nmod) : sc_channel(nmod){

    SC_METHOD(write_out);
    sensitive << my_event

}

 

void write_out{

            if(typeid(T).name() == "N5sc_dt8sc_logicE"){
                out.write(SC_LOGIC_Z);
            }else{
            out.write(0);
            }

        }

}

 

 

 thanks for the help

Share this post


Link to post
Share on other sites

You cannot not check typeid() against a string as this is compiler dependend. What you shoudl do is

 void write_out{
            if(typeid(T) == typeid(sc_dt::sc_logic){
                out.write(SC_LOGIC_Z);
            }else{
            	out.write(0);
            }
        }
} 

But actually this is more a C++ related question, in my experience Stackoverflow is a good source of help.

Cheers

Share this post


Link to post
Share on other sites
2 hours ago, Eyck said:

You cannot not check typeid() against a string as this is compiler dependend. What you shoudl do is


 void write_out{
            if(typeid(T) == typeid(sc_dt::sc_logic){
                out.write(SC_LOGIC_Z);
            }else{
            	out.write(0);
            }
        }
} 

But actually this is more a C++ related question, in my experience Stackoverflow is a good source of help.

Cheers

But even this won't fix your error.  Because compiler will still complain about assigning sc_logic to double, even if it is in always false branch.

What you need is if-constexpr and std::is_same if you have C++17.  Or SFINAE, if you don't.  Something like this may work:

if constexpr (std::is_same_v<T, sc_dt::sc_logic>)
{
    out = SC_LOGIC_Z;
}
else
{
    out = 0;
}

 

Share this post


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