scc 2025.09
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 <functional>
21#include <sysc/kernel/sc_ver.h>
22#include <sysc/tracing/sc_trace.h>
23#include <vector>
24
25namespace sc_core {
26class sc_time;
27}
33namespace scc {
34namespace trace {
35class vcd_trace;
36}
37
38struct 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
44protected:
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) || defined(NCSC)
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, const std::string& name, const char** enum_literals) override;
88
89 // Output a comment to the trace file
90 void write_comment(const std::string& comment) override;
91
92 // Write trace info for cycle.
93 void cycle(bool delta_cycle) override;
94
95 void set_time_unit(double v, sc_core::sc_time_unit tu) override;
96
97private:
98#if WITH_SC_TRACING_PHASE_CALLBACKS
99 // avoid hidden overload warnings
100 virtual void trace(sc_trace_file*) const;
101#endif
102
103 void init();
104 std::string prune_name(std::string const& name);
105 std::string obtain_name();
106 std::function<bool()> check_enabled;
107
108 FILE* vcd_out{nullptr};
109 struct trace_entry {
110 bool (*compare_and_update)(trace::vcd_trace*);
111 trace::vcd_trace* trc;
112 trace_entry(bool (*compare_and_update)(trace::vcd_trace*), trace::vcd_trace* trc)
113 : compare_and_update{compare_and_update}
114 , trc{trc} {}
115 };
116 std::vector<trace_entry> all_traces, active_traces;
117 std::vector<trace::vcd_trace*> changed_traces;
118 ;
119 bool initialized{false};
120 unsigned vcd_name_index{0};
121 std::string name;
122};
123
124} // namespace scc // end of scc-sysc
126
127#endif // SCC_SC_VCD_TRACE_H
128// Taf!
SCC SystemC tracing utilities.
Definition fst_trace.cpp:33
SCC TLM utilities.