17 #include "tracer_base.h"
19 #include "sc_variable.h"
20 #include "traceable.h"
24 #define SC_TRACE_NS ::scc::
26 using namespace sc_dt;
28 using sc_trace_file = sc_core::sc_trace_file;
29 using sc_object = sc_core::sc_object;
31 template <
typename T>
inline auto try_trace_obj(sc_trace_file* trace_file,
const sc_object*
object, trace_types types_to_trace) ->
bool {
32 if((types_to_trace & trace_types::PORTS) == trace_types::PORTS) {
33 if(
auto const* ptr =
dynamic_cast<sc_core::sc_in<T> const*
>(
object)) {
34 if(
auto* if_ptr = ptr->get_interface(0)) {
35 SC_TRACE_NS sc_trace(trace_file, *if_ptr, object->name());
39 if(
auto const* ptr =
dynamic_cast<sc_core::sc_inout<T> const*
>(
object)) {
40 if(
auto* if_ptr = ptr->get_interface(0)) {
41 SC_TRACE_NS sc_trace(trace_file, *if_ptr, object->name());
46 if((types_to_trace & trace_types::SIGNALS) == trace_types::SIGNALS) {
47 if(
auto const* ptr =
dynamic_cast<sc_core::sc_signal_inout_if<T> const*
>(
object)) {
48 SC_TRACE_NS sc_trace(trace_file, *ptr, object->name());
56 template <
template <
size_t>
class Func>
57 static bool iterate(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
58 if(
ForLoop<SIZE - (SIZE > 128 ? 8 : 1)>::
template iterate<Func>(trace_file,
object, types_to_trace))
61 return Func<SIZE>()(trace_file, object, types_to_trace);
66 template <
template <
size_t>
class Func>
67 static bool iterate(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
68 return Func<1>()(trace_file, object, types_to_trace);
73 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
74 return try_trace_obj<sc_uint<size>>(trace_file, object, types_to_trace);
79 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
80 return try_trace_obj<sc_int<size>>(trace_file, object, types_to_trace);
85 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
86 return try_trace_obj<sc_biguint<size>>(trace_file, object, types_to_trace);
91 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
92 return try_trace_obj<sc_bigint<size>>(trace_file, object, types_to_trace);
97 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
98 return try_trace_obj<sc_bv<size>>(trace_file, object, types_to_trace);
103 bool operator()(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
104 return try_trace_obj<sc_lv<size>>(trace_file, object, types_to_trace);
108 void tracer_base::try_trace(sc_trace_file* trace_file,
const sc_object*
object,
trace_types types_to_trace) {
109 if(try_trace_obj<bool>(trace_file,
object, types_to_trace))
112 if(try_trace_obj<char>(trace_file,
object, types_to_trace))
114 if(try_trace_obj<unsigned char>(trace_file,
object, types_to_trace))
117 if(try_trace_obj<short>(trace_file,
object, types_to_trace))
119 if(try_trace_obj<unsigned short>(trace_file,
object, types_to_trace))
122 if(try_trace_obj<int>(trace_file,
object, types_to_trace))
124 if(try_trace_obj<unsigned int>(trace_file,
object, types_to_trace))
127 if(try_trace_obj<long>(trace_file,
object, types_to_trace))
129 if(try_trace_obj<unsigned long>(trace_file,
object, types_to_trace))
132 if(try_trace_obj<long long>(trace_file,
object, types_to_trace))
134 if(try_trace_obj<unsigned long long>(trace_file,
object, types_to_trace))
137 if(try_trace_obj<float>(trace_file,
object, types_to_trace))
139 if(try_trace_obj<double>(trace_file,
object, types_to_trace))
141 #if(SYSTEMC_VERSION >= 20171012)
142 if(try_trace_obj<sc_core::sc_time>(trace_file,
object, types_to_trace))
145 if(try_trace_obj<sc_bit>(trace_file,
object, types_to_trace))
147 if(try_trace_obj<sc_logic>(trace_file,
object, types_to_trace))
149 #if defined(FULL_TRACE_TYPE_LIST)
165 if(try_trace_obj<sc_uint<32>>(trace_file,
object, types_to_trace))
167 if(try_trace_obj<sc_uint<40>>(trace_file,
object, types_to_trace))
169 if(try_trace_obj<sc_uint<48>>(trace_file,
object, types_to_trace))
171 if(try_trace_obj<sc_uint<56>>(trace_file,
object, types_to_trace))
173 if(try_trace_obj<sc_uint<64>>(trace_file,
object, types_to_trace))
178 if(try_trace_obj<sc_int<32>>(trace_file,
object, types_to_trace))
180 if(try_trace_obj<sc_int<40>>(trace_file,
object, types_to_trace))
182 if(try_trace_obj<sc_int<48>>(trace_file,
object, types_to_trace))
184 if(try_trace_obj<sc_int<56>>(trace_file,
object, types_to_trace))
186 if(try_trace_obj<sc_int<64>>(trace_file,
object, types_to_trace))
189 if(try_trace_obj<sc_biguint<32>>(trace_file,
object, types_to_trace))
191 if(try_trace_obj<sc_biguint<64>>(trace_file,
object, types_to_trace))
193 if(try_trace_obj<sc_biguint<128>>(trace_file,
object, types_to_trace))
195 if(try_trace_obj<sc_biguint<256>>(trace_file,
object, types_to_trace))
197 if(try_trace_obj<sc_biguint<384>>(trace_file,
object, types_to_trace))
199 if(try_trace_obj<sc_biguint<512>>(trace_file,
object, types_to_trace))
201 if(try_trace_obj<sc_biguint<1024>>(trace_file,
object, types_to_trace))
204 if(try_trace_obj<sc_bigint<32>>(trace_file,
object, types_to_trace))
206 if(try_trace_obj<sc_bigint<64>>(trace_file,
object, types_to_trace))
208 if(try_trace_obj<sc_bigint<128>>(trace_file,
object, types_to_trace))
210 if(try_trace_obj<sc_bigint<256>>(trace_file,
object, types_to_trace))
212 if(try_trace_obj<sc_bigint<384>>(trace_file,
object, types_to_trace))
214 if(try_trace_obj<sc_bigint<512>>(trace_file,
object, types_to_trace))
216 if(try_trace_obj<sc_bigint<1024>>(trace_file,
object, types_to_trace))
221 if(try_trace_obj<sc_bv<32>>(trace_file,
object, types_to_trace))
223 if(try_trace_obj<sc_bv<40>>(trace_file,
object, types_to_trace))
225 if(try_trace_obj<sc_bv<48>>(trace_file,
object, types_to_trace))
227 if(try_trace_obj<sc_bv<56>>(trace_file,
object, types_to_trace))
229 if(try_trace_obj<sc_bv<64>>(trace_file,
object, types_to_trace))
231 if(try_trace_obj<sc_bv<128>>(trace_file,
object, types_to_trace))
233 if(try_trace_obj<sc_bv<256>>(trace_file,
object, types_to_trace))
235 if(try_trace_obj<sc_bv<384>>(trace_file,
object, types_to_trace))
237 if(try_trace_obj<sc_bv<512>>(trace_file,
object, types_to_trace))
239 if(try_trace_obj<sc_bv<1024>>(trace_file,
object, types_to_trace))
244 if(try_trace_obj<sc_lv<32>>(trace_file,
object, types_to_trace))
246 if(try_trace_obj<sc_lv<40>>(trace_file,
object, types_to_trace))
248 if(try_trace_obj<sc_lv<48>>(trace_file,
object, types_to_trace))
250 if(try_trace_obj<sc_lv<56>>(trace_file,
object, types_to_trace))
252 if(try_trace_obj<sc_lv<64>>(trace_file,
object, types_to_trace))
254 if(try_trace_obj<sc_lv<128>>(trace_file,
object, types_to_trace))
256 if(try_trace_obj<sc_lv<256>>(trace_file,
object, types_to_trace))
258 if(try_trace_obj<sc_lv<384>>(trace_file,
object, types_to_trace))
260 if(try_trace_obj<sc_lv<512>>(trace_file,
object, types_to_trace))
262 if(try_trace_obj<sc_lv<1024>>(trace_file,
object, types_to_trace))
267 std::string tracer_base::get_name() {
return sc_core::sc_gen_unique_name(
"$$$scc_tracer$$$",
true); }
269 void tracer_base::descend(
const sc_object* obj,
bool trace_all) {
272 const char* kind = obj->kind();
273 if(strcmp(kind,
"tlm_signal") == 0) {
275 }
else if(strcmp(kind,
"sc_vector") == 0) {
276 for(
auto o : obj->get_child_objects())
277 descend(o, trace_all);
278 }
else if((strcmp(kind,
"sc_module") == 0 && trace_all) ||
dynamic_cast<const traceable*
>(obj)) {
280 for(
auto o : obj->get_child_objects())
281 descend(o, trace_all);
282 }
else if(strcmp(kind,
"sc_variable") == 0) {
283 if((types_to_trace & trace_types::VARIABLES) == trace_types::VARIABLES)
285 }
else if(
const auto* tr =
dynamic_cast<const scc::traceable*
>(obj)) {
286 if(tr->is_trace_enabled())
288 for(
auto o : obj->get_child_objects())
289 descend(o, tr->is_trace_enabled());
291 try_trace(trf, obj, types_to_trace);
interface defining a traceable component
trace_types
identifies the various type to be traced