scc  2022.4.0
SystemC components library
fst_trace.hh
1 /*******************************************************************************
2  * Copyright 2021 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 
18 #ifndef SCC_FST_TRACE_H
19 #define SCC_FST_TRACE_H
20 
21 #include <scc/observer.h>
22 #include <sysc/tracing/sc_trace.h>
23 #include <sysc/kernel/sc_ver.h>
24 #include <deque>
25 #include <vector>
26 #include <functional>
27 
28 namespace sc_core {
29 class sc_time;
30 }
36 namespace scc {
38 namespace trace {
39 class fst_trace;
40 }
41 struct fst_trace_file : public sc_core::sc_trace_file, public observer {
42 
43  fst_trace_file(const char *name, std::function<bool()>& enable);
44 
45  virtual ~fst_trace_file();
46 
47 protected:
48 #define DECL_TRACE_METHOD_A(tp) void trace(const tp& object, const std::string& name) override;
49 #define DECL_TRACE_METHOD_B(tp) void trace(const tp& object, const std::string& name, int width) override;
50 #if (SYSTEMC_VERSION >= 20171012)
51  DECL_TRACE_METHOD_A( sc_core::sc_event )
52  DECL_TRACE_METHOD_A( sc_core::sc_time )
53 #endif
54  DECL_TRACE_METHOD_A( bool )
55  DECL_TRACE_METHOD_A( sc_dt::sc_bit )
56  DECL_TRACE_METHOD_A( sc_dt::sc_logic )
57  DECL_TRACE_METHOD_B( unsigned char )
58  DECL_TRACE_METHOD_B( unsigned short )
59  DECL_TRACE_METHOD_B( unsigned int )
60  DECL_TRACE_METHOD_B( unsigned long )
61 #ifdef SYSTEMC_64BIT_PATCHES
62  DECL_TRACE_METHOD_B( unsigned long long)
63 #endif
64  DECL_TRACE_METHOD_B( char )
65  DECL_TRACE_METHOD_B( short )
66  DECL_TRACE_METHOD_B( int )
67  DECL_TRACE_METHOD_B( long )
68  DECL_TRACE_METHOD_B( sc_dt::int64 )
69  DECL_TRACE_METHOD_B( sc_dt::uint64 )
70  DECL_TRACE_METHOD_A( float )
71  DECL_TRACE_METHOD_A( double )
72  DECL_TRACE_METHOD_A( sc_dt::sc_int_base )
73  DECL_TRACE_METHOD_A( sc_dt::sc_uint_base )
74  DECL_TRACE_METHOD_A( sc_dt::sc_signed )
75  DECL_TRACE_METHOD_A( sc_dt::sc_unsigned )
76  DECL_TRACE_METHOD_A( sc_dt::sc_fxval )
77  DECL_TRACE_METHOD_A( sc_dt::sc_fxval_fast )
78  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum )
79  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum_fast )
80  DECL_TRACE_METHOD_A( sc_dt::sc_bv_base )
81  DECL_TRACE_METHOD_A( sc_dt::sc_lv_base )
82 #undef DECL_TRACE_METHOD_A
83 #undef DECL_TRACE_METHOD_B
84 
85  void trace( const unsigned int& object,
86  const std::string& name,
87  const char** enum_literals ) override;
88 
89 #define DECL_REGISTER_METHOD_A(tp) observer::notification_handle* observe(tp const& o, std::string const& nm) override;
90 #if (SYSTEMC_VERSION >= 20171012)
91  DECL_REGISTER_METHOD_A( sc_core::sc_event )
92  DECL_REGISTER_METHOD_A( sc_core::sc_time )
93 #endif
94  DECL_REGISTER_METHOD_A( bool )
95  DECL_REGISTER_METHOD_A( sc_dt::sc_bit )
96  DECL_REGISTER_METHOD_A( sc_dt::sc_logic )
97 
98  DECL_REGISTER_METHOD_A( unsigned char )
99  DECL_REGISTER_METHOD_A( unsigned short )
100  DECL_REGISTER_METHOD_A( unsigned int )
101  DECL_REGISTER_METHOD_A( unsigned long )
102  DECL_REGISTER_METHOD_A( char )
103  DECL_REGISTER_METHOD_A( short )
104  DECL_REGISTER_METHOD_A( int )
105  DECL_REGISTER_METHOD_A( long )
106  DECL_REGISTER_METHOD_A( sc_dt::int64 )
107  DECL_REGISTER_METHOD_A( sc_dt::uint64 )
108 
109  DECL_REGISTER_METHOD_A( float )
110  DECL_REGISTER_METHOD_A( double )
111  DECL_REGISTER_METHOD_A( sc_dt::sc_int_base )
112  DECL_REGISTER_METHOD_A( sc_dt::sc_uint_base )
113  DECL_REGISTER_METHOD_A( sc_dt::sc_signed )
114  DECL_REGISTER_METHOD_A( sc_dt::sc_unsigned )
115 
116  DECL_REGISTER_METHOD_A( sc_dt::sc_fxval )
117  DECL_REGISTER_METHOD_A( sc_dt::sc_fxval_fast )
118  DECL_REGISTER_METHOD_A( sc_dt::sc_fxnum )
119  DECL_REGISTER_METHOD_A( sc_dt::sc_fxnum_fast )
120 
121  DECL_REGISTER_METHOD_A( sc_dt::sc_bv_base )
122  DECL_REGISTER_METHOD_A( sc_dt::sc_lv_base )
123 #undef DECL_REGISTER_METHOD_A
124 
125  // Output a comment to the trace file
126  void write_comment(const std::string& comment) override;
127 
128  // Write trace info for cycle.
129  void cycle(bool delta_cycle) override;
130 
131  void set_time_unit( double v, sc_core::sc_time_unit tu ) override;
132 #ifdef NCSC
133  void set_time_unit( int exponent10_seconds ) override;
134 #endif
135 
136 private:
137 #if WITH_SC_TRACING_PHASE_CALLBACKS
138  // avoid hidden overload warnings
139  virtual void trace( sc_trace_file* ) const;
140 #endif
141 
142  void init();
143  std::function<bool()> check_enabled;
144 
145  void* m_fst{nullptr};
146  struct trace_entry: public observer::notification_handle {
147  bool (*compare_and_update)(trace::fst_trace*);
148  trace::fst_trace* trc;
149  fst_trace_file* that;
150  bool notify() override;
151  trace_entry(fst_trace_file* owner, bool (*compare_and_update)(trace::fst_trace*), trace::fst_trace* trc)
152  :compare_and_update{compare_and_update}, trc{trc}, that{owner}{}
153  virtual ~trace_entry(){}
154  };
155  std::deque<trace_entry> all_traces;
156  std::vector<trace_entry*> pull_traces;
157  std::vector<trace::fst_trace*> changed_traces;
158  std::vector<trace::fst_trace*> triggered_traces;
159  uint64_t last_emitted_ts{std::numeric_limits<uint64_t>::max()};
160 };
161 } // namespace scc // end of scc-sysc
163 #endif // SCC_FST_TRACE_H
SCC SystemC utilities.
A handle to be used be the observed object to notify the observer about a change.
Definition: observer.h:57
The interface defining an observer.
Definition: observer.h:53