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

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