sc_isdb_trace.cpp
来自「基于4个mips核的noc设计」· C++ 代码 · 共 1,876 行 · 第 1/4 页
CPP
1,876 行
/***************************************************************************** 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_isdb_trace.cpp - Implementation of ISDB tracing. Original Author: Ulli Holtmann, Synopsys, Inc. *****************************************************************************//***************************************************************************** MODIFICATION LOG - modifiers, enter your name, affiliation, 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: *****************************************************************************/#include <assert.h>#include <ctime>#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/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_isdb_trace.h"#include "systemc/utils/sc_iostream.h"#include "systemc/utils/sc_string.h"static bool running_regression = false;// Forward declarations for functions that come later in the file// Map sc_logic to printable ISDBstatic unsigned int map_sc_logic_state_to_isdb_binval (char);// Print ISDB error messagestatic void isdb_put_error_message(const char* msg, bool just_warning);/*****************************************************************************/// Base class for the tracesclass isdb_trace {public: isdb_trace(const sc_string& name_, const sc_string& isdb_name_); // Needs to be pure virtual as has to be defined by the particular // type being traced virtual void write(ISDB_Conn database) = 0; virtual void set_width(); // Comparison function needs to be pure virtual too virtual bool changed() = 0; // Make this virtual as some derived classes may overwrite virtual void declare_variable(ISDB_Conn database); void compose_data_line(char* rawdata, char* compdata); virtual ~isdb_trace(); const sc_string name; const sc_string isdb_name; const char* isdb_var_typ_name; int bit_width; ISDB_Signal isdb_id;};isdb_trace::isdb_trace(const sc_string& name_, const sc_string& isdb_name_) : name(name_), isdb_name(isdb_name_), bit_width(0){ /* Intentionally blank */} void isdb_trace::compose_data_line(char* rawdata, char* compdata){ assert(rawdata != compdata); if(bit_width == 0) { compdata[0] = '\0'; } else { if(bit_width == 1){ compdata[0] = rawdata[0]; strcpy(&(compdata[1]), isdb_name); } else{ char* effective_begin = rawdata; sprintf(compdata, "b%s %s", effective_begin, (const char *) isdb_name); } }}void isdb_trace::declare_variable (ISDB_Conn /* database */){ /* Intentionally Blank, should be defined for each type separately */}void isdb_trace::set_width(){ /* Intentionally Blank, should be defined for each type separately */}isdb_trace::~isdb_trace(){ /* Intentionally Blank */}/*****************************************************************************/class isdb_bool_trace : public isdb_trace {public: isdb_bool_trace(const bool& object, const sc_string& name_, const sc_string& isdb_name_); void write(ISDB_Conn database); bool changed(); void declare_variable(ISDB_Conn database);protected: const bool& object; bool old_value;};isdb_bool_trace::isdb_bool_trace(const bool& object_, const sc_string& name_, const sc_string& isdb_name_) : isdb_trace(name_, isdb_name_), object( object_){ isdb_var_typ_name = "wire"; bit_width = 1; old_value = object;}void isdb_bool_trace::declare_variable (ISDB_Conn database){ isdb_id = ISDB_DefineSignal (database, ISDB_Binary, (const char*)name); write(database);}bool isdb_bool_trace::changed(){ return object != old_value;}void isdb_bool_trace::write(ISDB_Conn database){ int val = object==true ? ISDB_HIGH : ISDB_LOW; ISDB_SetValue (database, isdb_id, val); old_value = object;}/*****************************************************************************/class isdb_sc_bit_trace: public isdb_trace{public: isdb_sc_bit_trace(const sc_bit& , const sc_string& , const sc_string& ); void write(ISDB_Conn database); bool changed(); void declare_variable(ISDB_Conn database);protected: const sc_bit& object; sc_bit old_value;};isdb_sc_bit_trace::isdb_sc_bit_trace( const sc_bit& object_, const sc_string& name_, const sc_string& isdb_name ): isdb_trace( name_, isdb_name ), object( object_ ){ isdb_var_typ_name = "wire"; bit_width = 1; old_value = object;}void isdb_sc_bit_trace::declare_variable (ISDB_Conn database){ isdb_id = ISDB_DefineSignal (database, ISDB_Binary, (const char*)name); write(database);}bool isdb_sc_bit_trace::changed(){ return object != old_value;}void isdb_sc_bit_trace::write(ISDB_Conn database){ int val = object==true ? ISDB_HIGH : ISDB_LOW; ISDB_SetValue (database, isdb_id, val); old_value = object;}/*****************************************************************************/class isdb_sc_logic_trace : public isdb_trace {public: isdb_sc_logic_trace(const sc_logic& object, const sc_string& name_, const sc_string& isdb_name_); void write(ISDB_Conn database); bool changed(); void declare_variable(ISDB_Conn database);protected: const sc_logic& object; sc_logic old_value;};isdb_sc_logic_trace::isdb_sc_logic_trace(const sc_logic& object_, const sc_string& name_, const sc_string& isdb_name_) : isdb_trace( name_, isdb_name_), object( object_){ isdb_var_typ_name = "wire"; bit_width = 1; old_value = object;}void isdb_sc_logic_trace::declare_variable (ISDB_Conn database){ isdb_id = ISDB_DefineSignal (database, ISDB_Binary, name); write(database);}bool isdb_sc_logic_trace::changed(){ return object != old_value;}void isdb_sc_logic_trace::write(ISDB_Conn database){ int val = map_sc_logic_state_to_isdb_binval(object.to_char()); ISDB_SetValue (database, isdb_id, val); old_value = object;}/*****************************************************************************/class isdb_sc_unsigned_trace : public isdb_trace {public: isdb_sc_unsigned_trace(const sc_unsigned& object, const sc_string& name_, const sc_string& isdb_name_); void declare_variable(ISDB_Conn database); void write(ISDB_Conn database); bool changed(); void set_width();protected: const sc_unsigned& object; sc_unsigned old_value;};isdb_sc_unsigned_trace::isdb_sc_unsigned_trace(const sc_unsigned& object_, const sc_string& name_, const sc_string& isdb_name_) : isdb_trace( name_, isdb_name_), object( object_), old_value( object_.length()) // The last may look strange, but is correct{ isdb_var_typ_name = "wire"; old_value = object;}void isdb_sc_unsigned_trace::declare_variable (ISDB_Conn database){ isdb_id = ISDB_DefineSignal (database, ISDB_Integer, name); write(database);}bool isdb_sc_unsigned_trace::changed(){ return object != old_value;}void isdb_sc_unsigned_trace::write(ISDB_Conn database){ ISDB_SetValue (database, isdb_id, object.to_uint()); old_value = object;}void isdb_sc_unsigned_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class isdb_sc_signed_trace : public isdb_trace {public: isdb_sc_signed_trace(const sc_signed& object, const sc_string& name_, const sc_string& isdb_name_); void declare_variable(ISDB_Conn database); void write(ISDB_Conn database); bool changed(); void set_width();protected: const sc_signed& object; sc_signed old_value;};isdb_sc_signed_trace::isdb_sc_signed_trace(const sc_signed& object_, const sc_string& name_, const sc_string& isdb_name_) : isdb_trace( name_, isdb_name_), object( object_), old_value( object_.length()){ isdb_var_typ_name = "wire"; old_value = object;}void isdb_sc_signed_trace::declare_variable (ISDB_Conn database){ isdb_id = ISDB_DefineSignal (database, ISDB_Integer, name); write(database);}bool isdb_sc_signed_trace::changed(){ return object != old_value;}void isdb_sc_signed_trace::write(ISDB_Conn database){ ISDB_SetValue (database, isdb_id, object.to_int()); old_value = object;}void isdb_sc_signed_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class isdb_sc_uint_base_trace : public isdb_trace {public: isdb_sc_uint_base_trace(const sc_uint_base& object, const sc_string& name_, const sc_string& isdb_name_); void declare_variable(ISDB_Conn database); void write(ISDB_Conn database); bool changed(); void set_width();protected: const sc_uint_base& object; sc_uint_base old_value;};isdb_sc_uint_base_trace::isdb_sc_uint_base_trace(const sc_uint_base& object_, const sc_string& name_, const sc_string& isdb_name_) : isdb_trace( name_, isdb_name_), object( object_), old_value( object_.length()) // The last may look strange, but is correct{ isdb_var_typ_name = "wire"; old_value = object;}void isdb_sc_uint_base_trace::declare_variable (ISDB_Conn database){ isdb_id = ISDB_DefineSignal (database, ISDB_Integer, name); write(database);}bool isdb_sc_uint_base_trace::changed(){ return object != old_value;}void isdb_sc_uint_base_trace::write(ISDB_Conn database){ ISDB_SetValue (database, isdb_id, uint64(object)); old_value = object;}void isdb_sc_uint_base_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class isdb_sc_int_base_trace : public isdb_trace {public: isdb_sc_int_base_trace(const sc_int_base& object, const sc_string& name_, const sc_string& isdb_name_); void declare_variable(ISDB_Conn database); void write(ISDB_Conn database); bool changed(); void set_width();protected: const sc_int_base& object; sc_int_base old_value;};isdb_sc_int_base_trace::isdb_sc_int_base_trace(const sc_int_base& object_, const sc_string& name_, const sc_string& isdb_name_) : isdb_trace( name_, isdb_name_), object( object_), old_value( object_.length()){ isdb_var_typ_name = "wire"; old_value = object;}void isdb_sc_int_base_trace::declare_variable (ISDB_Conn database){ isdb_id = ISDB_DefineSignal (database, ISDB_Integer, name); write(database);}bool isdb_sc_int_base_trace::changed(){ return object != old_value;}void isdb_sc_int_base_trace::write(ISDB_Conn database){ ISDB_SetValue (database, isdb_id, int64(object)); old_value = object;}void isdb_sc_int_base_trace::set_width(){ bit_width = object.length();}/*****************************************************************************/class isdb_sc_fxval_trace : public isdb_trace{public: isdb_sc_fxval_trace( const sc_fxval& object, const sc_string& name_, const sc_string& isdb_name_ ); void declare_variable( ISDB_Conn database ); void write( ISDB_Conn database );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?