sc_wif_trace.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_wif_trace.h - Implementation of WIF tracing.
00021 
00022   Original Author - Abhijit Ghosh, Synopsys, Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 /*****************************************************************************
00037 
00038    Acknowledgement: The tracing mechanism is based on the tracing
00039    mechanism developed at Infineon (formerly Siemens HL). Though this
00040    code is somewhat different, and significantly enhanced, the basics
00041    are identical to what was originally contributed by Infineon.
00042    The contribution of Infineon in the development of this tracing
00043    technology is hereby acknowledged.
00044 
00045  *****************************************************************************/
00046 
00047 /*****************************************************************************
00048 
00049    Instead of creating the binary WIF format, we create the ASCII
00050    WIF format which can be converted to the binary format using
00051    a2wif (utility that comes with VSS from Synopsys). This way, 
00052    a user who does not have Synopsys VSS can still create WIF 
00053    files, but the files can only be viewed by users who have VSS.
00054 
00055  *****************************************************************************/
00056 
00057 #ifndef SC_WIF_TRACE_H
00058 #define SC_WIF_TRACE_H
00059 
00060 #include <cstdio>
00061 #include "sysc/datatypes/int/sc_nbdefs.h"
00062 #include "sysc/tracing/sc_trace.h"
00063 
00064 namespace sc_core {
00065 
00066 class wif_trace;  // defined in wif_trace.cc
00067 template<class T> class wif_T_trace;
00068 
00069 class wif_trace_file : public sc_trace_file{
00070 public:
00071     enum wif_enum {WIF_BIT=0, WIF_MVL=1, WIF_REAL=2, WIF_LAST};
00072 
00073     // sc_set_wif_time_unit is deprecated.
00074     inline void sc_set_wif_time_unit(int exponent10_seconds)
00075         { set_time_unit(exponent10_seconds); }
00076 
00077     // Create a wif trace file.
00078     // `Name' forms the base of the name to which `.awif' is added.
00079     wif_trace_file(const char *name);
00080 
00081     // Flush results and close file.
00082     ~wif_trace_file();
00083 
00084 protected:
00085     // These are all virtual functions in sc_trace_file and
00086     // they need to be defined here.
00087 
00088     // Trace a boolean object (single bit)
00089      void trace(const bool& object, const std::string& name);
00090 
00091     // Trace a sc_bit object (single bit)
00092      void trace(const sc_dt::sc_bit& object, const std::string& name);
00093 
00094     // Trace a sc_logic object (single bit)
00095      void trace(const sc_dt::sc_logic& object, const std::string& name);
00096     
00097     // Trace an unsigned char with the given width
00098      void trace(const unsigned char& object, const std::string& name, 
00099     int width);
00100 
00101     // Trace an unsigned short with the given width
00102      void trace(const unsigned short& object, const std::string& name, 
00103          int width);
00104 
00105     // Trace an unsigned int with the given width
00106      void trace(const unsigned int& object, const std::string& name, 
00107          int width);
00108 
00109     // Trace an unsigned long with the given width
00110      void trace(const unsigned long& object, const std::string& name, 
00111          int width);
00112 
00113     // Trace a signed char with the given width
00114      void trace(const char& object, const std::string& name, int width);
00115 
00116     // Trace a signed short with the given width
00117      void trace(const short& object, const std::string& name, int width);
00118 
00119     // Trace a signed int with the given width
00120      void trace(const int& object, const std::string& name, int width);
00121 
00122     // Trace a signed long with the given width
00123      void trace(const long& object, const std::string& name, int width);
00124     
00125     // Trace a signed long long with the given width
00126      void trace(const sc_dt::int64& object, const std::string& name, 
00127          int width);
00128     
00129     // Trace an usigned long long with the given width
00130      void trace(const sc_dt::uint64& object, const std::string& name, 
00131          int width);
00132     
00133     // Trace a float
00134      void trace(const float& object, const std::string& name);
00135 
00136     // Trace a double
00137      void trace(const double& object, const std::string& name);
00138 
00139     // Trace sc_unsigned
00140      void trace (const sc_dt::sc_unsigned& object, 
00141      const std::string& name);
00142 
00143     // Trace sc_signed
00144      void trace (const sc_dt::sc_signed& object, 
00145      const std::string& name);
00146 
00147     // Trace sc_uint_base
00148      void trace (const sc_dt::sc_uint_base& object, 
00149          const std::string& name);
00150 
00151     // Trace sc_int_base
00152      void trace (const sc_dt::sc_int_base& object, const std::string& name);
00153 
00154     // Trace sc_fxval
00155     void trace( const sc_dt::sc_fxval& object, const std::string& name );
00156 
00157     // Trace sc_fxval_fast
00158     void trace( const sc_dt::sc_fxval_fast& object, 
00159         const std::string& name );
00160 
00161     // Trace sc_fxnum
00162     void trace( const sc_dt::sc_fxnum& object, const std::string& name );
00163 
00164     // Trace sc_fxnum_fast
00165     void trace( const sc_dt::sc_fxnum_fast& object, 
00166         const std::string& name );
00167 
00168     template<class T>
00169     void traceT(const T& object, const std::string& name, wif_enum type)
00170     {
00171       if(initialized)
00172         put_error_message("No traces can be added once simulation has"
00173         " started.\nTo add traces, create a new wif trace file.", false);
00174       else
00175         traces.push_back(new wif_T_trace<T>(object, name,
00176           obtain_new_index(),type));
00177     }
00178 
00179     // Trace sc_bv_base (sc_bv)
00180     virtual void trace( const sc_dt::sc_bv_base& object, 
00181         const std::string& name );
00182 
00183     // Trace sc_lv_base (sc_lv)
00184     virtual void trace( const sc_dt::sc_lv_base& object, 
00185         const std::string& name );
00186 
00187     // Trace an enumerated object - where possible output the enumeration literals
00188     // in the trace file. Enum literals is a null terminated array of null
00189     // terminated char* literal strings.
00190      void trace(const unsigned& object, const std::string& name, 
00191          const char** enum_literals);
00192 
00193     // Output a comment to the trace file
00194      void write_comment(const std::string& comment);
00195 
00196     // Also trace transitions between delta cycles if flag is true.
00197      void delta_cycles(bool flag);
00198 
00199     // Write trace info for cycle.
00200      void cycle(bool delta_cycle);
00201 
00202 private:
00203     // Initialize the tracing mechanism
00204     void initialize();
00205 
00206     // Create wif names for each variable
00207     void create_wif_name(std::string* ptr_to_str);
00208 
00209     // Pointer to the file that needs to be written
00210     FILE* fp;
00211 
00212     bool trace_delta_cycles;    // = 1 means trace the delta cycles
00213 
00214     unsigned wif_name_index;    // Number of variables traced
00215 
00216     unsigned previous_time_units_low, previous_time_units_high; // Previous time as 64 bit integer
00217     double previous_time;       // Previous time as a double
00218 
00219 public:
00220 
00221     // same as create_wif_name (corrected style)
00222     std::string obtain_new_index();
00223 
00224     // Array to store the variables traced
00225     std::vector<wif_trace*> traces;
00226 };
00227 
00228 // Create WIF file
00229 extern sc_trace_file *sc_create_wif_trace_file(const char *name);
00230 extern void sc_close_wif_trace_file( sc_trace_file* tf );
00231 
00232 } //  namespace sc_core
00233 
00234 #endif

Generated on Wed Jan 21 15:32:10 2009 for SystemC by  doxygen 1.5.5