SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_trace_file_base.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_trace_file_base.h - Shared internal tracing implementation
23
24 Original Author: Philipp A. Hartmann, OFFIS, 2013-11-15
25
26 CHANGE LOG AT END OF FILE
27 *****************************************************************************/
28
29/*****************************************************************************
30
31 Acknowledgement: The tracing mechanism is based on the tracing
32 mechanism developed at Infineon (formerly Siemens HL). Though this
33 code is somewhat different, and significantly enhanced, the basics
34 are identical to what was originally contributed by Infineon. The
35 contribution of Infineon in the development of this tracing
36 technology is hereby acknowledged.
37
38 *****************************************************************************/
39
40#ifndef SC_TRACE_FILE_BASE_H_INCLUDED_
41#define SC_TRACE_FILE_BASE_H_INCLUDED_
42
43#include <cstdio>
44
48
49#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
50#pragma warning(push)
51#pragma warning(disable: 4251) // DLL import for std::string
52#endif
53
54namespace sc_core {
55
56// shared implementation of trace files
58 : public sc_trace_file
59 , private sc_stage_callback_if // to be used as callback target
60{
61public:
63
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
76protected:
77 sc_trace_file_base( const char* name, const char* extension );
78
79 // returns true, if trace file is already initialized
80 bool is_initialized() const;
81 // returns true, iff initialization has been performed in this call
82 bool initialize();
83 // ensure that file has been opened (needed for early write_comment())
84 void open_fp();
85 // perform format specific initialization
86 virtual void do_initialize() = 0;
87
88 // returns true, if new trace objects can still be added
89 // (i.e. trace file is not yet initialized)
90 bool add_trace_check( const std::string& name ) const;
91
92 // tracefile time unit < kernel unit, extra units will be placed in low part
93 bool has_low_units() const;
94
95 // number of decimal digits in low units
96 int low_units_len() const;
97
98 // get current kernel time in trace time units
100
101 // Flush results and close file.
103
105
107
108private:
109 virtual void stage_callback(const sc_stage & stage);
110
111protected:
112 FILE* fp; // pointer to the trace file
113
114 unit_type trace_unit_fs; // tracefile timescale unit in femtoseconds
115 unit_type kernel_unit_fs; // kernel timescale unit in femtoseconds
116 bool timescale_set_by_user; // = true means set by user
117
118private:
119 std::string filename_; // name of the file (for reporting)
120 bool initialized_; // tracing started?
121 bool trace_delta_cycles_; // also trace delta transitions?
122
123 static bool tracing_initialized_; // shared setup of tracing implementation
124
125private: // disabled
126 sc_trace_file_base( const sc_trace_file_base& ) /* = delete */;
127 sc_trace_file_base& operator=( const sc_trace_file_base& ) /* = delete */;
128
129}; // class sc_trace_file_base
130
131// -----------------------------------------------------------------------
132
133
134// obtain formatted time string
136
137} // namespace sc_core
138
139#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
140#pragma warning(pop)
141#endif
142
143/*****************************************************************************
144
145 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
146 changes you are making here.
147
148 Name, Affiliation, Date:
149 Description of Modification:
150
151 *****************************************************************************/
152
153#endif // SC_TRACE_FILE_BASE_H_INCLUDED_
154// Taf!
#define SC_API
Definition: sc_cmnhdr.h:148
SC_API std::string localtime_string()
sc_time_unit
Definition: sc_time.h:82
class SC_API sc_trace_file_base
Definition: sc_object.h:52
SC_TIME_DT value_type
Definition: sc_time.h:115
const char * filename() const
static std::string fs_unit_to_str(sc_trace_file_base::unit_type tu)
void timestamp_in_trace_units(unit_type &high, unit_type &low) const
sc_time::value_type unit_type
sc_trace_file_base(const char *name, const char *extension)
static sc_time::value_type unit_to_fs(sc_time_unit tu)
virtual void set_time_unit(double v, sc_time_unit tu)
virtual void delta_cycles(bool flag)
virtual void do_initialize()=0
bool add_trace_check(const std::string &name) const