sc_vcd_trace.cpp
来自「system C源码 一种替代verilog的语言」· C++ 代码 · 共 2,278 行 · 第 1/4 页
CPP
2,278 行
return object != old_value;}voidvcd_sc_uint_base_trace::write(FILE* f){ char rawdata[1000], *rawdata_ptr = rawdata; char compdata[1000]; int bitindex; for (bitindex = object.length()-1; bitindex >= 0; --bitindex) { *rawdata_ptr++ = "01"[int((object)[bitindex])]; } *rawdata_ptr = '\0'; compose_data_line(rawdata, compdata); std::fputs(compdata, f); old_value = object;}voidvcd_sc_uint_base_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class vcd_sc_int_base_trace : public vcd_trace {public: vcd_sc_int_base_trace(const sc_dt::sc_int_base& object, const std::string& name_, const std::string& vcd_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;};vcd_sc_int_base_trace::vcd_sc_int_base_trace(const sc_dt::sc_int_base& object_, const std::string& name_, const std::string& vcd_name_) : vcd_trace(name_, vcd_name_), object(object_), old_value(object_.length()){ vcd_var_typ_name = "wire"; old_value = object;}boolvcd_sc_int_base_trace::changed(){ return object != old_value;}voidvcd_sc_int_base_trace::write(FILE* f){ char rawdata[1000], *rawdata_ptr = rawdata; char compdata[1000]; int bitindex; for (bitindex = object.length()-1; bitindex >= 0; --bitindex) { *rawdata_ptr++ = "01"[int((object)[bitindex])]; } *rawdata_ptr = '\0'; compose_data_line(rawdata, compdata); std::fputs(compdata, f); old_value = object;}voidvcd_sc_int_base_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class vcd_sc_fxval_trace : public vcd_trace{public: vcd_sc_fxval_trace( const sc_dt::sc_fxval& object, const std::string& name_, const std::string& vcd_name_ ); void write( FILE* f ); bool changed();protected: const sc_dt::sc_fxval& object; sc_dt::sc_fxval old_value;};vcd_sc_fxval_trace::vcd_sc_fxval_trace( const sc_dt::sc_fxval& object_, const std::string& name_, const std::string& vcd_name_ ): vcd_trace( name_, vcd_name_ ), object( object_ ){ vcd_var_typ_name = "real"; bit_width = 1; old_value = object;}boolvcd_sc_fxval_trace::changed(){ return object != old_value;}voidvcd_sc_fxval_trace::write( FILE* f ){ std::fprintf( f, "r%.16g %s", object.to_double(), vcd_name.c_str() ); old_value = object;}/*****************************************************************************/class vcd_sc_fxval_fast_trace : public vcd_trace{public: vcd_sc_fxval_fast_trace( const sc_dt::sc_fxval_fast& object, const std::string& name_, const std::string& vcd_name_ ); void write( FILE* f ); bool changed();protected: const sc_dt::sc_fxval_fast& object; sc_dt::sc_fxval_fast old_value;};vcd_sc_fxval_fast_trace::vcd_sc_fxval_fast_trace( const sc_dt::sc_fxval_fast& object_, const std::string& name_, const std::string& vcd_name_ ): vcd_trace( name_, vcd_name_ ), object( object_ ){ vcd_var_typ_name = "real"; bit_width = 1; old_value = object;}boolvcd_sc_fxval_fast_trace::changed(){ return object != old_value;}voidvcd_sc_fxval_fast_trace::write( FILE* f ){ std::fprintf( f, "r%.16g %s", object.to_double(), vcd_name.c_str() ); old_value = object;}/*****************************************************************************/class vcd_sc_fxnum_trace : public vcd_trace{public: vcd_sc_fxnum_trace( const sc_dt::sc_fxnum& object, const std::string& name_, const std::string& vcd_name_ ); void write( FILE* f ); bool changed(); void set_width();protected: const sc_dt::sc_fxnum& object; sc_dt::sc_fxnum old_value;};vcd_sc_fxnum_trace::vcd_sc_fxnum_trace( const sc_dt::sc_fxnum& object_, const std::string& name_, const std::string& vcd_name_ ): vcd_trace( name_, vcd_name_ ), object( object_ ), old_value( object_.m_params.type_params(), object_.m_params.enc(), object_.m_params.cast_switch(), 0 ){ vcd_var_typ_name = "wire"; old_value = object;}boolvcd_sc_fxnum_trace::changed(){ return object != old_value;}voidvcd_sc_fxnum_trace::write( FILE* f ){ char rawdata[1000], *rawdata_ptr = rawdata; char compdata[1000]; int bitindex; for( bitindex = object.wl() - 1; bitindex >= 0; -- bitindex ) { *rawdata_ptr ++ = "01"[(object)[bitindex]]; } *rawdata_ptr = '\0'; compose_data_line( rawdata, compdata ); std::fputs( compdata, f ); old_value = object;}voidvcd_sc_fxnum_trace::set_width(){ bit_width = object.wl();}/*****************************************************************************/class vcd_sc_fxnum_fast_trace : public vcd_trace{public: vcd_sc_fxnum_fast_trace( const sc_dt::sc_fxnum_fast& object, const std::string& name_, const std::string& vcd_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;};vcd_sc_fxnum_fast_trace::vcd_sc_fxnum_fast_trace( const sc_dt::sc_fxnum_fast& object_, const std::string& name_, const std::string& vcd_name_ ): vcd_trace( name_, vcd_name_ ), object( object_ ), old_value( object_.m_params.type_params(), object_.m_params.enc(), object_.m_params.cast_switch(), 0 ){ vcd_var_typ_name = "wire"; old_value = object;}boolvcd_sc_fxnum_fast_trace::changed(){ return object != old_value;}voidvcd_sc_fxnum_fast_trace::write( FILE* f ){ char rawdata[1000], *rawdata_ptr = rawdata; char compdata[1000]; int bitindex; for( bitindex = object.wl() - 1; bitindex >= 0; -- bitindex ) { *rawdata_ptr ++ = "01"[(object)[bitindex]]; } *rawdata_ptr = '\0'; compose_data_line( rawdata, compdata ); std::fputs( compdata, f ); old_value = object;}voidvcd_sc_fxnum_fast_trace::set_width(){ bit_width = object.wl();}/*****************************************************************************/class vcd_unsigned_int_trace : public vcd_trace {public: vcd_unsigned_int_trace(const unsigned& object, const std::string& name_, const std::string& vcd_name_, int width_); void write(FILE* f); bool changed();protected: const unsigned& object; unsigned old_value; unsigned mask; };vcd_unsigned_int_trace::vcd_unsigned_int_trace( const unsigned& object_, const std::string& name_, const std::string& vcd_name_, int width_) : vcd_trace(name_, vcd_name_), object(object_){ bit_width = width_; if (bit_width < 32) { mask = ~(-1 << bit_width); } else { mask = 0xffffffff; } vcd_var_typ_name = "wire"; old_value = object;}boolvcd_unsigned_int_trace::changed(){ return object != old_value;}voidvcd_unsigned_int_trace::write(FILE* f){ char rawdata[1000]; char compdata[1000]; int bitindex; // Check for overflow if ((object & mask) != object) { for (bitindex = 0; bitindex < bit_width; bitindex++){ rawdata[bitindex] = 'x'; } } else{ unsigned bit_mask = 1 << (bit_width-1); for (bitindex = 0; bitindex < bit_width; bitindex++) { rawdata[bitindex] = (object & bit_mask)? '1' : '0'; bit_mask = bit_mask >> 1; } } rawdata[bitindex] = '\0'; compose_data_line(rawdata, compdata); std::fputs(compdata, f); old_value = object;}/*****************************************************************************/class vcd_unsigned_short_trace : public vcd_trace {public: vcd_unsigned_short_trace(const unsigned short& object, const std::string& name_, const std::string& vcd_name_, int width_); void write(FILE* f); bool changed();protected: const unsigned short& object; unsigned short old_value; unsigned short mask; };vcd_unsigned_short_trace::vcd_unsigned_short_trace( const unsigned short& object_, const std::string& name_, const std::string& vcd_name_, int width_) : vcd_trace(name_, vcd_name_), object(object_){ bit_width = width_; if (bit_width < 16) { mask = ~(-1 << bit_width); } else { mask = 0xffff; } vcd_var_typ_name = "wire"; old_value = object;}boolvcd_unsigned_short_trace::changed(){ return object != old_value;}voidvcd_unsigned_short_trace::write(FILE* f){ char rawdata[1000]; char compdata[1000]; int bitindex; // Check for overflow if ((object & mask) != object) { for (bitindex = 0; bitindex < bit_width; bitindex++){ rawdata[bitindex] = 'x'; } } else{ unsigned bit_mask = 1 << (bit_width-1); for (bitindex = 0; bitindex < bit_width; bitindex++) { rawdata[bitindex] = (object & bit_mask)? '1' : '0'; bit_mask = bit_mask >> 1; } } rawdata[bitindex] = '\0'; compose_data_line(rawdata, compdata); std::fputs(compdata, f); old_value = object;}/*****************************************************************************/class vcd_unsigned_char_trace : public vcd_trace {public: vcd_unsigned_char_trace(const unsigned char& object, const std::string& name_, const std::string& vcd_name_, int width_); void write(FILE* f); bool changed();protected: const unsigned char& object; unsigned char old_value; unsigned char mask; };vcd_unsigned_char_trace::vcd_unsigned_char_trace( const unsigned char& object_, const std::string& name_, const std::string& vcd_name_, int width_): vcd_trace(name_, vcd_name_), object(object_){ bit_width = width_; if (bit_width < 8) { mask = ~(-1 << bit_width); } else { mask = 0xff; } vcd_var_typ_name = "wire"; old_value = object;}bool vcd_unsigned_char_trace::changed(){ return object != old_value;}void vcd_unsigned_char_trace::write(FILE* f){ char rawdata[1000]; char compdata[1000]; int bitindex; // Check for overflow if ((object & mask) != object) { for (bitindex = 0; bitindex < bit_width; bitindex++){ rawdata[bitindex] = 'x'; } } else{ unsigned bit_mask = 1 << (bit_width-1); for (bitindex = 0; bitindex < bit_width; bitindex++) { rawdata[bitindex] = (object & bit_mask)? '1' : '0'; bit_mask = bit_mask >> 1; } } rawdata[bitindex] = '\0'; compose_data_line(rawdata, compdata); std::fputs(compdata, f); old_value = object;}/*****************************************************************************/class vcd_unsigned_long_trace : public vcd_trace {public: vcd_unsigned_long_trace(const unsigned long& object, const std::string& name_, const std::string& vcd_name_, int width_); void write(FILE* f); bool changed();protected: const unsigned long& object; unsigned long old_value; unsigned long mask; };vcd_unsigned_long_trace::vcd_unsigned_long_trace( const unsigned long& object_, const std::string& name_, const std::string& vcd_name_, int width_): vcd_trace(name_, vcd_name_), object(object_){ bit_width = width_; if (bit_width < 32) { mask = ~(-1 << bit_width); } else { mask = 0xffffffff; } vcd_var_typ_name = "wire"; old_value = object;}bool vcd_unsigned_long_trace::changed(){ return object != old_value;}void vcd_unsigned_long_trace::write(FILE* f){ char rawdata[1000]; char compdata[1000]; int bitindex; // Check for overflow if ((object & mask) != object) { for (bitindex = 0; bitindex < bit_width; bitindex++){ rawdata[bitindex] = 'x'; } } else{ unsigned bit_mask = 1 << (bit_width-1); for (bitindex = 0; bitindex < bit_width; bitindex++) { rawdata[bitindex] = (object & bit_mask)? '1' : '0'; bit_mask = bit_mask >> 1; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?