17#include "tracer_base.h"
21#include <sysc/communication/sc_signal_ifs.h>
24#define SC_TRACE_NS ::scc::
26using namespace sc_core;
30using sc_trace_file = sc_core::sc_trace_file;
31using sc_object = sc_core::sc_object;
33template <
typename T>
inline auto try_trace_obj(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) ->
bool {
35 if(
auto const* ptr =
dynamic_cast<sc_core::sc_port_b<sc_core::sc_signal_in_if<T>
> const*>(
object)) {
36 if(
auto* if_ptr = ptr->get_interface(0)) {
37 SC_TRACE_NS sc_trace(trace_file, *if_ptr, object->name());
41 if(
auto const* ptr =
dynamic_cast<sc_core::sc_port_b<sc_core::sc_signal_inout_if<T>
> const*>(
object)) {
42 if(
auto* if_ptr = ptr->get_interface(0)) {
43 SC_TRACE_NS sc_trace(trace_file, *if_ptr, object->name());
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);
110void 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)
152 if(ForLoop<64>::iterate<sc_uint_tester>(trace_file,
object, types_to_trace))
154 if(ForLoop<64>::iterate<sc_int_tester>(trace_file,
object, types_to_trace))
156 if(ForLoop<1024>::iterate<sc_biguint_tester>(trace_file,
object, types_to_trace))
158 if(ForLoop<1024>::iterate<sc_bigint_tester>(trace_file,
object, types_to_trace))
160 if(ForLoop<1024>::iterate<sc_bv_tester>(trace_file,
object, types_to_trace))
162 if(ForLoop<1024>::iterate<sc_lv_tester>(trace_file,
object, types_to_trace))
165 if(ForLoop<31>::iterate<sc_uint_tester>(trace_file,
object, types_to_trace))
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))
178 if(ForLoop<31>::iterate<sc_int_tester>(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))
221 if(ForLoop<31>::iterate<sc_bv_tester>(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))
244 if(ForLoop<31>::iterate<sc_lv_tester>(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))
269std::string tracer_base::get_name() {
return sc_core::sc_gen_unique_name(
"$$$scc_tracer$$$",
true); }
271void 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) {
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);
298tracer_base* find_tracer_base(sc_core::sc_object* obj) {
301 for(
auto* o : obj->get_child_objects()) {
302 if(
auto p = find_tracer_base(o))
309static char const*
const default_trace_enable_name =
"scc_tracer.default_trace_enable";
311: sc_core::sc_module(nm)
316 default_trace_enable = scc::make_unique<cci::cci_param<bool>>(
317 default_trace_enable_name, false,
"the default for tracing if no attribute is configured", cci::CCI_ABSOLUTE_NAME);
318 default_trace_enable_handle = cci_broker.get_param_handle(default_trace_enable_name);
322bool tracer_base::get_default_trace_enable() {
331void tracer_base::set_default_trace_enable(
bool v) {
trace_types
identifies the various type to be traced
base class for automatic tracer
cci::cci_param_handle default_trace_enable_handle
tracer_base(const sc_core::sc_module_name &nm)
named constructor
cci::cci_broker_handle cci_broker