scc  2022.4.0
SystemC components library
vcd_mt_trace.hh
1 /*******************************************************************************
2  * Copyright 2021 MINRES Technologies GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 
18 #ifndef SCC_VCD_MT_TRACE_H
19 #define SCC_VCD_MT_TRACE_H
20 
21 #include <scc/observer.h>
22 #include <sysc/tracing/sc_trace.h>
23 #include <sysc/kernel/sc_ver.h>
24 #include <util/thread_pool.h>
25 #include <deque>
26 #include <vector>
27 #include <functional>
28 
29 namespace sc_core {
30 class sc_time;
31 }
37 namespace scc {
38 namespace trace {
39 class vcd_trace;
40 class gz_writer;
41 }
42 struct vcd_mt_trace_file : public sc_core::sc_trace_file, public observer {
43 
44  vcd_mt_trace_file(const char *name, std::function<bool()>& enable);
45 
46  virtual ~vcd_mt_trace_file();
47 
48 protected:
49 #define DECL_TRACE_METHOD_A(tp) void trace(const tp& object, const std::string& name) override;
50 #define DECL_TRACE_METHOD_B(tp) void trace(const tp& object, const std::string& name, int width) override;
51 #if (SYSTEMC_VERSION >= 20171012)
52  DECL_TRACE_METHOD_A( sc_core::sc_event )
53  DECL_TRACE_METHOD_A( sc_core::sc_time )
54 #endif
55  DECL_TRACE_METHOD_A( bool )
56  DECL_TRACE_METHOD_A( sc_dt::sc_bit )
57  DECL_TRACE_METHOD_A( sc_dt::sc_logic )
58  DECL_TRACE_METHOD_B( unsigned char )
59  DECL_TRACE_METHOD_B( unsigned short )
60  DECL_TRACE_METHOD_B( unsigned int )
61  DECL_TRACE_METHOD_B( unsigned long )
62 #ifdef SYSTEMC_64BIT_PATCHES
63  DECL_TRACE_METHOD_B( unsigned long long)
64 #endif
65  DECL_TRACE_METHOD_B( char )
66  DECL_TRACE_METHOD_B( short )
67  DECL_TRACE_METHOD_B( int )
68  DECL_TRACE_METHOD_B( long )
69  DECL_TRACE_METHOD_B( sc_dt::int64 )
70  DECL_TRACE_METHOD_B( sc_dt::uint64 )
71  DECL_TRACE_METHOD_A( float )
72  DECL_TRACE_METHOD_A( double )
73  DECL_TRACE_METHOD_A( sc_dt::sc_int_base )
74  DECL_TRACE_METHOD_A( sc_dt::sc_uint_base )
75  DECL_TRACE_METHOD_A( sc_dt::sc_signed )
76  DECL_TRACE_METHOD_A( sc_dt::sc_unsigned )
77  DECL_TRACE_METHOD_A( sc_dt::sc_fxval )
78  DECL_TRACE_METHOD_A( sc_dt::sc_fxval_fast )
79  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum )
80  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum_fast )
81  DECL_TRACE_METHOD_A( sc_dt::sc_bv_base )
82  DECL_TRACE_METHOD_A( sc_dt::sc_lv_base )
83 #undef DECL_TRACE_METHOD_A
84 #undef DECL_TRACE_METHOD_B
85 
86  void trace( const unsigned int& object,
87  const std::string& name,
88  const char** enum_literals ) override;
89 
90 #define DECL_REGISTER_METHOD_A(tp) observer::notification_handle* observe(tp const& o, std::string const& nm) override;
91 #if (SYSTEMC_VERSION >= 20171012)
92  DECL_REGISTER_METHOD_A( sc_core::sc_event )
93  DECL_REGISTER_METHOD_A( sc_core::sc_time )
94 #endif
95  DECL_REGISTER_METHOD_A( bool )
96  DECL_REGISTER_METHOD_A( sc_dt::sc_bit )
97  DECL_REGISTER_METHOD_A( sc_dt::sc_logic )
98 
99  DECL_REGISTER_METHOD_A( unsigned char )
100  DECL_REGISTER_METHOD_A( unsigned short )
101  DECL_REGISTER_METHOD_A( unsigned int )
102  DECL_REGISTER_METHOD_A( unsigned long )
103  DECL_REGISTER_METHOD_A( char )
104  DECL_REGISTER_METHOD_A( short )
105  DECL_REGISTER_METHOD_A( int )
106  DECL_REGISTER_METHOD_A( long )
107  DECL_REGISTER_METHOD_A( sc_dt::int64 )
108  DECL_REGISTER_METHOD_A( sc_dt::uint64 )
109 
110  DECL_REGISTER_METHOD_A( float )
111  DECL_REGISTER_METHOD_A( double )
112  DECL_REGISTER_METHOD_A( sc_dt::sc_int_base )
113  DECL_REGISTER_METHOD_A( sc_dt::sc_uint_base )
114  DECL_REGISTER_METHOD_A( sc_dt::sc_signed )
115  DECL_REGISTER_METHOD_A( sc_dt::sc_unsigned )
116 
117  DECL_REGISTER_METHOD_A( sc_dt::sc_fxval )
118  DECL_REGISTER_METHOD_A( sc_dt::sc_fxval_fast )
119  DECL_REGISTER_METHOD_A( sc_dt::sc_fxnum )
120  DECL_REGISTER_METHOD_A( sc_dt::sc_fxnum_fast )
121 
122  DECL_REGISTER_METHOD_A( sc_dt::sc_bv_base )
123  DECL_REGISTER_METHOD_A( sc_dt::sc_lv_base )
124 #undef DECL_REGISTER_METHOD_A
125 
126  // Output a comment to the trace file
127  void write_comment(const std::string& comment) override;
128 
129  // Write trace info for cycle.
130  void cycle(bool delta_cycle) override;
131 
132  void set_time_unit( double v, sc_core::sc_time_unit tu ) override;
133 #ifdef NCSC
134  void set_time_unit( int exponent10_seconds ) override;
135 #endif
136 
137 private:
138 #if WITH_SC_TRACING_PHASE_CALLBACKS
139  // avoid hidden overload warnings
140  virtual void trace( sc_trace_file* ) const;
141 #endif
142 
143  void init();
144  std::string prune_name(std::string const& name);
145  std::string obtain_name();
146  std::function<bool()> check_enabled;
147  std::unique_ptr<trace::gz_writer> vcd_out{nullptr};
148  struct trace_entry: public observer::notification_handle {
149  bool (*compare_and_update)(trace::vcd_trace*);
150  trace::vcd_trace* trc;
151  vcd_mt_trace_file* that;
152  bool notify() override;
153  trace_entry(vcd_mt_trace_file* owner, bool (*compare_and_update)(trace::vcd_trace*), trace::vcd_trace* trc)
154  :compare_and_update{compare_and_update}, trc{trc}, that{owner}{}
155  virtual ~trace_entry(){}
156  };
157  std::deque<trace_entry> all_traces;
158  std::vector<trace_entry> active_traces;
159  std::vector<trace::vcd_trace*> changed_traces;
160  std::vector<trace::vcd_trace*> triggered_traces;
161  std::vector<trace::vcd_trace*> record_traces;
162  bool initialized{false};
163  unsigned vcd_name_index{0};
164  std::string name;
165  std::future<bool> res;
166 };
167 
168 } // namespace scc // end of scc-sysc
170 #endif // SCC_VCD_MT_TRACE_H
SCC SystemC utilities.
A handle to be used be the observed object to notify the observer about a change.
Definition: observer.h:57
The interface defining an observer.
Definition: observer.h:53