📄 sc_wif_trace.cpp
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.4 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** sc_wif_trace.cpp - Implementation of WIF tracing. Original Author - Abhijit Ghosh, Synopsys, Inc. *****************************************************************************//***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affliation, date and changes you are making here. Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc. Description of Modification: - Replaced 'width' of sc_(u)int with their 'bitwidth()'. Name, Affiliation, Date: Description of Modification: *****************************************************************************//***************************************************************************** Acknowledgement: The tracing mechanism is based on the tracing mechanism developed at Infineon (formerly Siemens HL). Though this code is somewhat different, and significantly enhanced, the basics are identical to what was originally contributed by Infineon. The contribution of Infineon in the development of this tracing technology is hereby acknowledged. *****************************************************************************//***************************************************************************** Instead of creating the binary WIF format, we create the ASCII WIF format which can be converted to the binary format using a2wif (utility that comes with VSS from Synopsys). This way, a user who does not have Synopsys VSS can still create WIF files, but they can only be viewed by users who have VSS. *****************************************************************************/#include <assert.h>#include <time.h>#include <cstdlib>#include "sysc/kernel/sc_simcontext.h"#include "sysc/kernel/sc_ver.h"#include "sysc/datatypes/bit/sc_bit.h"#include "sysc/datatypes/bit/sc_logic.h"#include "sysc/datatypes/bit/sc_lv_base.h"#include "sysc/datatypes/int/sc_signed.h"#include "sysc/datatypes/int/sc_unsigned.h"#include "sysc/datatypes/int/sc_int_base.h"#include "sysc/datatypes/int/sc_uint_base.h"#include "sysc/datatypes/fx/fx.h"#include "sysc/tracing/sc_wif_trace.h"namespace sc_core {static bool running_regression = false;// Forward declarations for functions that come later in the filestatic char map_sc_logic_state_to_wif_state(char in_char);const char* wif_names[wif_trace_file::WIF_LAST] = {"BIT","MVL","real"};// ----------------------------------------------------------------------------// CLASS : wif_trace//// Base class for WIF traces.// ----------------------------------------------------------------------------class wif_trace{public: wif_trace(const std::string& name_, const std::string& wif_name_); // Needs to be pure virtual as has to be defined by the particular // type being traced virtual void write(FILE* f) = 0; virtual void set_width(); // Comparison function needs to be pure virtual too virtual bool changed() = 0; // Got to declare this virtual as this will be overwritten // by one base class virtual void print_variable_declaration_line(FILE* f); virtual ~wif_trace(); const std::string name; // Name of the variable const std::string wif_name; // Name of the variable in WIF file const char* wif_type; // WIF data type int bit_width; };wif_trace::wif_trace(const std::string& name_, const std::string& wif_name_) : name(name_), wif_name(wif_name_), bit_width(-1){ /* Intentionally blank */} voidwif_trace::print_variable_declaration_line( FILE* f ){ char buf[2000]; if( bit_width < 0 ) { std::sprintf( buf, "Traced object \"%s\" has < 0 Bits, cannot be traced.", name.c_str() ); put_error_message( buf, false ); } else { std::fprintf( f, "declare %s \"%s\" %s ", wif_name.c_str(), name.c_str(), wif_type ); if( bit_width > 0 ) { std::fprintf( f, "0 %d ", bit_width - 1 ); } std::fprintf( f, "variable ;\n" ); std::fprintf( f, "start_trace %s ;\n", wif_name.c_str() ); }}voidwif_trace::set_width(){ /* Intentionally Blank, should be defined for each type separately */}wif_trace::~wif_trace(){ /* Intentionally Blank */}// Classes for tracing individual data types/*****************************************************************************/class wif_uint64_trace: public wif_trace {public: wif_uint64_trace(const sc_dt::uint64& object_, const std::string& name_, const std::string& wif_name_, int width_); void write(FILE* f); bool changed();protected: const sc_dt::uint64& object; sc_dt::uint64 old_value; sc_dt::uint64 mask; };wif_uint64_trace::wif_uint64_trace(const sc_dt::uint64& object_, const std::string& name_, const std::string& wif_name_, int width_) : wif_trace(name_, wif_name_), object(object_){ bit_width = width_; mask = (sc_dt::uint64)-1; if (bit_width < 32) mask = ~(mask << bit_width); old_value = object; wif_type = "BIT";}bool wif_uint64_trace::changed(){ return object != old_value;}void wif_uint64_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 { sc_dt::uint64 bit_mask = 1; bit_mask = bit_mask << (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_int64_trace: public wif_trace {public: wif_int64_trace(const sc_dt::int64& object_, const std::string& name_, const std::string& wif_name_, int width_); void write(FILE* f); bool changed();protected: const sc_dt::int64& object; sc_dt::int64 old_value; sc_dt::uint64 mask; };wif_int64_trace::wif_int64_trace(const sc_dt::int64& object_, const std::string& name_, const std::string& wif_name_, int width_) : wif_trace(name_, wif_name_), object(object_){ bit_width = width_; mask = (sc_dt::uint64)-1; if (bit_width < 32) mask = ~(mask << bit_width); old_value = object; wif_type = "BIT";}bool wif_int64_trace::changed(){ return object != old_value;}void wif_int64_trace::write(FILE* f){ char buf[1000]; int bitindex; // Check for overflow if ((object & mask) != (sc_dt::uint64)object) { for (bitindex = 0; bitindex < bit_width; bitindex++) { buf[bitindex]='0'; } } else { sc_dt::uint64 bit_mask = 1; bit_mask = bit_mask << (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_bool_trace: public wif_trace{public: wif_bool_trace( const bool& object_, const std::string& name_, const std::string& wif_name_ ); void write( FILE* f ); bool changed();protected: const bool& object; bool old_value;};wif_bool_trace::wif_bool_trace( const bool& 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 = "BIT";}boolwif_bool_trace::changed(){ return object != old_value;}voidwif_bool_trace::write( FILE* f ){ if( object == true ) { std::fprintf( f, "assign %s \'1\' ;\n", wif_name.c_str() ); } else { std::fprintf( f, "assign %s \'0\' ;\n", wif_name.c_str() ); } old_value = object;}//*****************************************************************************class wif_sc_bit_trace : public wif_trace {public: wif_sc_bit_trace(const sc_dt::sc_bit& object_, const std::string& name_, const std::string& wif_name_); void write(FILE* f); bool changed();protected: const sc_dt::sc_bit& object; sc_dt::sc_bit old_value;};wif_sc_bit_trace::wif_sc_bit_trace(const sc_dt::sc_bit& 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 = "BIT";}bool wif_sc_bit_trace::changed(){ return object != old_value;}void wif_sc_bit_trace::write(FILE* f){ if (object == true) { std::fprintf(f, "assign %s \'1\' ;\n", wif_name.c_str()); } else { std::fprintf(f, "assign %s \'0\' ;\n", wif_name.c_str()); } old_value = object;}/*****************************************************************************/class wif_sc_logic_trace: public wif_trace {public: wif_sc_logic_trace(const sc_dt::sc_logic& object_, const std::string& name_, const std::string& wif_name_); void write(FILE* f); bool changed();protected: const sc_dt::sc_logic& object; sc_dt::sc_logic old_value;};wif_sc_logic_trace::wif_sc_logic_trace(const sc_dt::sc_logic& 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 = "MVL";}bool wif_sc_logic_trace::changed(){ return object != old_value;}void wif_sc_logic_trace::write(FILE* f){ char wif_char; std::fprintf(f, "assign %s \'", wif_name.c_str()); wif_char = map_sc_logic_state_to_wif_state(object.to_char()); std::fputc(wif_char, f); std::fprintf(f,"\' ;\n"); old_value = object;}/*****************************************************************************/class wif_sc_unsigned_trace: public wif_trace {public: wif_sc_unsigned_trace(const sc_dt::sc_unsigned& object_, const std::string& name_, const std::string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_dt::sc_unsigned& object; sc_dt::sc_unsigned old_value;};wif_sc_unsigned_trace::wif_sc_unsigned_trace(const sc_dt::sc_unsigned& 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_unsigned_trace::changed(){ return object != old_value;}void wif_sc_unsigned_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_unsigned_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class wif_sc_signed_trace: public wif_trace {public: wif_sc_signed_trace(const sc_dt::sc_signed& object_, const std::string& name_, const std::string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_dt::sc_signed& object; sc_dt::sc_signed old_value;};wif_sc_signed_trace::wif_sc_signed_trace(const sc_dt::sc_signed& 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_signed_trace::changed()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -