PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/src/sysc/tracing/sc_trace.h

https://github.com/systemc/systemc-2.2.0
C Header | 405 lines | 233 code | 95 blank | 77 comment | 6 complexity | 64942997a4a6f40f467fd99660d0448c MD5 | raw file
  1. /*****************************************************************************
  2. The following code is derived, directly or indirectly, from the SystemC
  3. source code Copyright (c) 1996-2006 by all Contributors.
  4. All Rights reserved.
  5. The contents of this file are subject to the restrictions and limitations
  6. set forth in the SystemC Open Source License Version 2.4 (the "License");
  7. You may not use this file except in compliance with such restrictions and
  8. limitations. You may obtain instructions on how to receive a copy of the
  9. License at http://www.systemc.org/. Software distributed by Contributors
  10. under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
  11. ANY KIND, either express or implied. See the License for the specific
  12. language governing rights and limitations under the License.
  13. *****************************************************************************/
  14. /*****************************************************************************
  15. sc_trace.h - Functions for tracing signals and variables.
  16. Author: Abhijit Ghosh, Synopsys, Inc.
  17. *****************************************************************************/
  18. /*****************************************************************************
  19. MODIFICATION LOG - modifiers, enter your name, affiliation, date and
  20. changes you are making here.
  21. Name, Affiliation, Date:
  22. Description of Modification:
  23. *****************************************************************************/
  24. /*****************************************************************************
  25. Acknowledgement: The tracing mechanism is based on the tracing
  26. mechanism developed at Infineon (formerly Siemens HL). Though this
  27. code is somewhat different, the basics are identical to what was
  28. originally contributed by Infineon. The contribution of Infineon
  29. in the development of this tracing technology is hereby
  30. acknowledged.
  31. *****************************************************************************/
  32. #ifndef SC_TRACE_H
  33. #define SC_TRACE_H
  34. #include <cstdio>
  35. #include "sysc/datatypes/int/sc_nbdefs.h"
  36. #include "sysc/kernel/sc_time.h"
  37. // Some forward declarations
  38. namespace sc_dt
  39. {
  40. class sc_bit;
  41. class sc_logic;
  42. class sc_bv_base;
  43. class sc_lv_base;
  44. class sc_signed;
  45. class sc_unsigned;
  46. class sc_int_base;
  47. class sc_uint_base;
  48. class sc_fxval;
  49. class sc_fxval_fast;
  50. class sc_fxnum;
  51. class sc_fxnum_fast;
  52. }
  53. namespace sc_core {
  54. class sc_logic_resolve;
  55. class sc_time;
  56. template <class T> class sc_signal_in_if;
  57. // Write error message
  58. void put_error_message(const char* msg, bool just_warning);
  59. // Base class for all kinds of trace files.
  60. class sc_trace_file
  61. {
  62. friend class sc_simcontext;
  63. public:
  64. // Constructor
  65. sc_trace_file();
  66. // All functions are pure virtual because they need to be defined by the
  67. // particular tracing mechanism
  68. #define DECL_TRACE_METHOD_A(tp) \
  69. virtual void trace( const tp& object, \
  70. const std::string& name ) = 0;
  71. #define DECL_TRACE_METHOD_B(tp) \
  72. virtual void trace( const tp& object, \
  73. const std::string& name, \
  74. int width ) = 0;
  75. DECL_TRACE_METHOD_A( bool )
  76. DECL_TRACE_METHOD_A( sc_dt::sc_bit )
  77. DECL_TRACE_METHOD_A( sc_dt::sc_logic )
  78. DECL_TRACE_METHOD_B( unsigned char )
  79. DECL_TRACE_METHOD_B( unsigned short )
  80. DECL_TRACE_METHOD_B( unsigned int )
  81. DECL_TRACE_METHOD_B( unsigned long )
  82. DECL_TRACE_METHOD_B( char )
  83. DECL_TRACE_METHOD_B( short )
  84. DECL_TRACE_METHOD_B( int )
  85. DECL_TRACE_METHOD_B( long )
  86. DECL_TRACE_METHOD_B( sc_dt::int64 )
  87. DECL_TRACE_METHOD_B( sc_dt::uint64 )
  88. DECL_TRACE_METHOD_A( float )
  89. DECL_TRACE_METHOD_A( double )
  90. DECL_TRACE_METHOD_A( sc_dt::sc_int_base )
  91. DECL_TRACE_METHOD_A( sc_dt::sc_uint_base )
  92. DECL_TRACE_METHOD_A( sc_dt::sc_signed )
  93. DECL_TRACE_METHOD_A( sc_dt::sc_unsigned )
  94. DECL_TRACE_METHOD_A( sc_dt::sc_fxval )
  95. DECL_TRACE_METHOD_A( sc_dt::sc_fxval_fast )
  96. DECL_TRACE_METHOD_A( sc_dt::sc_fxnum )
  97. DECL_TRACE_METHOD_A( sc_dt::sc_fxnum_fast )
  98. DECL_TRACE_METHOD_A( sc_dt::sc_bv_base )
  99. DECL_TRACE_METHOD_A( sc_dt::sc_lv_base )
  100. #undef DECL_TRACE_METHOD_A
  101. #undef DECL_TRACE_METHOD_B
  102. // Trace an enumerated object - where possible output the enumeration
  103. // literals in the trace file. Enum literals is a null terminated array
  104. // of null terminated char* literal strings.
  105. virtual void trace( const unsigned int& object,
  106. const std::string& name,
  107. const char** enum_literals ) = 0;
  108. // Output a comment to the trace file
  109. virtual void write_comment( const std::string& comment ) = 0;
  110. // Set the amount of space before next column
  111. // (For most formats this does nothing)
  112. virtual void space( int n );
  113. // Also trace transitions between delta cycles if flag is true.
  114. virtual void delta_cycles( bool flag );
  115. // Set time unit.
  116. virtual void set_time_unit( int exponent10_seconds ); // deprecated.
  117. virtual void set_time_unit( double v, sc_time_unit tu );
  118. protected:
  119. // Write trace info for cycle
  120. virtual void cycle( bool delta_cycle ) = 0;
  121. // Flush results and close file
  122. virtual ~sc_trace_file()
  123. { /* Intentionally blank */ };
  124. protected:
  125. bool initialized; // = true means initialized
  126. double timescale_unit; // in seconds
  127. bool timescale_set_by_user; // = true means set by user
  128. };
  129. /*****************************************************************************/
  130. // Now comes all the SystemC defined tracing functions.
  131. // We define two sc_trace() versions for scalar types; one where the object to
  132. // be traced is passed as a reference and the other where a pointer to the
  133. // tracing object is passed.
  134. #define DECL_TRACE_FUNC_REF_A(tp) \
  135. void \
  136. sc_trace( sc_trace_file* tf, \
  137. const tp& object, \
  138. const std::string& name );
  139. #define DECL_TRACE_FUNC_PTR_A(tp) \
  140. void \
  141. sc_trace( sc_trace_file* tf, \
  142. const tp* object, \
  143. const std::string& name ); \
  144. #define DECL_TRACE_FUNC_A(tp) \
  145. DECL_TRACE_FUNC_REF_A(tp) \
  146. DECL_TRACE_FUNC_PTR_A(tp)
  147. DECL_TRACE_FUNC_A( sc_dt::sc_bit )
  148. DECL_TRACE_FUNC_A( sc_dt::sc_logic )
  149. DECL_TRACE_FUNC_A( sc_dt::sc_int_base )
  150. DECL_TRACE_FUNC_A( sc_dt::sc_uint_base )
  151. DECL_TRACE_FUNC_A( sc_dt::sc_signed )
  152. DECL_TRACE_FUNC_A( sc_dt::sc_unsigned )
  153. DECL_TRACE_FUNC_REF_A( sc_dt::sc_bv_base )
  154. DECL_TRACE_FUNC_REF_A( sc_dt::sc_lv_base )
  155. #undef DECL_TRACE_FUNC_REF_A
  156. #undef DECL_TRACE_FUNC_PTR_A
  157. #undef DECL_TRACE_FUNC_A
  158. // ----------------------------------------------------------------------------
  159. #define DEFN_TRACE_FUNC_REF_A(tp) \
  160. inline \
  161. void \
  162. sc_trace( sc_trace_file* tf, const tp& object, const std::string& name ) \
  163. { \
  164. if( tf ) { \
  165. tf->trace( object, name ); \
  166. } \
  167. }
  168. #define DEFN_TRACE_FUNC_PTR_A(tp) \
  169. inline \
  170. void \
  171. sc_trace( sc_trace_file* tf, const tp* object, const std::string& name ) \
  172. { \
  173. if( tf ) { \
  174. tf->trace( *object, name ); \
  175. } \
  176. }
  177. #define DEFN_TRACE_FUNC_A(tp) \
  178. DEFN_TRACE_FUNC_REF_A(tp) \
  179. DEFN_TRACE_FUNC_PTR_A(tp)
  180. #define DEFN_TRACE_FUNC_REF_B(tp) \
  181. inline \
  182. void \
  183. sc_trace( sc_trace_file* tf, const tp& object, const std::string& name, \
  184. int width = 8 * sizeof( tp ) ) \
  185. { \
  186. if( tf ) { \
  187. tf->trace( object, name, width ); \
  188. } \
  189. }
  190. #define DEFN_TRACE_FUNC_PTR_B(tp) \
  191. inline \
  192. void \
  193. sc_trace( sc_trace_file* tf, const tp* object, const std::string& name, \
  194. int width = 8 * sizeof( tp ) ) \
  195. { \
  196. if( tf ) { \
  197. tf->trace( *object, name, width ); \
  198. } \
  199. }
  200. #define DEFN_TRACE_FUNC_B(tp) \
  201. DEFN_TRACE_FUNC_REF_B(tp) \
  202. DEFN_TRACE_FUNC_PTR_B(tp)
  203. DEFN_TRACE_FUNC_A( bool )
  204. DEFN_TRACE_FUNC_A( float )
  205. DEFN_TRACE_FUNC_A( double )
  206. DEFN_TRACE_FUNC_B( unsigned char )
  207. DEFN_TRACE_FUNC_B( unsigned short )
  208. DEFN_TRACE_FUNC_B( unsigned int )
  209. DEFN_TRACE_FUNC_B( unsigned long )
  210. DEFN_TRACE_FUNC_B( char )
  211. DEFN_TRACE_FUNC_B( short )
  212. DEFN_TRACE_FUNC_B( int )
  213. DEFN_TRACE_FUNC_B( long )
  214. DEFN_TRACE_FUNC_B( sc_dt::int64 )
  215. DEFN_TRACE_FUNC_B( sc_dt::uint64 )
  216. #undef DEFN_TRACE_FUNC_REF_A
  217. #undef DEFN_TRACE_FUNC_PTR_A
  218. #undef DEFN_TRACE_FUNC_A
  219. #undef DEFN_TRACE_FUNC_REF_B
  220. #undef DEFN_TRACE_FUNC_PTR_B
  221. #undef DEFN_TRACE_FUNC_B
  222. template <class T>
  223. inline
  224. void
  225. sc_trace( sc_trace_file* tf,
  226. const sc_signal_in_if<T>& object,
  227. const std::string& name )
  228. {
  229. sc_trace( tf, object.read(), name );
  230. }
  231. template< class T >
  232. inline
  233. void
  234. sc_trace( sc_trace_file* tf,
  235. const sc_signal_in_if<T>& object,
  236. const char* name )
  237. {
  238. sc_trace( tf, object.read(), name );
  239. }
  240. // specializations for signals of type char, short, int, long
  241. void sc_trace( sc_trace_file* tf,
  242. const sc_signal_in_if<char>& object,
  243. const std::string& name,
  244. int width );
  245. void sc_trace( sc_trace_file* tf,
  246. const sc_signal_in_if<short>& object,
  247. const std::string& name,
  248. int width );
  249. void sc_trace( sc_trace_file* tf,
  250. const sc_signal_in_if<int>& object,
  251. const std::string& name,
  252. int width );
  253. void sc_trace( sc_trace_file* tf,
  254. const sc_signal_in_if<long>& object,
  255. const std::string& name,
  256. int width );
  257. // 1. non-template function is better than template
  258. // 2. more-specialized template is better than less-specialized
  259. // 3. no partial specialization for template functions
  260. // Trace an enumerated object - where possible output the enumeration literals
  261. // in the trace file. Enum literals is a null terminated array of null
  262. // terminated char* literal strings.
  263. void
  264. sc_trace( sc_trace_file* tf,
  265. const unsigned int& object,
  266. const std::string& name,
  267. const char** enum_literals );
  268. // Dummy function for arbitrary types of value, does nothing
  269. extern void sc_trace( sc_trace_file* tf,
  270. const void* object,
  271. const std::string& name );
  272. // Turn on/off delta cycle tracing on trace file `tf'.
  273. // Default is to turn on delta cycle tracing.
  274. inline
  275. void
  276. sc_trace_delta_cycles( sc_trace_file* tf, bool on = true )
  277. {
  278. if( tf ) tf->delta_cycles( on );
  279. }
  280. // Output a comment to the trace file
  281. inline
  282. void
  283. sc_write_comment( sc_trace_file* tf, const std::string& comment )
  284. {
  285. if( tf ) tf->write_comment( comment );
  286. }
  287. // Equivalent of std::fprintf for trace files!
  288. #ifdef __GNUC__
  289. void tprintf( sc_trace_file* tf, const char* format, ... )
  290. __attribute__ ((format (printf,2,3)));
  291. #else
  292. void tprintf( sc_trace_file* tf, const char* format, ... );
  293. #endif
  294. // Convert double time to 64-bit integer
  295. extern void double_to_special_int64( double in,
  296. unsigned* high,
  297. unsigned* low );
  298. } // namespace sc_core
  299. #endif