⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc_wif_trace.cpp

📁 system C源码 一种替代verilog的语言
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    wif_type = "BIT";}bool wif_unsigned_char_trace::changed(){    return object != old_value;}void wif_unsigned_char_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_long_trace: public wif_trace {public:    wif_unsigned_long_trace(const unsigned long& object_,			    const std::string& name_,			    const std::string& wif_name_,			    int width_);    void write(FILE* f);    bool changed();protected:    const unsigned long& object;    unsigned long old_value;    unsigned long mask; };wif_unsigned_long_trace::wif_unsigned_long_trace(const unsigned long& 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_long_trace::changed(){    return object != old_value;}void wif_unsigned_long_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_signed_int_trace: public wif_trace {public:    wif_signed_int_trace(const int& object_,			 const std::string& name_,			 const std::string& wif_name_,			 int width_);    void write(FILE* f);    bool changed();protected:    const int& object;    int old_value;    unsigned mask; };wif_signed_int_trace::wif_signed_int_trace(const signed& 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_signed_int_trace::changed(){    return object != old_value;}void wif_signed_int_trace::write(FILE* f){    char buf[1000];    int bitindex;    // Check for overflow    if (((unsigned) object & mask) != (unsigned) 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_signed_short_trace: public wif_trace {public:    wif_signed_short_trace(const short& object_,			   const std::string& name_,			   const std::string& wif_name_,			   int width_);    void write(FILE* f);    bool changed();protected:    const short& object;    short old_value;    unsigned short mask; };wif_signed_short_trace::wif_signed_short_trace(const 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_signed_short_trace::changed(){    return object != old_value;}void wif_signed_short_trace::write(FILE* f){    char buf[1000];    int bitindex;    // Check for overflow    if (((unsigned short) object & mask) != (unsigned short) 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_signed_char_trace: public wif_trace {public:    wif_signed_char_trace(const char& object_,			  const std::string& name_,			  const std::string& wif_name_,			  int width_);    void write(FILE* f);    bool changed();protected:    const char& object;    char old_value;    unsigned char mask; };wif_signed_char_trace::wif_signed_char_trace(const 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;    wif_type = "BIT";}bool wif_signed_char_trace::changed(){    return object != old_value;}void wif_signed_char_trace::write(FILE* f){    char buf[1000];    int bitindex;    // Check for overflow    if (((unsigned char) object & mask) != (unsigned char) 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_signed_long_trace: public wif_trace {public:    wif_signed_long_trace(const long& object_,			  const std::string& name_,			  const std::string& wif_name_,			  int width_);    void write(FILE* f);    bool changed();protected:    const long& object;    long old_value;    unsigned long mask; };wif_signed_long_trace::wif_signed_long_trace(const long& 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_signed_long_trace::changed(){    return object != old_value;}void wif_signed_long_trace::write(FILE* f){    char buf[1000];    int bitindex;    // Check for overflow    if (((unsigned long) object & mask) != (unsigned long) 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_float_trace: public wif_trace {public:    wif_float_trace(const float& object_,		    const std::string& name_,		    const std::string& wif_name_);    void write(FILE* f);    bool changed();protected:        const float& object;    float old_value;};wif_float_trace::wif_float_trace(const float& 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";}bool wif_float_trace::changed(){    return object != old_value;}void wif_float_trace::write(FILE* f){    std::fprintf(f,"assign  %s %f ; \n", wif_name.c_str(), object);    old_value = object;}/*****************************************************************************/class wif_double_trace: public wif_trace {public:    wif_double_trace(const double& object_,		     const std::string& name_,		     const std::string& wif_name_);    void write(FILE* f);    bool changed();protected:        const double& object;    double old_value;};wif_double_trace::wif_double_trace(const double& 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";}bool wif_double_trace::changed(){    return object != old_value;}void wif_double_trace::write(FILE* f){    std::fprintf(f,"assign  %s %f ; \n", wif_name.c_str(), object);    old_value = object;}/*****************************************************************************/class wif_enum_trace : public wif_trace {public:    wif_enum_trace(const unsigned& object_,		   const std::string& name_,		   const std::string& wif_name_,		   const char** enum_literals);    void write(FILE* f);    bool changed();    // Hides the definition of the same (virtual) function in wif_trace    void print_variable_declaration_line(FILE* f);protected:    const unsigned& object;    unsigned old_value;        const char** literals;    unsigned nliterals;    std::string type_name;    ~wif_enum_trace();};wif_enum_trace::wif_enum_trace(const unsigned& object_,			       const std::string& name_,			       const std::string& wif_name_,			       const char** enum_literals_) : wif_trace(name_, wif_name_), object(object_), literals(enum_literals_){    // find number of enumeration literals - counting loop    for (nliterals = 0; enum_literals_[nliterals]; nliterals++);    bit_width = 0;    old_value = object;    type_name = name_ + "__type__";    wif_type = type_name.c_str();}       void wif_enum_trace::print_variable_declaration_line(FILE* f){    std::fprintf(f, "type scalar \"%s\" enum ", wif_type);    for (unsigned i = 0; i < nliterals; i++)      std::fprintf(f, "\"%s\", ", literals[i]);    std::fprintf(f, "\"SC_WIF_UNDEF\" ;\n");    std::fprintf(f, "declare  %s   \"%s\"  \"%s\" ",	    wif_name.c_str(), name.c_str(), wif_type);    std::fprintf(f, "variable ;\n");    std::fprintf(f, "start_trace %s ;\n", wif_name.c_str());}bool wif_enum_trace::changed(){    return object != old_value;}void wif_enum_trace::write(FILE* f){    char buf[2000];    static bool warning_issued = false;    if (object >= nliterals) { // Note unsigned value is always greater than 0        if (!warning_issued) {	    std::sprintf(buf, "Tracing error: Value of enumerated type undefined");	    put_error_message(buf, false);	    warning_issued = true;	}

⌨️ 快捷键说明

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