SystemC  Recoding Infrastructure for SystemC v0.6.0 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_trace_file_base.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_trace_file_base.h - Shared internal tracing implementation
21 
22  Original Author: Philipp A. Hartmann, OFFIS, 2013-11-15
23 
24  CHANGE LOG AT END OF FILE
25  *****************************************************************************/
26 
27 /*****************************************************************************
28 
29  Acknowledgement: The tracing mechanism is based on the tracing
30  mechanism developed at Infineon (formerly Siemens HL). Though this
31  code is somewhat different, and significantly enhanced, the basics
32  are identical to what was originally contributed by Infineon. The
33  contribution of Infineon in the development of this tracing
34  technology is hereby acknowledged.
35 
36  *****************************************************************************/
37 
38 #ifndef SC_TRACE_FILE_BASE_H_INCLUDED_
39 #define SC_TRACE_FILE_BASE_H_INCLUDED_
40 
41 #include <cstdio>
42 
43 // use callback-based tracing implementation
44 #if defined( SC_ENABLE_SIMULATION_PHASE_CALLBACKS_TRACING )
45 # define SC_TRACING_PHASE_CALLBACKS_ 1
46 # include "sysc/kernel/sc_object.h"
47 #else
48 # define SC_TRACING_PHASE_CALLBACKS_ 0
49 #endif
50 
51 #include "sysc/tracing/sc_trace.h"
53 
54 namespace sc_core {
55 
56 // shared implementation of trace files
58  : public sc_trace_file
59 #if SC_TRACING_PHASE_CALLBACKS_
60  , private sc_object // to be used as callback target
61 #endif
62 {
63 public:
64  const char* filename() const
65  { return filename_.c_str(); }
66 
67  bool delta_cycles() const
68  { return trace_delta_cycles_; }
69 
70  // Also trace transitions between delta cycles if flag is true.
71  virtual void delta_cycles(bool flag);
72 
73  // set a user-define timescale unit for the trace file
74  virtual void set_time_unit( double v, sc_time_unit tu);
75 
76 protected:
77  sc_trace_file_base( const char* name, const char* extension );
78 
79  // returns true, iff initialization has been performed
80  bool initialize();
81  // ensure that file has been opened (needed for early write_comment())
82  void open_fp();
83  // perform format specific initialization
84  virtual void do_initialize() = 0;
85 
86  // returns true, if new trace objects can still be added
87  // (i.e. trace file is not yet initialized)
88  bool add_trace_check( const std::string& name ) const;
89 
90  // Flush results and close file.
91  virtual ~sc_trace_file_base();
92 
93 #if SC_TRACING_PHASE_CALLBACKS_
94 private:
95  virtual void simulation_phase_callback();
96 #endif // SC_TRACING_PHASE_CALLBACKS_
97 
98 protected:
99  FILE* fp; // pointer to the trace file
100  double timescale_unit; // in seconds
101  bool timescale_set_by_user; // = true means set by user
102 
103 private:
104  std::string filename_; // name of the file (for reporting)
105  bool initialized_; // tracing started?
106  bool trace_delta_cycles_; // also trace delta transitions?
107 
108  static bool tracing_initialized_; // shared setup of tracing implementation
109 
110 private: // disabled
111  sc_trace_file_base( const sc_trace_file_base& ) /* = delete */;
112  sc_trace_file_base& operator=( const sc_trace_file_base& ) /* = delete */;
113 
114 }; // class sc_trace_file_base
115 
116 // -----------------------------------------------------------------------
117 
118 // Convert double time to 64-bit integer
119 
120 void double_to_special_int64( double in, unsigned* high, unsigned* low );
121 
122 // obtain formatted time string
123 std::string localtime_string();
124 
125 } // namespace sc_core
126 
127 /*****************************************************************************
128 
129  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
130  changes you are making here.
131 
132  Name, Affiliation, Date:
133  Description of Modification:
134 
135  *****************************************************************************/
136 
137 #endif // SC_TRACE_FILE_BASE_H_INCLUDED_
138 // Taf!
const char * filename() const
virtual void do_initialize()=0
void double_to_special_int64(double in, unsigned *high, unsigned *low)
virtual void set_time_unit(double v, sc_time_unit tu)
bool add_trace_check(const std::string &name) const
std::string localtime_string()
sc_trace_file_base(const char *name, const char *extension)
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:51
sc_time_unit
Definition: sc_time.h:56