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-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_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 
00054 namespace sc_core {
00055 
00056 class vcd_trace;  // defined in vcd_trace.cpp
00057 template<class T> class vcd_T_trace;
00058 
00059 
00060 // ----------------------------------------------------------------------------
00061 //  CLASS : vcd_trace_file
00062 //
00063 //  ...
00064 // ----------------------------------------------------------------------------
00065 
00066 class vcd_trace_file
00067 : public sc_trace_file
00068 {
00069 public:
00070 
00071     enum vcd_enum {VCD_WIRE=0, VCD_REAL=1, VCD_LAST};
00072     // sc_set_vcd_time_unit is deprecated.
00073     inline void sc_set_vcd_time_unit(int exponent10_seconds)
00074         { set_time_unit(exponent10_seconds); }
00075 
00076     // Create a Vcd trace file.
00077     // `Name' forms the base of the name to which `.vcd' is added.
00078     vcd_trace_file(const char *name);
00079 
00080     // Flush results and close file.
00081     ~vcd_trace_file();
00082 
00083 protected:
00084 
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     virtual void trace( const sc_dt::sc_bit& object, 
00093         const std::string& name);
00094 
00095     // Trace a sc_logic object (single bit)
00096      void trace(const sc_dt::sc_logic& object, const std::string& name);
00097     
00098     // Trace an unsigned char with the given width
00099      void trace(const unsigned char& object, const std::string& name, 
00100         int width);
00101 
00102     // Trace an unsigned short with the given width
00103      void trace(const unsigned short& object, const std::string& name, 
00104         int width);
00105 
00106     // Trace an unsigned int with the given width
00107      void trace(const unsigned int& object, const std::string& name, 
00108         int width);
00109 
00110     // Trace an unsigned long with the given width
00111      void trace(const unsigned long& object, const std::string& name, 
00112         int width);
00113 
00114     // Trace a signed char with the given width
00115      void trace(const char& object, const std::string& name, int width);
00116 
00117     // Trace a signed short with the given width
00118      void trace(const short& object, const std::string& name, int width);
00119 
00120     // Trace a signed int with the given width
00121      void trace(const int& object, const std::string& name, int width);
00122 
00123     // Trace a signed long with the given width
00124      void trace(const long& object, const std::string& name, int width);
00125     
00126     // Trace an int64 with a given width
00127      void trace(const sc_dt::int64& object, const std::string& name, 
00128          int width);
00129 
00130     // Trace a uint64 with a given width
00131      void trace(const sc_dt::uint64& object, const std::string& name, 
00132          int width);
00133 
00134     // Trace a float
00135      void trace(const float& object, const std::string& name);
00136 
00137     // Trace a double
00138      void trace(const double& object, const std::string& name);
00139 
00140     // Trace sc_dt::sc_uint_base
00141      void trace (const sc_dt::sc_uint_base& object, 
00142         const std::string& name);
00143 
00144     // Trace sc_dt::sc_int_base
00145      void trace (const sc_dt::sc_int_base& object, 
00146         const std::string& name);
00147 
00148     // Trace sc_dt::sc_unsigned
00149      void trace (const sc_dt::sc_unsigned& object, 
00150         const std::string& name);
00151 
00152     // Trace sc_dt::sc_signed
00153      void trace (const sc_dt::sc_signed& object, const std::string& name);
00154 
00155     // Trace sc_dt::sc_fxval
00156     void trace( const sc_dt::sc_fxval& object, const std::string& name );
00157 
00158     // Trace sc_dt::sc_fxval_fast
00159     void trace( const sc_dt::sc_fxval_fast& object, 
00160         const std::string& name );
00161 
00162     // Trace sc_dt::sc_fxnum
00163     void trace( const sc_dt::sc_fxnum& object, const std::string& name );
00164 
00165     // Trace sc_dt::sc_fxnum_fast
00166     void trace( const sc_dt::sc_fxnum_fast& object, 
00167         const std::string& name );
00168 
00169     template<class T>
00170     void traceT(const T& object, const std::string& name, 
00171         vcd_enum type=VCD_WIRE)
00172     {
00173       if(initialized)
00174          put_error_message("No traces can be added once simulation has"
00175          " started.\nTo add traces, create a new vcd trace file.", false);
00176       else
00177         traces.push_back(new vcd_T_trace<T>(object, name, obtain_name(),type));
00178     }
00179 
00180    // Trace sc_dt::sc_bv_base (sc_dt::sc_bv)
00181     virtual void trace(const sc_dt::sc_bv_base& object, 
00182         const std::string& name);
00183 
00184     // Trace sc_dt::sc_lv_base (sc_dt::sc_lv)
00185     virtual void trace(const sc_dt::sc_lv_base& object, 
00186         const std::string& name);
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 
00204     // Initialize the tracing
00205     void initialize();
00206     // Create VCD names for each variable
00207     void create_vcd_name(std::string* p_destination);
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 vcd_name_index;    // Number of variables traced
00215 
00216     unsigned previous_time_units_low, previous_time_units_high; // Previous time unit as 64-bit integer
00217 
00218 public:
00219 
00220     // Array to store the variables traced
00221     std::vector<vcd_trace*> traces;
00222     // same as create_vcd_name (corrected style)
00223     std::string obtain_name();
00224 };
00225 
00226 
00227 // ----------------------------------------------------------------------------
00228 
00229 // Create VCD file
00230 extern sc_trace_file *sc_create_vcd_trace_file(const char* name);
00231 extern void sc_close_vcd_trace_file( sc_trace_file* tf );
00232 
00233 } // namespace sc_core
00234 #endif

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