00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 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 (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.accellera.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_file_base.h - Shared internal tracing implementation 00021 00022 Original Author: Philipp A. Hartmann, OFFIS, 2013-11-15 00023 00024 CHANGE LOG AT END OF FILE 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 00029 Acknowledgement: The tracing mechanism is based on the tracing 00030 mechanism developed at Infineon (formerly Siemens HL). Though this 00031 code is somewhat different, and significantly enhanced, the basics 00032 are identical to what was originally contributed by Infineon. The 00033 contribution of Infineon in the development of this tracing 00034 technology is hereby acknowledged. 00035 00036 *****************************************************************************/ 00037 00038 #ifndef SC_TRACE_FILE_BASE_H_INCLUDED_ 00039 #define SC_TRACE_FILE_BASE_H_INCLUDED_ 00040 00041 #include <cstdio> 00042 00043 // use callback-based tracing implementation 00044 #if defined( SC_ENABLE_SIMULATION_PHASE_CALLBACKS_TRACING ) 00045 # define SC_TRACING_PHASE_CALLBACKS_ 1 00046 # include "sysc/kernel/sc_object.h" 00047 #else 00048 # define SC_TRACING_PHASE_CALLBACKS_ 0 00049 #endif 00050 00051 #include "sysc/tracing/sc_trace.h" 00052 #include "sysc/tracing/sc_tracing_ids.h" 00053 00054 namespace sc_core { 00055 00056 // shared implementation of trace files 00057 class sc_trace_file_base 00058 : public sc_trace_file 00059 #if SC_TRACING_PHASE_CALLBACKS_ 00060 , private sc_object // to be used as callback target 00061 #endif 00062 { 00063 public: 00064 const char* filename() const 00065 { return filename_.c_str(); } 00066 00067 bool delta_cycles() const 00068 { return trace_delta_cycles_; } 00069 00070 // Also trace transitions between delta cycles if flag is true. 00071 virtual void delta_cycles(bool flag); 00072 00073 // set a user-define timescale unit for the trace file 00074 virtual void set_time_unit( double v, sc_time_unit tu); 00075 00076 protected: 00077 sc_trace_file_base( const char* name, const char* extension ); 00078 00079 // returns true, iff initialization has been performed 00080 bool initialize(); 00081 // ensure that file has been opened (needed for early write_comment()) 00082 void open_fp(); 00083 // perform format specific initialization 00084 virtual void do_initialize() = 0; 00085 00086 // returns true, if new trace objects can still be added 00087 // (i.e. trace file is not yet initialized) 00088 bool add_trace_check( const std::string& name ) const; 00089 00090 // Flush results and close file. 00091 virtual ~sc_trace_file_base(); 00092 00093 #if SC_TRACING_PHASE_CALLBACKS_ 00094 private: 00095 virtual void simulation_phase_callback(); 00096 #endif // SC_TRACING_PHASE_CALLBACKS_ 00097 00098 protected: 00099 FILE* fp; // pointer to the trace file 00100 double timescale_unit; // in seconds 00101 bool timescale_set_by_user; // = true means set by user 00102 00103 private: 00104 std::string filename_; // name of the file (for reporting) 00105 bool initialized_; // tracing started? 00106 bool trace_delta_cycles_; // also trace delta transitions? 00107 00108 static bool tracing_initialized_; // shared setup of tracing implementation 00109 00110 private: // disabled 00111 sc_trace_file_base( const sc_trace_file_base& ) /* = delete */; 00112 sc_trace_file_base& operator=( const sc_trace_file_base& ) /* = delete */; 00113 00114 }; // class sc_trace_file_base 00115 00116 // ----------------------------------------------------------------------- 00117 00118 // Convert double time to 64-bit integer 00119 00120 void double_to_special_int64( double in, unsigned* high, unsigned* low ); 00121 00122 // obtain formatted time string 00123 std::string localtime_string(); 00124 00125 } // namespace sc_core 00126 00127 /***************************************************************************** 00128 00129 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00130 changes you are making here. 00131 00132 Name, Affiliation, Date: 00133 Description of Modification: 00134 00135 *****************************************************************************/ 00136 00137 #endif // SC_TRACE_FILE_BASE_H_INCLUDED_ 00138 // Taf!