sc_vcd_trace.cpp

来自「基于4个mips核的noc设计」· C++ 代码 · 共 2,112 行 · 第 1/4 页

CPP
2,112
字号
}/*****************************************************************************/class vcd_unsigned_long_trace : public vcd_trace {public:    vcd_unsigned_long_trace(const unsigned long& object,			    const sc_string& name_,			    const sc_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 sc_string& name_,						 const sc_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;        }    }    rawdata[bitindex] = '\0';    compose_data_line(rawdata, compdata);    fputs(compdata, f);    old_value = object;}/*****************************************************************************/class vcd_signed_int_trace : public vcd_trace {public:    vcd_signed_int_trace(const int& object,			 const sc_string& name_,			 const sc_string& vcd_name_,			 int width_);    void write(FILE* f);    bool changed();protected:    const int& object;    int old_value;    unsigned mask; };vcd_signed_int_trace::vcd_signed_int_trace(const signed& object_,					   const sc_string& name_,					   const sc_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_signed_int_trace::changed(){    return object != old_value;}void vcd_signed_int_trace::write(FILE* f){    char rawdata[1000];    char compdata[1000];    int bitindex;    // Check for overflow    if (((unsigned) object & mask) != (unsigned) 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);    fputs(compdata, f);    old_value = object;}/*****************************************************************************/class vcd_signed_short_trace : public vcd_trace {public:    vcd_signed_short_trace(const short& object,			   const sc_string& name_,			   const sc_string& vcd_name_,			   int width_);    void write(FILE* f);    bool changed();protected:    const short& object;    short old_value;    unsigned short mask; };vcd_signed_short_trace::vcd_signed_short_trace(const short& object_,					       const sc_string& name_,					       const sc_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;}bool vcd_signed_short_trace::changed(){    return object != old_value;}void vcd_signed_short_trace::write(FILE* f){    char rawdata[1000];    char compdata[1000];    int bitindex;    // Check for overflow    if (((unsigned short) object & mask) != (unsigned short) 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);    fputs(compdata, f);    old_value = object;}/*****************************************************************************/class vcd_signed_char_trace : public vcd_trace {public:    vcd_signed_char_trace(const char& object,			  const sc_string& name_,			  const sc_string& vcd_name_,			  int width_);    void write(FILE* f);    bool changed();protected:    const char& object;    char old_value;    unsigned char mask; };vcd_signed_char_trace::vcd_signed_char_trace(const char& object_,					     const sc_string& name_,					     const sc_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_signed_char_trace::changed(){    return object != old_value;}void vcd_signed_char_trace::write(FILE* f){    char rawdata[1000];    char compdata[1000];    int bitindex;    // Check for overflow    if (((unsigned char) object & mask) != (unsigned char) 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);    fputs(compdata, f);    old_value = object;}/*****************************************************************************/class vcd_signed_long_trace : public vcd_trace {public:    vcd_signed_long_trace(const long& object,			  const sc_string& name_,			  const sc_string& vcd_name_,			  int width_);    void write(FILE* f);    bool changed();protected:    const long& object;    long old_value;    unsigned long mask; };vcd_signed_long_trace::vcd_signed_long_trace(const long& object_,					     const sc_string& name_,					     const sc_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_signed_long_trace::changed(){    return object != old_value;}void vcd_signed_long_trace::write(FILE* f){    char rawdata[1000];    char compdata[1000];    int bitindex;    // Check for overflow    if (((unsigned long) object & mask) != (unsigned long) 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);    fputs(compdata, f);    old_value = object;}/*****************************************************************************/class vcd_float_trace : public vcd_trace {public:    vcd_float_trace(const float& object,		    const sc_string& name_,		    const sc_string& vcd_name_);    void write(FILE* f);    bool changed();protected:        const float& object;    float old_value;};vcd_float_trace::vcd_float_trace(const float& object_,				 const sc_string& name_,				 const sc_string& vcd_name_): vcd_trace(name_, vcd_name_), object(object_){    vcd_var_typ_name = "real";    bit_width = 1;    old_value = object;}bool vcd_float_trace::changed(){    return object != old_value;}void vcd_float_trace::write(FILE* f){    fprintf(f, "r%.16g %s", object, (const char *) vcd_name);    old_value = object;}/*****************************************************************************/class vcd_double_trace : public vcd_trace {public:    vcd_double_trace(const double& object,		     const sc_string& name_,		     const sc_string& vcd_name_);    void write(FILE* f);    bool changed();protected:        const double& object;    double old_value;};vcd_double_trace::vcd_double_trace(const double& object_,				   const sc_string& name_,				   const sc_string& vcd_name_): vcd_trace(name_, vcd_name_), object(object_){    vcd_var_typ_name = "real";    bit_width = 1;    old_value = object;}bool vcd_double_trace::changed(){    return object != old_value;}void vcd_double_trace::write(FILE* f){    fprintf(f, "r%.16g %s", object, (const char *) vcd_name);    old_value = object;}/*****************************************************************************/class vcd_enum_trace : public vcd_trace {public:    vcd_enum_trace(const unsigned& object_,		   const sc_string& name_,		   const sc_string& vcd_name_,		   const char** enum_literals);    void write(FILE* f);    bool changed();protected:    const unsigned& object;    unsigned old_value;    unsigned mask;    const char** literals;    unsigned nliterals;};vcd_enum_trace::vcd_enum_trace(const unsigned& object_,			       const sc_string& name_,			       const sc_string& vcd_name_,			       const char** enum_literals_): vcd_trace(name_, vcd_name_), object(object_), literals(enum_literals_){    // find number of bits required to represent enumeration literal - counting loop    for (nliterals = 0; enum_literals_[nliterals]; nliterals++);    // Figure out number of bits required to represent the number of literals    bit_width = 0;    unsigned shifted_maxindex = nliterals-1;    while(shifted_maxindex != 0){        shifted_maxindex >>= 1;        bit_width++;    }    // Set the mask    if (bit_width < 32) {      mask = ~(-1 << bit_width);    } else {      mask = 0xffffffff;    }    vcd_var_typ_name = "wire";    old_value = object;}       bool vcd_enum_trace::changed(){    return object != old_value;}void vcd_enum_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);    fputs(compdata, f);    old_value = object;}/*****************************************************************************           vcd_trace_file functions *****************************************************************************/vcd_trace_file::vcd_trace_file(const char *name){    sc_string file_name = name ;    file_name += ".vcd";    fp = fopen((const char *) file_name, "w");    if (!fp) {        sc_string msg = sc_string("Cannot write trace file '") +	                file_name + "'";	cerr << "FATAL: " << msg << "\n";        exit(1);    }    trace_delta_cycles = false; // Make this the default    initialized = false;    vcd_name_index = 0;    // default time step is the time resolution    timescale_unit = sc_get_time_resolution().to_seconds();    timescale_set_by_user = false;}void vcd_trace_file::initialize(){    char buf[2000];    //date:    time_t long_time;    time(&long_time);    struct tm* p_tm;    p_tm = localtime(&long_time);    strftime(buf, 199, "%b %d, %Y       %H:%M:%S", p_tm);    fprintf(fp, "$date\n     %s\n$end\n\n", buf);    //version:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?