scc  2022.4.0
SystemC components library
vcd_pull_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 #ifndef SCC_VCD_PULL_TRACE_H
18 #define SCC_VCD_PULL_TRACE_H
19 
20 #include <sysc/tracing/sc_trace.h>
21 #include <sysc/kernel/sc_ver.h>
22 #include <vector>
23 #include <functional>
24 
25 namespace sc_core {
26 class sc_time;
27 }
33 namespace scc {
34 namespace trace {
35 class vcd_trace;
36 }
37 
38 struct vcd_pull_trace_file : public sc_core::sc_trace_file {
39 
40  vcd_pull_trace_file(const char *name, std::function<bool()>& enable);
41 
42  virtual ~vcd_pull_trace_file();
43 
44 protected:
45 #define DECL_TRACE_METHOD_A(tp) void trace(const tp& object, const std::string& name) override;
46 #define DECL_TRACE_METHOD_B(tp) void trace(const tp& object, const std::string& name, int width) override;
47 
48 #if (SYSTEMC_VERSION >= 20171012)
49  DECL_TRACE_METHOD_A( sc_core::sc_event )
50  DECL_TRACE_METHOD_A( sc_core::sc_time )
51 #endif
52  DECL_TRACE_METHOD_A( bool )
53  DECL_TRACE_METHOD_A( sc_dt::sc_bit )
54  DECL_TRACE_METHOD_A( sc_dt::sc_logic )
55 
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 
70  DECL_TRACE_METHOD_A( float )
71  DECL_TRACE_METHOD_A( double )
72  DECL_TRACE_METHOD_A( sc_dt::sc_int_base )
73  DECL_TRACE_METHOD_A( sc_dt::sc_uint_base )
74  DECL_TRACE_METHOD_A( sc_dt::sc_signed )
75  DECL_TRACE_METHOD_A( sc_dt::sc_unsigned )
76 
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 
82  DECL_TRACE_METHOD_A( sc_dt::sc_bv_base )
83  DECL_TRACE_METHOD_A( sc_dt::sc_lv_base )
84 #undef DECL_TRACE_METHOD_A
85 #undef DECL_TRACE_METHOD_B
86 
87  void trace( const unsigned int& object,
88  const std::string& name,
89  const char** enum_literals ) override;
90 
91  // Output a comment to the trace file
92  void write_comment(const std::string& comment) override;
93 
94  // Write trace info for cycle.
95  void cycle(bool delta_cycle) override;
96 
97  void set_time_unit( double v, sc_core::sc_time_unit tu ) override;
98 #ifdef NCSC
99  void set_time_unit( int exponent10_seconds ) override;
100 #endif
101 
102 private:
103 #if WITH_SC_TRACING_PHASE_CALLBACKS
104  // avoid hidden overload warnings
105  virtual void trace( sc_trace_file* ) const;
106 #endif
107 
108  void init();
109  std::string prune_name(std::string const& name);
110  std::string obtain_name();
111  std::function<bool()> check_enabled;
112 
113  FILE* vcd_out{nullptr};
114  struct trace_entry {
115  bool (*compare_and_update)(trace::vcd_trace*);
116  trace::vcd_trace* trc;
117  trace_entry(bool (*compare_and_update)(trace::vcd_trace*), trace::vcd_trace* trc):compare_and_update{compare_and_update}, trc{trc}{}
118  };
119  std::vector<trace_entry> all_traces, active_traces;
120  std::vector<trace::vcd_trace*> changed_traces;;
121  bool initialized{false};
122  unsigned vcd_name_index{0};
123  std::string name;
124 };
125 
126 } // namespace sc_core // end of scc-sysc
128 
129 #endif // SCC_SC_VCD_TRACE_H
130 // Taf!
SCC SystemC utilities.