src/sysc/tracing/sc_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_trace.h - Functions for tracing signals and variables.
00021 
00022   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, the basics are identical to what was
00041    originally contributed by Infineon.  The contribution of Infineon
00042    in the development of this tracing technology is hereby
00043    acknowledged.
00044 
00045  *****************************************************************************/
00046 
00047 #ifndef SC_TRACE_H
00048 #define SC_TRACE_H
00049 
00050 #include <cstdio>
00051 
00052 #include "sysc/datatypes/int/sc_nbdefs.h"
00053 #include "sysc/utils/sc_string.h"
00054 
00055 // Some forward declarations
00056 namespace sc_dt
00057 {
00058     class sc_bit;
00059     class sc_logic;
00060     class sc_bv_base;
00061     class sc_lv_base;
00062     class sc_signed;
00063     class sc_unsigned;
00064     class sc_int_base;
00065     class sc_uint_base;
00066     class sc_fxval;
00067     class sc_fxval_fast;
00068     class sc_fxnum;
00069     class sc_fxnum_fast;
00070 }
00071 
00072 namespace sc_core {
00073 
00074 class sc_logic_resolve;
00075 class sc_time;
00076 
00077 template <class T> class sc_signal_in_if;
00078 
00079 // Base class for all kinds of trace files. 
00080 
00081 class sc_trace_file
00082 {
00083     friend class sc_simcontext;
00084     
00085 public:
00086 
00087     // Constructor
00088     sc_trace_file();
00089     
00090     // All functions are pure virtual because they need to be defined by the
00091     // particular tracing mechanism
00092 
00093 
00094 #define DECL_TRACE_METHOD_A(tp)                                               \
00095     virtual void trace( const tp& object,                                     \
00096                         const std::string& name ) = 0;
00097 
00098 #define DECL_TRACE_METHOD_B(tp)                                               \
00099     virtual void trace( const tp& object,                                     \
00100                         const std::string& name,                                     \
00101                         int width ) = 0;
00102 
00103 
00104     DECL_TRACE_METHOD_A( bool )
00105     DECL_TRACE_METHOD_A( sc_dt::sc_bit )
00106     DECL_TRACE_METHOD_A( sc_dt::sc_logic )
00107 
00108     DECL_TRACE_METHOD_B( unsigned char )
00109     DECL_TRACE_METHOD_B( unsigned short )
00110     DECL_TRACE_METHOD_B( unsigned int )
00111     DECL_TRACE_METHOD_B( unsigned long )
00112     DECL_TRACE_METHOD_B( char )
00113     DECL_TRACE_METHOD_B( short )
00114     DECL_TRACE_METHOD_B( int )
00115     DECL_TRACE_METHOD_B( long )
00116     DECL_TRACE_METHOD_B( sc_dt::int64 )
00117     DECL_TRACE_METHOD_B( sc_dt::uint64 )
00118 
00119     DECL_TRACE_METHOD_A( float )
00120     DECL_TRACE_METHOD_A( double )
00121     DECL_TRACE_METHOD_A( sc_dt::sc_int_base )
00122     DECL_TRACE_METHOD_A( sc_dt::sc_uint_base )
00123     DECL_TRACE_METHOD_A( sc_dt::sc_signed )
00124     DECL_TRACE_METHOD_A( sc_dt::sc_unsigned )
00125 
00126     DECL_TRACE_METHOD_A( sc_dt::sc_fxval )
00127     DECL_TRACE_METHOD_A( sc_dt::sc_fxval_fast )
00128     DECL_TRACE_METHOD_A( sc_dt::sc_fxnum )
00129     DECL_TRACE_METHOD_A( sc_dt::sc_fxnum_fast )
00130 
00131     DECL_TRACE_METHOD_A( sc_dt::sc_bv_base )
00132     DECL_TRACE_METHOD_A( sc_dt::sc_lv_base )
00133 
00134 
00135 #undef DECL_TRACE_METHOD_A
00136 #undef DECL_TRACE_METHOD_B
00137 
00138     // Trace an enumerated object - where possible output the enumeration
00139     // literals in the trace file. Enum literals is a null terminated array
00140     // of null terminated char* literal strings.
00141     virtual void trace( const unsigned int& object,
00142                         const std::string& name,
00143                         const char** enum_literals ) = 0;
00144 
00145     // Output a comment to the trace file
00146     virtual void write_comment( const std::string& comment ) = 0;
00147 
00148     // Set the amount of space before next column
00149     // (For most formats this does nothing)
00150     virtual void space( int n );
00151 
00152     // Also trace transitions between delta cycles if flag is true.
00153     virtual void delta_cycles( bool flag );
00154 
00155 protected:
00156 
00157     // Write trace info for cycle
00158     virtual void cycle( bool delta_cycle ) = 0;
00159 
00160     // Flush results and close file
00161     virtual ~sc_trace_file()
00162         { /* Intentionally blank */ };
00163 };
00164 
00165 /*****************************************************************************/
00166 
00167 // Now comes all the SystemC defined tracing functions.
00168 // We define two sc_trace() versions for scalar types; one where the object to
00169 // be traced is passed as a reference and the other where a pointer to the
00170 // tracing object is passed.
00171 
00172 #define DECL_TRACE_FUNC_REF_A(tp)     \
00173 void                                  \
00174 sc_trace( sc_trace_file* tf,          \
00175           const tp& object,               \
00176           const std::string& name );
00177 
00178 #define DECL_TRACE_FUNC_PTR_A(tp)     \
00179 void                                  \
00180 sc_trace( sc_trace_file* tf,          \
00181           const tp* object,               \
00182           const std::string& name );        \
00183 
00184 #define DECL_TRACE_FUNC_A(tp)         \
00185 DECL_TRACE_FUNC_REF_A(tp)             \
00186 DECL_TRACE_FUNC_PTR_A(tp)
00187 
00188 
00189 DECL_TRACE_FUNC_A( sc_dt::sc_bit )
00190 DECL_TRACE_FUNC_A( sc_dt::sc_logic )
00191 
00192 DECL_TRACE_FUNC_A( sc_dt::sc_int_base )
00193 DECL_TRACE_FUNC_A( sc_dt::sc_uint_base )
00194 DECL_TRACE_FUNC_A( sc_dt::sc_signed )
00195 DECL_TRACE_FUNC_A( sc_dt::sc_unsigned )
00196 
00197 DECL_TRACE_FUNC_REF_A( sc_dt::sc_bv_base )
00198 DECL_TRACE_FUNC_REF_A( sc_dt::sc_lv_base )
00199 
00200 
00201 #undef DECL_TRACE_FUNC_REF_A
00202 #undef DECL_TRACE_FUNC_PTR_A
00203 #undef DECL_TRACE_FUNC_A
00204 
00205 
00206 // ----------------------------------------------------------------------------
00207 
00208 #define DEFN_TRACE_FUNC_REF_A(tp)                                             \
00209 inline                                                                        \
00210 void                                                                          \
00211 sc_trace( sc_trace_file* tf, const tp& object, const std::string& name ) \
00212 {                                                                             \
00213     if( tf ) {                                                                \
00214         tf->trace( object, name );                                            \
00215     }                                                                         \
00216 }
00217 
00218 #define DEFN_TRACE_FUNC_PTR_A(tp)                                             \
00219 inline                                                                        \
00220 void                                                                          \
00221 sc_trace( sc_trace_file* tf, const tp* object, const std::string& name ) \
00222 {                                                                             \
00223     if( tf ) {                                                                \
00224         tf->trace( *object, name );                                           \
00225     }                                                                         \
00226 }
00227 
00228 #define DEFN_TRACE_FUNC_A(tp)                                                 \
00229 DEFN_TRACE_FUNC_REF_A(tp)                                                     \
00230 DEFN_TRACE_FUNC_PTR_A(tp)
00231 
00232 
00233 #define DEFN_TRACE_FUNC_REF_B(tp)                                             \
00234 inline                                                                        \
00235 void                                                                          \
00236 sc_trace( sc_trace_file* tf, const tp& object, const std::string& name,  \
00237           int width = 8 * sizeof( tp ) )                                      \
00238 {                                                                             \
00239     if( tf ) {                                                                \
00240         tf->trace( object, name, width );                                     \
00241     }                                                                         \
00242 }
00243 
00244 #define DEFN_TRACE_FUNC_PTR_B(tp)                                             \
00245 inline                                                                        \
00246 void                                                                          \
00247 sc_trace( sc_trace_file* tf, const tp* object, const std::string& name,  \
00248           int width = 8 * sizeof( tp ) )                                      \
00249 {                                                                             \
00250     if( tf ) {                                                                \
00251         tf->trace( *object, name, width );                                    \
00252     }                                                                         \
00253 }
00254 
00255 
00256 #define DEFN_TRACE_FUNC_B(tp)                                                 \
00257 DEFN_TRACE_FUNC_REF_B(tp)                                                     \
00258 DEFN_TRACE_FUNC_PTR_B(tp)
00259 
00260 
00261 DEFN_TRACE_FUNC_A( bool )
00262 DEFN_TRACE_FUNC_A( float )
00263 DEFN_TRACE_FUNC_A( double )
00264 
00265 DEFN_TRACE_FUNC_B( unsigned char )
00266 DEFN_TRACE_FUNC_B( unsigned short )
00267 DEFN_TRACE_FUNC_B( unsigned int )
00268 DEFN_TRACE_FUNC_B( unsigned long )
00269 DEFN_TRACE_FUNC_B( char )
00270 DEFN_TRACE_FUNC_B( short )
00271 DEFN_TRACE_FUNC_B( int )
00272 DEFN_TRACE_FUNC_B( long )
00273 DEFN_TRACE_FUNC_B( sc_dt::int64 )
00274 DEFN_TRACE_FUNC_B( sc_dt::uint64 )
00275 
00276 
00277 #undef DEFN_TRACE_FUNC_REF_A
00278 #undef DEFN_TRACE_FUNC_PTR_A
00279 #undef DEFN_TRACE_FUNC_A
00280 
00281 #undef DEFN_TRACE_FUNC_REF_B
00282 #undef DEFN_TRACE_FUNC_PTR_B
00283 #undef DEFN_TRACE_FUNC_B
00284 
00285 
00286 template <class T> 
00287 inline
00288 void
00289 sc_trace( sc_trace_file* tf,
00290           const sc_signal_in_if<T>& object,
00291           const std::string& name )
00292 {
00293     sc_trace( tf, object.get_data_ref(), name );
00294 }
00295 
00296 template< class T >
00297 inline
00298 void
00299 sc_trace( sc_trace_file* tf,
00300           const sc_signal_in_if<T>& object,
00301           const char* name )
00302 {
00303     sc_trace( tf, object.get_data_ref(), name );
00304 }
00305 
00306 
00307 // specializations for signals of type char, short, int, long
00308 
00309 void sc_trace( sc_trace_file* tf,
00310                const sc_signal_in_if<char>& object,
00311                const std::string& name,
00312                int width );
00313 
00314 void sc_trace( sc_trace_file* tf,
00315                const sc_signal_in_if<short>& object,
00316                const std::string& name,
00317                int width );
00318 
00319 void sc_trace( sc_trace_file* tf,
00320                const sc_signal_in_if<int>& object,
00321                const std::string& name,
00322                int width );
00323 
00324 void sc_trace( sc_trace_file* tf,
00325                const sc_signal_in_if<long>& object,
00326                const std::string& name,
00327                int width );
00328 
00329 
00330 // 1. non-template function is better than template
00331 // 2. more-specialized template is better than less-specialized
00332 // 3. no partial specialization for template functions
00333 
00334 
00335 // Trace an enumerated object - where possible output the enumeration literals
00336 // in the trace file. Enum literals is a null terminated array of null
00337 // terminated char* literal strings.
00338 
00339 void
00340 sc_trace( sc_trace_file* tf,
00341           const unsigned int& object,
00342           const std::string& name,
00343           const char** enum_literals );
00344 
00345 
00346 // Dummy function for arbitrary types of value, does nothing
00347 
00348 extern void sc_trace( sc_trace_file* tf,
00349                       const void* object,
00350                       const std::string& name );
00351 
00352 
00353 // Turn on/off delta cycle tracing on trace file `tf'.
00354 // Default is to turn on delta cycle tracing.
00355 
00356 inline
00357 void
00358 sc_trace_delta_cycles( sc_trace_file* tf, bool on = true )
00359 {
00360     if( tf ) tf->delta_cycles( on );
00361 }
00362 
00363 
00364 // Output a comment to the trace file
00365 
00366 inline
00367 void
00368 sc_write_comment( sc_trace_file* tf, const std::string& comment )
00369 {
00370     if( tf ) tf->write_comment( comment );
00371 }
00372 
00373 
00374 // Equivalent of fprintf for trace files!
00375 
00376 #ifdef __GNUC__
00377 void tprintf( sc_trace_file* tf,  const char* format, ... )
00378     __attribute__ ((format (printf,2,3)));
00379 #else
00380 void tprintf( sc_trace_file* tf,  const char* format, ... );
00381 #endif    
00382 
00383 
00384 // Convert double time to 64-bit integer
00385 
00386 extern void double_to_special_int64( double in,
00387                                      unsigned* high,
00388                                      unsigned* low );
00389 
00390 } // namespace sc_core
00391 
00392 #endif

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