sc_wif_trace.cpp
来自「基于4个mips核的noc设计」· C++ 代码 · 共 1,863 行 · 第 1/4 页
CPP
1,863 行
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2002 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.3 (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 <stdlib.h>#include "systemc/kernel/sc_simcontext.h"#include "systemc/kernel/sc_ver.h"#include "systemc/datatypes/bit/sc_bit.h"#include "systemc/datatypes/bit/sc_logic.h"#include "systemc/datatypes/bit/sc_lv_base.h"#include "systemc/datatypes/int/sc_signed.h"#include "systemc/datatypes/int/sc_unsigned.h"#include "systemc/datatypes/int/sc_int_base.h"#include "systemc/datatypes/int/sc_uint_base.h"#include "systemc/datatypes/fx/fx.h"#include "systemc/tracing/sc_wif_trace.h"#include "systemc/utils/sc_string.h"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 sc_string& name_, const sc_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 sc_string name; // Name of the variable const sc_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 sc_string& name_, const sc_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 ) { sprintf( buf, "Traced object \"%s\" has < 0 Bits, cannot be traced.", (const char *) name ); wif_put_error_message( buf, false ); } else { fprintf( f, "declare %s \"%s\" %s ", (const char *) wif_name, (const char *) name, wif_type ); if( bit_width > 0 ) { fprintf( f, "0 %d ", bit_width - 1 ); } fprintf( f, "variable ;\n" ); fprintf( f, "start_trace %s ;\n", (const char *) wif_name ); }}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_bool_trace: public wif_trace{public: wif_bool_trace( const bool& object_, const sc_string& name_, const sc_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 sc_string& name_, const sc_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 ) { fprintf( f, "assign %s \'1\' ;\n", (const char *) wif_name ); } else { fprintf( f, "assign %s \'0\' ;\n", (const char *) wif_name ); } old_value = object;}//*****************************************************************************class wif_sc_bit_trace : public wif_trace {public: wif_sc_bit_trace(const sc_bit& object_, const sc_string& name_, const sc_string& wif_name_); void write(FILE* f); bool changed();protected: const sc_bit& object; sc_bit old_value;};wif_sc_bit_trace::wif_sc_bit_trace(const sc_bit& object_, const sc_string& name_, const sc_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) { fprintf(f, "assign %s \'1\' ;\n", (const char *) wif_name); } else { fprintf(f, "assign %s \'0\' ;\n", (const char *) wif_name); } old_value = object;}/*****************************************************************************/class wif_sc_logic_trace: public wif_trace {public: wif_sc_logic_trace(const sc_logic& object_, const sc_string& name_, const sc_string& wif_name_); void write(FILE* f); bool changed();protected: const sc_logic& object; sc_logic old_value;};wif_sc_logic_trace::wif_sc_logic_trace(const sc_logic& object_, const sc_string& name_, const sc_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; fprintf(f, "assign %s \'", (const char *) wif_name); wif_char = map_sc_logic_state_to_wif_state(object.to_char()); fputc(wif_char, f); fprintf(f,"\' ;\n"); old_value = object;}/*****************************************************************************/class wif_sc_unsigned_trace: public wif_trace {public: wif_sc_unsigned_trace(const sc_unsigned& object_, const sc_string& name_, const sc_string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_unsigned& object; sc_unsigned old_value;};wif_sc_unsigned_trace::wif_sc_unsigned_trace(const sc_unsigned& object_, const sc_string& name_, const sc_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'; fprintf(f, "assign %s \"%s\" ;\n", (const char *) wif_name, 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_signed& object_, const sc_string& name_, const sc_string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_signed& object; sc_signed old_value;};wif_sc_signed_trace::wif_sc_signed_trace(const sc_signed& object_, const sc_string& name_, const sc_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(){ 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'; fprintf(f, "assign %s \"%s\" ;\n", (const char *) wif_name, 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_uint_base& object_, const sc_string& name_, const sc_string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_uint_base& object; sc_uint_base old_value;};wif_sc_uint_base_trace::wif_sc_uint_base_trace(const sc_uint_base& object_, const sc_string& name_, const sc_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'; fprintf(f, "assign %s \"%s\" ;\n", (const char *) wif_name, 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_int_base& object_, const sc_string& name_, const sc_string& wif_name_); void write(FILE* f); bool changed(); void set_width();protected: const sc_int_base& object; sc_int_base old_value;};wif_sc_int_base_trace::wif_sc_int_base_trace(const sc_int_base& object_, const sc_string& name_, const sc_string& wif_name_) : wif_trace(name_, wif_name_), object(object_), old_value(object_.length()){ old_value = object; wif_type = "BIT";}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?