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