scc  2022.4.0
SystemC components library
vcd_push_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_PUSH_TRACE_H
19 #define SCC_VCD_PUSH_TRACE_H
20 
21 #include <scc/observer.h>
22 #include <sysc/tracing/sc_trace.h>
23 #include <sysc/kernel/sc_ver.h>
24 #include <deque>
25 #include <vector>
26 #include <functional>
27 
28 namespace sc_core {
29 class sc_time;
30 }
36 namespace scc {
37 namespace trace {
38 class vcd_trace;
39 }
40 struct vcd_push_trace_file : public sc_core::sc_trace_file, public observer {
41 
42  vcd_push_trace_file(const char *name, std::function<bool()>& enable);
43 
44  virtual ~vcd_push_trace_file();
45 
46 protected:
47 #define DECL_TRACE_METHOD_A(tp) void trace(const tp& object, const std::string& name) override;
48 #define DECL_TRACE_METHOD_B(tp) void trace(const tp& object, const std::string& name, int width) override;
49 #if (SYSTEMC_VERSION >= 20171012)
50  DECL_TRACE_METHOD_A( sc_core::sc_event )
51  DECL_TRACE_METHOD_A( sc_core::sc_time )
52 #endif
53  DECL_TRACE_METHOD_A( bool )
54  DECL_TRACE_METHOD_A( sc_dt::sc_bit )
55  DECL_TRACE_METHOD_A( sc_dt::sc_logic )
56  DECL_TRACE_METHOD_B( unsigned char )
57  DECL_TRACE_METHOD_B( unsigned short )
58  DECL_TRACE_METHOD_B( unsigned int )
59  DECL_TRACE_METHOD_B( unsigned long )
60 #ifdef SYSTEMC_64BIT_PATCHES
61  DECL_TRACE_METHOD_B( unsigned long long)
62 #endif
63  DECL_TRACE_METHOD_B( char )
64  DECL_TRACE_METHOD_B( short )
65  DECL_TRACE_METHOD_B( int )
66  DECL_TRACE_METHOD_B( long )
67  DECL_TRACE_METHOD_B( sc_dt::int64 )
68  DECL_TRACE_METHOD_B( sc_dt::uint64 )
69  DECL_TRACE_METHOD_A( float )
70  DECL_TRACE_METHOD_A( double )
71  DECL_TRACE_METHOD_A( sc_dt::sc_int_base )
72  DECL_TRACE_METHOD_A( sc_dt::sc_uint_base )
73  DECL_TRACE_METHOD_A( sc_dt::sc_signed )
74  DECL_TRACE_METHOD_A( sc_dt::sc_unsigned )
75  DECL_TRACE_METHOD_A( sc_dt::sc_fxval )
76  DECL_TRACE_METHOD_A( sc_dt::sc_fxval_fast )
77  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum )
78  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum_fast )
79  DECL_TRACE_METHOD_A( sc_dt::sc_bv_base )
80  DECL_TRACE_METHOD_A( sc_dt::sc_lv_base )
81 #undef DECL_TRACE_METHOD_A
82 #undef DECL_TRACE_METHOD_B
83 
84  void trace( const unsigned int& object,
85  const std::string& name,
86  const char** enum_literals ) override;
87 
88 #define DECL_REGISTER_METHOD_A(tp) observer::notification_handle* observe(tp const& o, std::string const& nm) override;
89 #if (SYSTEMC_VERSION >= 20171012)
90  DECL_REGISTER_METHOD_A( sc_core::sc_event )
91  DECL_REGISTER_METHOD_A( sc_core::sc_time )
92 #endif
93  DECL_REGISTER_METHOD_A( bool )
94  DECL_REGISTER_METHOD_A( sc_dt::sc_bit )
95  DECL_REGISTER_METHOD_A( sc_dt::sc_logic )
96 
97  DECL_REGISTER_METHOD_A( unsigned char )
98  DECL_REGISTER_METHOD_A( unsigned short )
99  DECL_REGISTER_METHOD_A( unsigned int )
100  DECL_REGISTER_METHOD_A( unsigned long )
101  DECL_REGISTER_METHOD_A( char )
102  DECL_REGISTER_METHOD_A( short )
103  DECL_REGISTER_METHOD_A( int )
104  DECL_REGISTER_METHOD_A( long )
105  DECL_REGISTER_METHOD_A( sc_dt::int64 )
106  DECL_REGISTER_METHOD_A( sc_dt::uint64 )
107 
108  DECL_REGISTER_METHOD_A( float )
109  DECL_REGISTER_METHOD_A( double )
110  DECL_REGISTER_METHOD_A( sc_dt::sc_int_base )
111  DECL_REGISTER_METHOD_A( sc_dt::sc_uint_base )
112  DECL_REGISTER_METHOD_A( sc_dt::sc_signed )
113  DECL_REGISTER_METHOD_A( sc_dt::sc_unsigned )
114 
115  DECL_REGISTER_METHOD_A( sc_dt::sc_fxval )
116  DECL_REGISTER_METHOD_A( sc_dt::sc_fxval_fast )
117  DECL_REGISTER_METHOD_A( sc_dt::sc_fxnum )
118  DECL_REGISTER_METHOD_A( sc_dt::sc_fxnum_fast )
119 
120  DECL_REGISTER_METHOD_A( sc_dt::sc_bv_base )
121  DECL_REGISTER_METHOD_A( sc_dt::sc_lv_base )
122 #undef DECL_REGISTER_METHOD_A
123 
124  // Output a comment to the trace file
125  void write_comment(const std::string& comment) override;
126 
127  // Write trace info for cycle.
128  void cycle(bool delta_cycle) override;
129 
130  void set_time_unit( double v, sc_core::sc_time_unit tu ) override;
131 #ifdef NCSC
132  void set_time_unit( int exponent10_seconds ) override;
133 #endif
134 
135 private:
136 #if WITH_SC_TRACING_PHASE_CALLBACKS
137  // avoid hidden overload warnings
138  virtual void trace( sc_trace_file* ) const;
139 #endif
140 
141  void init();
142  std::string prune_name(std::string const& name);
143  std::string obtain_name();
144  std::function<bool()> check_enabled;
145 
146  FILE* vcd_out{nullptr};
147  struct trace_entry: public observer::notification_handle {
148  bool (*compare_and_update)(trace::vcd_trace*);
149  trace::vcd_trace* trc;
150  vcd_push_trace_file* that;
151  bool notify() override;
152  trace_entry(vcd_push_trace_file* owner, bool (*compare_and_update)(trace::vcd_trace*), trace::vcd_trace* trc)
153  :compare_and_update{compare_and_update}, trc{trc}, that{owner}{}
154  virtual ~trace_entry(){}
155  };
156  std::deque<trace_entry> all_traces;
157  std::vector<trace_entry*> pull_traces;
158  std::vector<trace::vcd_trace*> changed_traces;
159  std::vector<trace::vcd_trace*> triggered_traces;
160  uint64_t last_emitted_ts{std::numeric_limits<uint64_t>::max()};
161  unsigned vcd_name_index{0};
162  std::string name;
163 };
164 
165 } // namespace scc // end of scc-sysc
167 
168 #endif // SCC_VCD_PUSH_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