sc_trace.cpp

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.cpp - Functions for tracing signals and variables.
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, 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 #include <stdarg.h>
00048 #include <stdio.h>
00049 
00050 #include "sysc/utils/sc_iostream.h"
00051 #include "sysc/tracing/sc_trace.h"
00052 #include "sysc/communication/sc_signal_ifs.h"
00053 #include "sysc/utils/sc_utils_ids.h"
00054 
00055 namespace sc_core {
00056 
00057 // Trace file common functions.
00058 
00059 sc_trace_file::sc_trace_file()
00060 {
00061   /* Intentionally blank */
00062 }
00063 
00064 void
00065 put_error_message(const char* msg, bool just_warning)
00066 {
00067     if(just_warning){
00068         ::std::cout << "Trace Warning:\n" << msg << "\n" << ::std::endl;
00069     }
00070     else{
00071         ::std::cout << "Trace ERROR:\n" << msg << "\n" << ::std::endl;
00072     }
00073 }
00074 
00075 
00076 void sc_trace_file::set_time_unit(double v, sc_time_unit tu)
00077 {
00078     if(initialized)
00079     {        
00080     put_error_message(
00081         "Trace timescale unit cannot be changed once tracing has begun.",
00082         false
00083         );
00084         std::cout << "To change the scale, create a new trace file." 
00085           << std::endl;
00086         return;    
00087     }
00088 
00089     switch ( tu )
00090     {
00091       case SC_FS:  v = v * 1e-15; break;
00092       case SC_PS:  v = v * 1e-12; break;
00093       case SC_NS:  v = v * 1e-9;  break;
00094       case SC_US:  v = v * 1e-6;  break;
00095       case SC_MS:  v = v * 1e-3;  break;
00096       case SC_SEC:                break;
00097       default:                    
00098         put_error_message("Unknown time unit specified ",true);
00099         std::cout << tu << std::endl;
00100         break;
00101     };
00102 
00103     timescale_unit = v;
00104 
00105     // EMIT ADVISORY MESSAGE ABOUT CHANGE IN TIME SCALE:
00106 
00107     char buf[200];
00108     std::sprintf(buf,
00109         "Note: VCD trace timescale unit is set by user to %e sec.\n",
00110         timescale_unit);
00111     ::std::cout << buf << ::std::flush;
00112 
00113     timescale_set_by_user = true;
00114 }
00115 
00116 void sc_trace_file::set_time_unit(int exponent10_seconds)
00117 {
00118     sc_time_unit tu;
00119     double       v;
00120 
00121     if     (exponent10_seconds == -15) { v = 1.0;   tu = SC_FS; }
00122     else if(exponent10_seconds == -14) { v = 10.0;  tu = SC_FS; }
00123     else if(exponent10_seconds == -13) { v = 100.0; tu = SC_FS; }
00124     else if(exponent10_seconds == -12) { v = 1.0;   tu = SC_PS; }
00125     else if(exponent10_seconds == -11) { v = 10.0;  tu = SC_PS; }
00126     else if(exponent10_seconds == -10) { v = 100.0; tu = SC_PS; }
00127     else if(exponent10_seconds ==  -9) { v = 1.0;   tu = SC_NS; }
00128     else if(exponent10_seconds ==  -8) { v = 10.0;  tu = SC_NS; }
00129     else if(exponent10_seconds ==  -7) { v = 100.0; tu = SC_NS; }
00130     else if(exponent10_seconds ==  -6) { v = 1.0;   tu = SC_US; }
00131     else if(exponent10_seconds ==  -5) { v = 10.0;  tu = SC_US; }
00132     else if(exponent10_seconds ==  -4) { v = 100.0; tu = SC_US; }
00133     else if(exponent10_seconds ==  -3) { v = 1.0;   tu = SC_MS; }
00134     else if(exponent10_seconds ==  -2) { v = 10.0;  tu = SC_MS; }
00135     else if(exponent10_seconds ==  -1) { v = 100.0; tu = SC_MS; }
00136     else if(exponent10_seconds ==   0) { v = 1.0;   tu = SC_SEC; }
00137     else if(exponent10_seconds ==   1) { v = 10.0;  tu = SC_SEC; }
00138     else if(exponent10_seconds ==   2) { v = 100.0; tu = SC_SEC; }
00139     else
00140     {
00141     put_error_message(
00142     "set_time_unit() has valid exponent range -15...+2.", false);
00143     return;
00144     }
00145     set_time_unit( v, tu );
00146 }
00147 
00148 void tprintf(sc_trace_file* tf,  const char* format, ...)
00149 {
00150     static char buffer[4096];
00151     va_list ap;
00152     va_start(ap, format);
00153     (void) vsprintf(buffer, format, ap);
00154     va_end(ap);
00155     if (tf) tf->write_comment(buffer);
00156 }
00157 
00158 void sc_trace_file::space(int)
00159 {
00160   /* Intentionally blank */
00161 }
00162 
00163 void sc_trace_file::delta_cycles(bool)
00164 {
00165   /* Intentionally blank */
00166 }
00167 
00168 
00169 void
00170 sc_trace( sc_trace_file* tf,
00171       const sc_signal_in_if<char>& object,
00172       const std::string& name,
00173       int width )
00174 {
00175     if( tf ) {
00176     tf->trace( object.read(), name, width );
00177     }
00178 }
00179 
00180 void
00181 sc_trace( sc_trace_file* tf,
00182       const sc_signal_in_if<short>& object,
00183       const std::string& name,
00184       int width )
00185 {
00186     if( tf ) {
00187     tf->trace( object.read(), name, width );
00188     }
00189 }
00190 
00191 void
00192 sc_trace( sc_trace_file* tf,
00193       const sc_signal_in_if<int>& object,
00194       const std::string& name,
00195       int width )
00196 {
00197     if( tf ) {
00198     tf->trace( object.read(), name, width );
00199     }
00200 }
00201 
00202 void
00203 sc_trace( sc_trace_file* tf,
00204       const sc_signal_in_if<long>& object,
00205       const std::string& name,
00206       int width )
00207 {
00208     if( tf ) {
00209     tf->trace( object.read(), name, width );
00210     }
00211 }
00212 
00213 
00214 void
00215 sc_trace(sc_trace_file* /* not used */,
00216      const void* /* not used */,
00217      const std::string& name)
00218 {
00219     ::std::cout << "Object " << name << " will not be traced" << ::std::endl;
00220 }
00221 
00222 
00223 
00224 void double_to_special_int64(double in, unsigned* high, unsigned* low)
00225 {
00226     double invar = in;
00227     if(invar > 5e17) invar = 5e17; // Saturation limit
00228     if(invar < 0.0) invar = 0.0;
00229     invar += .5;
00230     *high = (unsigned)(invar / 1e9);
00231     double rest = invar - 1e9 * (*high);
00232     if(rest < 0) *low = 0;
00233     else *low = (unsigned)rest;
00234 }
00235 
00236 
00237 // ----------------------------------------------------------------------------
00238 
00239 #define DEFN_TRACE_FUNC_REF_A(tp)                                             \
00240 void                                                                          \
00241 sc_trace( sc_trace_file* tf, const tp& object, const std::string& name ) \
00242 {                                                                             \
00243     if( tf ) {                                                                \
00244     tf->trace( object, name );                                            \
00245     }                                                                         \
00246 }
00247 
00248 #define DEFN_TRACE_FUNC_PTR_A(tp)                                             \
00249 void                                                                          \
00250 sc_trace( sc_trace_file* tf, const tp* object, const std::string& name ) \
00251 {                                                                             \
00252     if( tf ) {                                                                \
00253     tf->trace( *object, name );                                           \
00254     }                                                                         \
00255 }
00256 
00257 #define DEFN_TRACE_FUNC_A(tp)                                                 \
00258 DEFN_TRACE_FUNC_REF_A(tp)                                                     \
00259 DEFN_TRACE_FUNC_PTR_A(tp)
00260 
00261 
00262 DEFN_TRACE_FUNC_A( sc_dt::sc_bit )
00263 DEFN_TRACE_FUNC_A( sc_dt::sc_logic )
00264 
00265 DEFN_TRACE_FUNC_A( sc_dt::sc_int_base )
00266 DEFN_TRACE_FUNC_A( sc_dt::sc_uint_base )
00267 DEFN_TRACE_FUNC_A( sc_dt::sc_signed )
00268 DEFN_TRACE_FUNC_A( sc_dt::sc_unsigned )
00269 
00270 DEFN_TRACE_FUNC_REF_A( sc_dt::sc_bv_base )
00271 DEFN_TRACE_FUNC_REF_A( sc_dt::sc_lv_base )
00272 
00273 
00274 #undef DEFN_TRACE_FUNC_REF_A
00275 #undef DEFN_TRACE_FUNC_PTR_A
00276 #undef DEFN_TRACE_FUNC_A
00277 
00278 
00279 void
00280 sc_trace( sc_trace_file* tf,
00281       const unsigned int& object,
00282       const std::string& name,
00283       const char** enum_literals )
00284 {
00285     static bool warn_sc_trace_literals=true;
00286     if ( warn_sc_trace_literals )
00287     {
00288         warn_sc_trace_literals=false;
00289         SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
00290         "tracing of enumerated literals is deprecated" );
00291     }
00292 
00293     if( tf ) tf->trace( object, name, enum_literals );
00294 }
00295 
00296 } // namespace sc_core
00297 
00298 // Taf!

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