📄 sc_wif_trace.cpp
字号:
{ return object != old_value;}void wif_sc_signed_trace::write(FILE* f){ char buf[1000], *buf_ptr = buf; int bitindex; for(bitindex = object.length() - 1; bitindex >= 0; --bitindex) { *buf_ptr++ = "01"[(object)[bitindex]]; } *buf_ptr = '\0'; std::fprintf(f, "assign %s \"%s\" ;\n", wif_name.c_str(), buf); old_value = object;}void wif_sc_signed_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class wif_sc_uint_base_trace: public wif_trace {public: wif_sc_uint_base_trace(const sc_dt::sc_uint_base& object_, const std::string& name_, const std::string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_dt::sc_uint_base& object; sc_dt::sc_uint_base old_value;};wif_sc_uint_base_trace::wif_sc_uint_base_trace( const sc_dt::sc_uint_base& object_, const std::string& name_, const std::string& wif_name_): wif_trace(name_, wif_name_), object(object_), old_value(object_.length()){ old_value = object; wif_type = "BIT";}bool wif_sc_uint_base_trace::changed(){ return object != old_value;}void wif_sc_uint_base_trace::write(FILE* f){ char buf[1000], *buf_ptr = buf; int bitindex; for(bitindex = object.length() - 1; bitindex >= 0; --bitindex) { *buf_ptr++ = "01"[(object)[bitindex]]; } *buf_ptr = '\0'; std::fprintf(f, "assign %s \"%s\" ;\n", wif_name.c_str(), buf); old_value = object;}void wif_sc_uint_base_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class wif_sc_int_base_trace: public wif_trace {public: wif_sc_int_base_trace(const sc_dt::sc_int_base& object_, const std::string& name_, const std::string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_dt::sc_int_base& object; sc_dt::sc_int_base old_value;};wif_sc_int_base_trace::wif_sc_int_base_trace(const sc_dt::sc_int_base& object_, const std::string& name_, const std::string& wif_name_) : wif_trace(name_, wif_name_), object(object_), old_value(object_.length()){ old_value = object; wif_type = "BIT";}bool wif_sc_int_base_trace::changed(){ return object != old_value;}void wif_sc_int_base_trace::write(FILE* f){ char buf[1000], *buf_ptr = buf; int bitindex; for(bitindex = object.length() - 1; bitindex >= 0; --bitindex) { *buf_ptr++ = "01"[(object)[bitindex]]; } *buf_ptr = '\0'; std::fprintf(f, "assign %s \"%s\" ;\n", wif_name.c_str(), buf); old_value = object;}void wif_sc_int_base_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class wif_sc_fxval_trace: public wif_trace{public: wif_sc_fxval_trace( const sc_dt::sc_fxval& object_, const std::string& name_, const std::string& wif_name_ ); void write( FILE* f ); bool changed();protected: const sc_dt::sc_fxval& object; sc_dt::sc_fxval old_value;};wif_sc_fxval_trace::wif_sc_fxval_trace( const sc_dt::sc_fxval& object_, const std::string& name_, const std::string& wif_name_ ): wif_trace( name_, wif_name_ ), object( object_ ){ bit_width = 0; old_value = object; wif_type = "real";}boolwif_sc_fxval_trace::changed(){ return object != old_value;}voidwif_sc_fxval_trace::write( FILE* f ){ std::fprintf( f, "assign %s %f ; \n", wif_name.c_str(), object.to_double() ); old_value = object;}/*****************************************************************************/class wif_sc_fxval_fast_trace: public wif_trace{public: wif_sc_fxval_fast_trace( const sc_dt::sc_fxval_fast& object_, const std::string& name_, const std::string& wif_name_ ); void write( FILE* f ); bool changed();protected: const sc_dt::sc_fxval_fast& object; sc_dt::sc_fxval_fast old_value;};wif_sc_fxval_fast_trace::wif_sc_fxval_fast_trace( const sc_dt::sc_fxval_fast& object_, const std::string& name_, const std::string& wif_name_ ): wif_trace( name_, wif_name_ ), object( object_ ){ bit_width = 0; old_value = object; wif_type = "real";}boolwif_sc_fxval_fast_trace::changed(){ return object != old_value;}voidwif_sc_fxval_fast_trace::write( FILE* f ){ std::fprintf( f, "assign %s %f ; \n", wif_name.c_str(), object.to_double() ); old_value = object;}/*****************************************************************************/class wif_sc_fxnum_trace: public wif_trace{public: wif_sc_fxnum_trace( const sc_dt::sc_fxnum& object_, const std::string& name_, const std::string& wif_name_ ); void write( FILE* f ); bool changed(); void set_width();protected: const sc_dt::sc_fxnum& object; sc_dt::sc_fxnum old_value;};wif_sc_fxnum_trace::wif_sc_fxnum_trace( const sc_dt::sc_fxnum& object_, const std::string& name_, const std::string& wif_name_ ): wif_trace( name_, wif_name_ ), object( object_ ), old_value( object_.m_params.type_params(), object_.m_params.enc(), object_.m_params.cast_switch(), 0 ){ old_value = object; wif_type = "BIT";}boolwif_sc_fxnum_trace::changed(){ return object != old_value;}voidwif_sc_fxnum_trace::write( FILE* f ){ char buf[1000], *buf_ptr = buf; int bitindex; for( bitindex = object.wl() - 1; bitindex >= 0; -- bitindex ) { *buf_ptr ++ = "01"[(object)[bitindex]]; } *buf_ptr = '\0'; std::fprintf( f, "assign %s \"%s\" ;\n", wif_name.c_str(), buf ); old_value = object;}voidwif_sc_fxnum_trace::set_width(){ bit_width = object.wl();}/*****************************************************************************/class wif_sc_fxnum_fast_trace: public wif_trace{public: wif_sc_fxnum_fast_trace( const sc_dt::sc_fxnum_fast& object_, const std::string& name_, const std::string& wif_name_ ); void write( FILE* f ); bool changed(); void set_width();protected: const sc_dt::sc_fxnum_fast& object; sc_dt::sc_fxnum_fast old_value;};wif_sc_fxnum_fast_trace::wif_sc_fxnum_fast_trace( const sc_dt::sc_fxnum_fast& object_, const std::string& name_, const std::string& wif_name_ ): wif_trace( name_, wif_name_ ), object( object_ ), old_value( object_.m_params.type_params(), object_.m_params.enc(), object_.m_params.cast_switch(), 0 ){ old_value = object; wif_type = "BIT";}boolwif_sc_fxnum_fast_trace::changed(){ return object != old_value;}voidwif_sc_fxnum_fast_trace::write( FILE* f ){ char buf[1000], *buf_ptr = buf; int bitindex; for( bitindex = object.wl() - 1; bitindex >= 0; -- bitindex ) { *buf_ptr ++ = "01"[(object)[bitindex]]; } *buf_ptr = '\0'; std::fprintf( f, "assign %s \"%s\" ;\n", wif_name.c_str(), buf ); old_value = object;}voidwif_sc_fxnum_fast_trace::set_width(){ bit_width = object.wl();}/*****************************************************************************/class wif_unsigned_int_trace: public wif_trace {public: wif_unsigned_int_trace(const unsigned& object_, const std::string& name_, const std::string& wif_name_, int width_); void write(FILE* f); bool changed();protected: const unsigned& object; unsigned old_value; unsigned mask; };wif_unsigned_int_trace::wif_unsigned_int_trace(const unsigned& object_, const std::string& name_, const std::string& wif_name_, int width_) : wif_trace(name_, wif_name_), object(object_){ bit_width = width_; if (bit_width < 32) { mask = ~(-1 << bit_width); } else { mask = 0xffffffff; } old_value = object; wif_type = "BIT";}bool wif_unsigned_int_trace::changed(){ return object != old_value;}void wif_unsigned_int_trace::write(FILE* f){ char buf[1000]; int bitindex; // Check for overflow if ((object & mask) != object) { for (bitindex = 0; bitindex < bit_width; bitindex++){ buf[bitindex] = '0'; } } else{ unsigned bit_mask = 1 << (bit_width-1); for (bitindex = 0; bitindex < bit_width; bitindex++) { buf[bitindex] = (object & bit_mask)? '1' : '0'; bit_mask = bit_mask >> 1; } } buf[bitindex] = '\0'; std::fprintf(f, "assign %s \"%s\" ;\n", wif_name.c_str(), buf); old_value = object;}/*****************************************************************************/class wif_unsigned_short_trace: public wif_trace {public: wif_unsigned_short_trace(const unsigned short& object_, const std::string& name_, const std::string& wif_name_, int width_); void write(FILE* f); bool changed();protected: const unsigned short& object; unsigned short old_value; unsigned short mask; };wif_unsigned_short_trace::wif_unsigned_short_trace( const unsigned short& object_, const std::string& name_, const std::string& wif_name_, int width_) : wif_trace(name_, wif_name_), object(object_){ bit_width = width_; if (bit_width < 16) { mask = ~(-1 << bit_width); } else { mask = 0xffff; } old_value = object; wif_type = "BIT";}bool wif_unsigned_short_trace::changed(){ return object != old_value;}void wif_unsigned_short_trace::write(FILE* f){ char buf[1000]; int bitindex; // Check for overflow if ((object & mask) != object) { for (bitindex = 0; bitindex < bit_width; bitindex++){ buf[bitindex]='0'; } } else{ unsigned bit_mask = 1 << (bit_width-1); for (bitindex = 0; bitindex < bit_width; bitindex++) { buf[bitindex] = (object & bit_mask)? '1' : '0'; bit_mask = bit_mask >> 1; } } buf[bitindex] = '\0'; std::fprintf(f, "assign %s \"%s\" ;\n", wif_name.c_str(), buf); old_value = object;}/*****************************************************************************/class wif_unsigned_char_trace: public wif_trace {public: wif_unsigned_char_trace(const unsigned char& object_, const std::string& name_, const std::string& wif_name_, int width_); void write(FILE* f); bool changed();protected: const unsigned char& object; unsigned char old_value; unsigned char mask; };wif_unsigned_char_trace::wif_unsigned_char_trace(const unsigned char& object_, const std::string& name_, const std::string& wif_name_, int width_) : wif_trace(name_, wif_name_), object(object_){ bit_width = width_; if (bit_width < 8) { mask = ~(-1 << bit_width); } else { mask = 0xff; } old_value = object;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -