src/sysc/tracing/sc_vcd_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-2005 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_vcd_trace.h - Implementation of VCD 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.  The
00042    contribution of Infineon in the development of this tracing
00043    technology is hereby acknowledged.
00044 
00045  *****************************************************************************/
00046 
00047 #ifndef SC_VCD_TRACE_H
00048 #define SC_VCD_TRACE_H
00049 
00050 
00051 #include <cstdio>
00052 #include "sysc/tracing/sc_trace.h"
00053 #include "sysc/utils/sc_vector.h"
00054 
00055 namespace sc_core {
00056 
00057 class vcd_trace;  // defined in vcd_trace.cpp
00058 template<class T> class vcd_T_trace;
00059 
00060 // Print VCD error message
00061 void vcd_put_error_message(const char* msg, bool just_warning);
00062 
00063 
00064 // ----------------------------------------------------------------------------
00065 //  CLASS : vcd_trace_file
00066 //
00067 //  ...
00068 // ----------------------------------------------------------------------------
00069 
00070 class vcd_trace_file
00071 : public sc_trace_file
00072 {
00073 public:
00074 
00075     enum vcd_enum {VCD_WIRE=0, VCD_REAL=1, VCD_LAST};
00076     void sc_set_vcd_time_unit(int exponent10_seconds); // -7 -> 100ns
00077 
00078     // Create a Vcd trace file.
00079     // `Name' forms the base of the name to which `.vcd' is added.
00080     vcd_trace_file(const char *name);
00081 
00082     // Flush results and close file.
00083     ~vcd_trace_file();
00084 
00085 protected:
00086 
00087     // These are all virtual functions in sc_trace_file and
00088     // they need to be defined here.
00089 
00090     // Trace a boolean object (single bit)
00091      void trace(const bool& object, const std::string& name);
00092 
00093     // Trace a sc_bit object (single bit)
00094     virtual void trace( const sc_dt::sc_bit& object, 
00095             const std::string& name);
00096 
00097     // Trace a sc_logic object (single bit)
00098      void trace(const sc_dt::sc_logic& object, const std::string& name);
00099     
00100     // Trace an unsigned char with the given width
00101      void trace(const unsigned char& object, const std::string& name, 
00102         int width);
00103 
00104     // Trace an unsigned short with the given width
00105      void trace(const unsigned short& object, const std::string& name, 
00106         int width);
00107 
00108     // Trace an unsigned int with the given width
00109      void trace(const unsigned int& object, const std::string& name, 
00110         int width);
00111 
00112     // Trace an unsigned long with the given width
00113      void trace(const unsigned long& object, const std::string& name, 
00114         int width);
00115 
00116     // Trace a signed char with the given width
00117      void trace(const char& object, const std::string& name, int width);
00118 
00119     // Trace a signed short with the given width
00120      void trace(const short& object, const std::string& name, int width);
00121 
00122     // Trace a signed int with the given width
00123      void trace(const int& object, const std::string& name, int width);
00124 
00125     // Trace a signed long with the given width
00126      void trace(const long& object, const std::string& name, int width);
00127     
00128     // Trace an int64 with a given width
00129      void trace(const sc_dt::int64& object, const std::string& name, 
00130          int width);
00131 
00132     // Trace a uint64 with a given width
00133      void trace(const sc_dt::uint64& object, const std::string& name, 
00134          int width);
00135 
00136     // Trace a float
00137      void trace(const float& object, const std::string& name);
00138 
00139     // Trace a double
00140      void trace(const double& object, const std::string& name);
00141 
00142     // Trace sc_dt::sc_uint_base
00143      void trace (const sc_dt::sc_uint_base& object, 
00144                 const std::string& name);
00145 
00146     // Trace sc_dt::sc_int_base
00147      void trace (const sc_dt::sc_int_base& object, 
00148                 const std::string& name);
00149 
00150     // Trace sc_dt::sc_unsigned
00151      void trace (const sc_dt::sc_unsigned& object, 
00152                 const std::string& name);
00153 
00154     // Trace sc_dt::sc_signed
00155      void trace (const sc_dt::sc_signed& object, const std::string& name);
00156 
00157     // Trace sc_dt::sc_fxval
00158     void trace( const sc_dt::sc_fxval& object, const std::string& name );
00159 
00160     // Trace sc_dt::sc_fxval_fast
00161     void trace( const sc_dt::sc_fxval_fast& object, 
00162                 const std::string& name );
00163 
00164     // Trace sc_dt::sc_fxnum
00165     void trace( const sc_dt::sc_fxnum& object, const std::string& name );
00166 
00167     // Trace sc_dt::sc_fxnum_fast
00168     void trace( const sc_dt::sc_fxnum_fast& object, 
00169                 const std::string& name );
00170 
00171     template<class T>
00172     void traceT(const T& object, const std::string& name, 
00173         vcd_enum type=VCD_WIRE)
00174     {
00175       if(initialized)
00176          vcd_put_error_message("No traces can be added once simulation has"
00177          " started.\nTo add traces, create a new vcd trace file.", false);
00178       else
00179         traces.push_back(new vcd_T_trace<T>(object, name, obtain_name(),type));
00180     }
00181 
00182    // Trace sc_dt::sc_bv_base (sc_dt::sc_bv)
00183     virtual void trace(const sc_dt::sc_bv_base& object, 
00184                 const std::string& name);
00185 
00186     // Trace sc_dt::sc_lv_base (sc_dt::sc_lv)
00187     virtual void trace(const sc_dt::sc_lv_base& object, 
00188             const std::string& name);
00189     // Trace an enumerated object - where possible output the enumeration literals
00190     // in the trace file. Enum literals is a null terminated array of null
00191     // terminated char* literal strings.
00192      void trace(const unsigned& object, const std::string& name, 
00193         const char** enum_literals);
00194 
00195     // Output a comment to the trace file
00196      void write_comment(const std::string& comment);
00197 
00198     // Also trace transitions between delta cycles if flag is true.
00199      void delta_cycles(bool flag);
00200 
00201     // Write trace info for cycle.
00202      void cycle(bool delta_cycle);
00203     
00204 private:
00205 
00206     // Initialize the tracing
00207     void initialize();
00208     // Create VCD names for each variable
00209     void create_vcd_name(std::string* p_destination);
00210 
00211     // Pointer to the file that needs to be written
00212     FILE* fp;
00213 
00214     double timescale_unit;      // in seconds
00215     bool timescale_set_by_user; // = 1 means set by user
00216     bool trace_delta_cycles;    // = 1 means trace the delta cycles
00217 
00218     unsigned vcd_name_index;    // Number of variables traced
00219 
00220     unsigned previous_time_units_low, previous_time_units_high; // Previous time unit as 64-bit integer
00221 
00222 public:
00223 
00224     // Array to store the variables traced
00225     sc_pvector<vcd_trace*> traces;
00226     bool initialized;           // = 1 means initialized
00227     // same as create_vcd_name (corrected style)
00228     std::string obtain_name();
00229 };
00230 
00231 
00232 // ----------------------------------------------------------------------------
00233 
00234 // Create VCD file
00235 extern sc_trace_file *sc_create_vcd_trace_file(const char* name);
00236 extern void sc_close_vcd_trace_file( sc_trace_file* tf );
00237 
00238 } // namespace sc_core
00239 #endif

Generated on Wed Apr 25 13:53:28 2007 for SystemC by  doxygen 1.5.1