23 #include "tracer_base.h"
25 #include "sc_variable.h"
26 #include "traceable.h"
30 #define SC_TRACE_NS ::scc::
32 using namespace sc_dt;
34 using sc_trace_file = sc_core::sc_trace_file;
35 using sc_object = sc_core::sc_object;
37 template <
typename T>
inline auto try_trace_obj(sc_trace_file* trace_file,
const sc_object*
object, trace_types types_to_trace) ->
bool {
38 if((types_to_trace & trace_types::PORTS) == trace_types::PORTS) {
39 if(
auto const* ptr =
dynamic_cast<sc_core::sc_in<T> const*
>(
object)) {
40 SC_TRACE_NS sc_trace(trace_file, *ptr->get_interface(0), object->name());
43 if(
auto const* ptr =
dynamic_cast<sc_core::sc_inout<T> const*
>(
object)) {
44 SC_TRACE_NS sc_trace(trace_file, *ptr->get_interface(0), object->name());
48 if((types_to_trace & trace_types::SIGNALS) == trace_types::SIGNALS) {
49 if(
auto const* ptr =
dynamic_cast<sc_core::sc_signal_inout_if<T> const*
>(
object)) {
50 SC_TRACE_NS sc_trace(trace_file, *ptr, object->name());
58 template <
template <
size_t>
class Func>
59 static bool iterate(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
60 if(
ForLoop<SIZE - (SIZE > 128 ? 8 : 1)>::
template iterate<Func>(trace_file,
object, types_to_trace))
63 return Func<SIZE>()(trace_file, object, types_to_trace);
68 template <
template <
size_t>
class Func>
69 static bool iterate(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
70 return Func<1>()(trace_file, object, types_to_trace);
75 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
76 return try_trace_obj<sc_uint<size>>(trace_file, object, types_to_trace);
81 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
82 return try_trace_obj<sc_int<size>>(trace_file, object, types_to_trace);
87 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
88 return try_trace_obj<sc_biguint<size>>(trace_file, object, types_to_trace);
93 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
94 return try_trace_obj<sc_bigint<size>>(trace_file, object, types_to_trace);
99 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
100 return try_trace_obj<sc_bv<size>>(trace_file, object, types_to_trace);
105 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
106 return try_trace_obj<sc_lv<size>>(trace_file, object, types_to_trace);
110 void tracer_base::try_trace(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
111 if(try_trace_obj<bool>(trace_file,
object, types_to_trace))
114 if(try_trace_obj<char>(trace_file,
object, types_to_trace))
116 if(try_trace_obj<unsigned char>(trace_file,
object, types_to_trace))
119 if(try_trace_obj<short>(trace_file,
object, types_to_trace))
121 if(try_trace_obj<unsigned short>(trace_file,
object, types_to_trace))
124 if(try_trace_obj<int>(trace_file,
object, types_to_trace))
126 if(try_trace_obj<unsigned int>(trace_file,
object, types_to_trace))
129 if(try_trace_obj<long>(trace_file,
object, types_to_trace))
131 if(try_trace_obj<unsigned long>(trace_file,
object, types_to_trace))
134 if(try_trace_obj<long long>(trace_file,
object, types_to_trace))
136 if(try_trace_obj<unsigned long long>(trace_file,
object, types_to_trace))
139 if(try_trace_obj<float>(trace_file,
object, types_to_trace))
141 if(try_trace_obj<double>(trace_file,
object, types_to_trace))
143 #if(SYSTEMC_VERSION >= 20171012)
144 if(try_trace_obj<sc_core::sc_time>(trace_file,
object, types_to_trace))
147 if(try_trace_obj<sc_bit>(trace_file,
object, types_to_trace))
149 if(try_trace_obj<sc_logic>(trace_file,
object, types_to_trace))
151 #if defined(FULL_TRACE_TYPE_LIST)
167 if(try_trace_obj<sc_uint<32>>(trace_file,
object, types_to_trace))
169 if(try_trace_obj<sc_uint<40>>(trace_file,
object, types_to_trace))
171 if(try_trace_obj<sc_uint<48>>(trace_file,
object, types_to_trace))
173 if(try_trace_obj<sc_uint<56>>(trace_file,
object, types_to_trace))
175 if(try_trace_obj<sc_uint<64>>(trace_file,
object, types_to_trace))
180 if(try_trace_obj<sc_int<32>>(trace_file,
object, types_to_trace))
182 if(try_trace_obj<sc_int<40>>(trace_file,
object, types_to_trace))
184 if(try_trace_obj<sc_int<48>>(trace_file,
object, types_to_trace))
186 if(try_trace_obj<sc_int<56>>(trace_file,
object, types_to_trace))
188 if(try_trace_obj<sc_int<64>>(trace_file,
object, types_to_trace))
191 if(try_trace_obj<sc_biguint<32>>(trace_file,
object, types_to_trace))
193 if(try_trace_obj<sc_biguint<64>>(trace_file,
object, types_to_trace))
195 if(try_trace_obj<sc_biguint<128>>(trace_file,
object, types_to_trace))
197 if(try_trace_obj<sc_biguint<256>>(trace_file,
object, types_to_trace))
199 if(try_trace_obj<sc_biguint<384>>(trace_file,
object, types_to_trace))
201 if(try_trace_obj<sc_biguint<512>>(trace_file,
object, types_to_trace))
203 if(try_trace_obj<sc_biguint<1024>>(trace_file,
object, types_to_trace))
206 if(try_trace_obj<sc_bigint<32>>(trace_file,
object, types_to_trace))
208 if(try_trace_obj<sc_bigint<64>>(trace_file,
object, types_to_trace))
210 if(try_trace_obj<sc_bigint<128>>(trace_file,
object, types_to_trace))
212 if(try_trace_obj<sc_bigint<256>>(trace_file,
object, types_to_trace))
214 if(try_trace_obj<sc_bigint<384>>(trace_file,
object, types_to_trace))
216 if(try_trace_obj<sc_bigint<512>>(trace_file,
object, types_to_trace))
218 if(try_trace_obj<sc_bigint<1024>>(trace_file,
object, types_to_trace))
223 if(try_trace_obj<sc_bv<32>>(trace_file,
object, types_to_trace))
225 if(try_trace_obj<sc_bv<40>>(trace_file,
object, types_to_trace))
227 if(try_trace_obj<sc_bv<48>>(trace_file,
object, types_to_trace))
229 if(try_trace_obj<sc_bv<56>>(trace_file,
object, types_to_trace))
231 if(try_trace_obj<sc_bv<64>>(trace_file,
object, types_to_trace))
233 if(try_trace_obj<sc_bv<128>>(trace_file,
object, types_to_trace))
235 if(try_trace_obj<sc_bv<256>>(trace_file,
object, types_to_trace))
237 if(try_trace_obj<sc_bv<384>>(trace_file,
object, types_to_trace))
239 if(try_trace_obj<sc_bv<512>>(trace_file,
object, types_to_trace))
241 if(try_trace_obj<sc_bv<1024>>(trace_file,
object, types_to_trace))
246 if(try_trace_obj<sc_lv<32>>(trace_file,
object, types_to_trace))
248 if(try_trace_obj<sc_lv<40>>(trace_file,
object, types_to_trace))
250 if(try_trace_obj<sc_lv<48>>(trace_file,
object, types_to_trace))
252 if(try_trace_obj<sc_lv<56>>(trace_file,
object, types_to_trace))
254 if(try_trace_obj<sc_lv<64>>(trace_file,
object, types_to_trace))
256 if(try_trace_obj<sc_lv<128>>(trace_file,
object, types_to_trace))
258 if(try_trace_obj<sc_lv<256>>(trace_file,
object, types_to_trace))
260 if(try_trace_obj<sc_lv<384>>(trace_file,
object, types_to_trace))
262 if(try_trace_obj<sc_lv<512>>(trace_file,
object, types_to_trace))
264 if(try_trace_obj<sc_lv<1024>>(trace_file,
object, types_to_trace))
269 std::string tracer_base::get_name() {
return sc_core::sc_gen_unique_name(
"$$$scc_tracer$$$",
true); }
271 void tracer_base::descend(
const sc_object* obj,
bool trace_all) {
274 const char* kind = obj->kind();
275 if(strcmp(kind,
"tlm_signal") == 0) {
277 }
else if(strcmp(kind,
"sc_vector") == 0) {
278 for(
auto o : obj->get_child_objects())
279 descend(o, trace_all);
280 }
else if((strcmp(kind,
"sc_module") == 0 && trace_all) ||
dynamic_cast<const traceable*
>(obj)) {
282 for(
auto o : obj->get_child_objects())
283 descend(o, trace_all);
284 }
else if(strcmp(kind,
"sc_variable") == 0) {
285 if((types_to_trace & trace_types::VARIABLES) == trace_types::VARIABLES)
287 }
else if(
const auto* tr =
dynamic_cast<const scc::traceable*
>(obj)) {
288 if(tr->is_trace_enabled())
290 for(
auto o : obj->get_child_objects())
291 descend(o, tr->is_trace_enabled());
293 try_trace(trf, obj, types_to_trace);
interface defining a traceable component
trace_types
identifies the various type to be traced