A SystemC productivity library for virtual platform development utilizing SCV and TLM2.0 https://www.minres.com/#opensource
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
8.8 KiB

  1. /*******************************************************************************
  2. * Copyright 2017, 2018 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. * tracer.cpp
  18. *
  19. * Created on: Nov 9, 2016
  20. * Author: developer
  21. */
  22. #include <scc/tracer_base.h>
  23. #include <scc/traceable.h>
  24. #include <scc/sc_variable.h>
  25. #include <cstring>
  26. #include <systemc>
  27. using namespace sc_core;
  28. using namespace sc_dt;
  29. using namespace scc;
  30. template <typename T, typename std::enable_if<std::is_class<T>::value, int>::type = 0>
  31. inline bool trace_helper(sc_trace_file* trace_file, const sc_object* object) {
  32. if(auto* ptr = dynamic_cast<const T*>(object)) {
  33. sc_core::sc_trace(trace_file, *ptr, object->name());
  34. return true;
  35. }
  36. return false;
  37. }
  38. template <typename T, typename std::enable_if<!std::is_class<T>::value, unsigned>::type = 0>
  39. inline bool trace_helper(sc_trace_file*, const sc_object*) {
  40. return false;
  41. }
  42. template <typename T> inline bool try_trace_obj(sc_trace_file* trace_file, const sc_object* object, trace_types types_to_trace) {
  43. if((types_to_trace & trace_types::PORTS) == trace_types::PORTS) {
  44. if(trace_helper<sc_core::sc_in<T>>(trace_file, object))
  45. return true;
  46. if(trace_helper<sc_core::sc_out<T>>(trace_file, object))
  47. return true;
  48. }
  49. if((types_to_trace & trace_types::SIGNALS) == trace_types::SIGNALS) {
  50. if(trace_helper<sc_core::sc_signal<T, SC_ONE_WRITER>>(trace_file, object))
  51. return true;
  52. if(trace_helper<sc_core::sc_signal<T, SC_MANY_WRITERS>>(trace_file, object))
  53. return true;
  54. if(trace_helper<sc_core::sc_signal<T, SC_UNCHECKED_WRITERS>>(trace_file, object))
  55. return true;
  56. }
  57. if((types_to_trace & trace_types::OBJECTS) == trace_types::OBJECTS)
  58. if(trace_helper<T>(trace_file, object))
  59. return true;
  60. return false;
  61. }
  62. void tracer_base::try_trace(sc_trace_file* trace_file, const sc_object* object, trace_types types_to_trace) {
  63. if(try_trace_obj<bool>(trace_file, object, types_to_trace))
  64. return;
  65. if(try_trace_obj<char>(trace_file, object, types_to_trace))
  66. return;
  67. if(try_trace_obj<unsigned char>(trace_file, object, types_to_trace))
  68. return;
  69. if(try_trace_obj<short>(trace_file, object, types_to_trace))
  70. return;
  71. if(try_trace_obj<unsigned short>(trace_file, object, types_to_trace))
  72. return;
  73. if(try_trace_obj<int>(trace_file, object, types_to_trace))
  74. return;
  75. if(try_trace_obj<unsigned int>(trace_file, object, types_to_trace))
  76. return;
  77. if(try_trace_obj<long>(trace_file, object, types_to_trace))
  78. return;
  79. if(try_trace_obj<unsigned long>(trace_file, object, types_to_trace))
  80. return;
  81. if(try_trace_obj<long long>(trace_file, object, types_to_trace))
  82. return;
  83. if(try_trace_obj<unsigned long long>(trace_file, object, types_to_trace))
  84. return;
  85. if(try_trace_obj<float>(trace_file, object, types_to_trace))
  86. return;
  87. if(try_trace_obj<double>(trace_file, object, types_to_trace))
  88. return;
  89. #if(SYSTEMC_VERSION >= 20171012)
  90. if(try_trace_obj<sc_time>(trace_file, object, types_to_trace))
  91. return;
  92. #endif
  93. if(try_trace_obj<sc_bit>(trace_file, object, types_to_trace))
  94. return;
  95. if(try_trace_obj<sc_logic>(trace_file, object, types_to_trace))
  96. return;
  97. if(try_trace_obj<sc_uint<1>>(trace_file, object, types_to_trace))
  98. return;
  99. if(try_trace_obj<sc_uint<2>>(trace_file, object, types_to_trace))
  100. return;
  101. if(try_trace_obj<sc_uint<3>>(trace_file, object, types_to_trace))
  102. return;
  103. if(try_trace_obj<sc_uint<4>>(trace_file, object, types_to_trace))
  104. return;
  105. if(try_trace_obj<sc_uint<8>>(trace_file, object, types_to_trace))
  106. return;
  107. if(try_trace_obj<sc_uint<16>>(trace_file, object, types_to_trace))
  108. return;
  109. if(try_trace_obj<sc_uint<32>>(trace_file, object, types_to_trace))
  110. return;
  111. if(try_trace_obj<sc_uint<64>>(trace_file, object, types_to_trace))
  112. return;
  113. if(try_trace_obj<sc_int<1>>(trace_file, object, types_to_trace))
  114. return;
  115. if(try_trace_obj<sc_int<2>>(trace_file, object, types_to_trace))
  116. return;
  117. if(try_trace_obj<sc_int<3>>(trace_file, object, types_to_trace))
  118. return;
  119. if(try_trace_obj<sc_int<4>>(trace_file, object, types_to_trace))
  120. return;
  121. if(try_trace_obj<sc_int<8>>(trace_file, object, types_to_trace))
  122. return;
  123. if(try_trace_obj<sc_int<16>>(trace_file, object, types_to_trace))
  124. return;
  125. if(try_trace_obj<sc_int<32>>(trace_file, object, types_to_trace))
  126. return;
  127. if(try_trace_obj<sc_int<64>>(trace_file, object, types_to_trace))
  128. return;
  129. if(try_trace_obj<sc_biguint<32>>(trace_file, object, types_to_trace))
  130. return;
  131. if(try_trace_obj<sc_biguint<64>>(trace_file, object, types_to_trace))
  132. return;
  133. if(try_trace_obj<sc_biguint<128>>(trace_file, object, types_to_trace))
  134. return;
  135. if(try_trace_obj<sc_biguint<256>>(trace_file, object, types_to_trace))
  136. return;
  137. if(try_trace_obj<sc_biguint<512>>(trace_file, object, types_to_trace))
  138. return;
  139. if(try_trace_obj<sc_biguint<1024>>(trace_file, object, types_to_trace))
  140. return;
  141. if(try_trace_obj<sc_bigint<32>>(trace_file, object, types_to_trace))
  142. return;
  143. if(try_trace_obj<sc_bigint<64>>(trace_file, object, types_to_trace))
  144. return;
  145. if(try_trace_obj<sc_bigint<128>>(trace_file, object, types_to_trace))
  146. return;
  147. if(try_trace_obj<sc_bigint<256>>(trace_file, object, types_to_trace))
  148. return;
  149. if(try_trace_obj<sc_bigint<512>>(trace_file, object, types_to_trace))
  150. return;
  151. if(try_trace_obj<sc_bigint<1024>>(trace_file, object, types_to_trace))
  152. return;
  153. if(try_trace_obj<sc_bv<1>>(trace_file, object, types_to_trace))
  154. return;
  155. if(try_trace_obj<sc_bv<2>>(trace_file, object, types_to_trace))
  156. return;
  157. if(try_trace_obj<sc_bv<3>>(trace_file, object, types_to_trace))
  158. return;
  159. if(try_trace_obj<sc_bv<4>>(trace_file, object, types_to_trace))
  160. return;
  161. if(try_trace_obj<sc_bv<8>>(trace_file, object, types_to_trace))
  162. return;
  163. if(try_trace_obj<sc_bv<16>>(trace_file, object, types_to_trace))
  164. return;
  165. if(try_trace_obj<sc_bv<32>>(trace_file, object, types_to_trace))
  166. return;
  167. if(try_trace_obj<sc_bv<64>>(trace_file, object, types_to_trace))
  168. return;
  169. if(try_trace_obj<sc_bv<128>>(trace_file, object, types_to_trace))
  170. return;
  171. if(try_trace_obj<sc_bv<256>>(trace_file, object, types_to_trace))
  172. return;
  173. if(try_trace_obj<sc_bv<512>>(trace_file, object, types_to_trace))
  174. return;
  175. if(try_trace_obj<sc_lv<1>>(trace_file, object, types_to_trace))
  176. return;
  177. if(try_trace_obj<sc_lv<2>>(trace_file, object, types_to_trace))
  178. return;
  179. if(try_trace_obj<sc_lv<3>>(trace_file, object, types_to_trace))
  180. return;
  181. if(try_trace_obj<sc_lv<4>>(trace_file, object, types_to_trace))
  182. return;
  183. if(try_trace_obj<sc_lv<8>>(trace_file, object, types_to_trace))
  184. return;
  185. if(try_trace_obj<sc_lv<16>>(trace_file, object, types_to_trace))
  186. return;
  187. if(try_trace_obj<sc_lv<32>>(trace_file, object, types_to_trace))
  188. return;
  189. if(try_trace_obj<sc_lv<64>>(trace_file, object, types_to_trace))
  190. return;
  191. if(try_trace_obj<sc_lv<128>>(trace_file, object, types_to_trace))
  192. return;
  193. if(try_trace_obj<sc_lv<256>>(trace_file, object, types_to_trace))
  194. return;
  195. if(try_trace_obj<sc_lv<512>>(trace_file, object, types_to_trace))
  196. return;
  197. }
  198. void tracer_base::descend(const sc_object* obj, bool trace_all) {
  199. if(obj == this)
  200. return;
  201. const char* kind = obj->kind();
  202. if(strcmp(kind, "tlm_signal") == 0) {
  203. obj->trace(trf);
  204. return;
  205. } else if(strcmp(kind, "sc_vector") == 0) {
  206. for(auto o : obj->get_child_objects())
  207. descend(o, trace_all);
  208. return;
  209. } else if((strcmp(kind, "sc_module") == 0 && trace_all) || dynamic_cast<const traceable*>(obj)) {
  210. obj->trace(trf);
  211. for(auto o : obj->get_child_objects())
  212. descend(o, trace_all);
  213. } else
  214. try_trace(trf, obj, types_to_trace);
  215. }