scc 2026.07
SystemC components library
tlm_extension_recording_registry.h
1/*******************************************************************************
2 * Copyright 2016, 2020 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#ifndef TLM_RECORDER_REGISTRY_H_
18#define TLM_RECORDER_REGISTRY_H_
19
20#include <memory>
21#include <tlm>
22#include <unordered_set>
23#include <util/delegate.h>
24#ifdef HAS_SCV
25#include <scv.h>
26#ifndef SCVNS
27#define SCVNS
28#endif
29#else
30#include <scv-tr.h>
31#ifndef SCVNS
32#define SCVNS ::scv_tr::
33#endif
34#endif
35#include <tlm>
36
38namespace tlm {
40namespace scc {
42namespace scv {
48 util::delegate<void(SCVNS scv_tr_handle&, tlm::tlm_extension_base*, std::string const&)> recordBegin;
53 util::delegate<void(SCVNS scv_tr_handle&, tlm::tlm_extension_base*, std::string const&)> recordEnd;
54
55 virtual ~tlm_extension_record_if() = default;
56};
57struct tlm_extension_record_registry {
58 using recording_vector = std::vector<std::unique_ptr<tlm_extension_record_if>>;
59
60 static tlm_extension_record_registry& get() {
61 static tlm_extension_record_registry reg;
62 return reg;
63 }
64
65 void register_ext_rec(size_t id, std::unique_ptr<tlm_extension_record_if> ext) {
66 if(id == 0)
67 return;
68 if(id >= ext_rec.size())
69 ext_rec.resize(id + 1);
70 ext_rec.at(id) = std::move(ext);
71 }
72
73 bool is_ext_registered(size_t id) { return id == 0 || (id < ext_rec.size() && ext_rec[id]); }
74
75 size_t size() const { return ext_rec.size(); }
76
77 typename recording_vector::iterator begin() { return ext_rec.begin(); }
78
79 typename recording_vector::iterator end() { return ext_rec.end(); }
80
81 tlm_extension_record_if* operator[](size_t n) {
82#ifdef NDEBUG
83 return ext_rec[n].get();
84#else
85 return ext_rec.at(n).get();
86#endif
87 }
91 inline void recordBeginTx(size_t id, SCVNS scv_tr_handle& handle, tlm::tlm_extension_base* ext, std::string const& prefix = "") {
92 assert(ext_rec.size() > id);
93 if(ext && ext_rec[id] && ext_rec[id]->recordBegin)
94 ext_rec[id]->recordBegin(handle, ext, prefix);
95 }
96
99 inline void recordEndTx(size_t id, SCVNS scv_tr_handle& handle, tlm::tlm_extension_base* ext, std::string const& prefix = "") {
100 assert(ext_rec.size() > id);
101 if(ext && ext_rec[id] && ext_rec[id]->recordEnd)
102 ext_rec[id]->recordEnd(handle, ext, prefix);
103 }
104
105private:
108
109 recording_vector ext_rec{};
110};
111
118template <typename TYPES = tlm::tlm_base_protocol_types> struct tlm_extensions_recording_if {
119public:
120 using record_tx_fct = util::delegate<void(SCVNS scv_tr_handle&, typename TYPES::tlm_payload_type&)>;
125 void recordBeginTx(SCVNS scv_tr_handle& h, typename TYPES::tlm_payload_type& trans) {
126 if(recordBegin)
127 recordBegin(h, trans);
128 }
129
133 void recordEndTx(SCVNS scv_tr_handle& h, typename TYPES::tlm_payload_type& trans) {
134 if(recordEnd)
135 recordEnd(h, trans);
136 }
137
138protected:
139 record_tx_fct recordBegin;
140 record_tx_fct recordEnd;
141};
142
149template <typename TYPES = tlm::tlm_base_protocol_types> class tlm_extension_recording_registry {
150public:
151 using recording_vector = std::vector<std::unique_ptr<tlm_extensions_recording_if<TYPES>>>;
152 static tlm_extension_recording_registry& get() {
153 static tlm_extension_recording_registry reg;
154 return reg;
155 }
156 void register_ext_rec(size_t id, std::unique_ptr<tlm_extensions_recording_if<TYPES>> ext) {
157 ext_rec.push_back(std::move(ext));
158 registered_ids.insert(id);
159 }
160
161 bool is_ext_registered(size_t id) { return registered_ids.count(id); }
162
163 typename recording_vector::iterator begin() { return ext_rec.begin(); }
164
165 typename recording_vector::iterator end() { return ext_rec.end(); }
166
167private:
168 tlm_extension_recording_registry() = default;
169 recording_vector ext_rec{};
170 std::unordered_set<size_t> registered_ids;
171};
172
173} // namespace scv
174} // namespace scc
175} // namespace tlm
176#endif /* TLM_RECORDER_REGISTRY_H_ */
SCC SCV4TLM classes and functions.
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19
util::delegate< void(SCVNS scv_tr_handle &, tlm::tlm_extension_base *, std::string const &)> recordBegin
recording attributes in extensions at the beginning, it is intended to be overload as it does nothing
util::delegate< void(SCVNS scv_tr_handle &, tlm::tlm_extension_base *, std::string const &)> recordEnd
recording attributes in extensions at the end, it is intended to be overload as it does nothing
void recordBeginTx(size_t id, SCVNS scv_tr_handle &handle, tlm::tlm_extension_base *ext, std::string const &prefix="")
recording attributes in extensions at the beginning
void recordEndTx(size_t id, SCVNS scv_tr_handle &handle, tlm::tlm_extension_base *ext, std::string const &prefix="")
recording attributes in extensions at the end
The TLM transaction extensions recorder interface.
void recordBeginTx(SCVNS scv_tr_handle &h, typename TYPES::tlm_payload_type &trans)
recording attributes in extensions at the beginning, it is intended to be overload as it does nothing
void recordEndTx(SCVNS scv_tr_handle &h, typename TYPES::tlm_payload_type &trans)
recording attributes in extensions at the end, it is intended to be overload as it does nothing