scc 2026.07
SystemC components library
cxs_tlm.cpp
1/*
2 * Copyright 2020 Arteris IP
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#include "cxs/cxs_tlm.h"
18#include "util/ities.h"
19#include <fmt/format.h>
20#include <tlm/scc/scv/tlm_extension_recording_registry.h>
21#include <tlm/scc/tlm_id.h>
22
23namespace cxs {
24using namespace tlm::scc::scv;
25
26struct cxs_ext_record : public tlm_extension_record_if {
27
28 cxs_ext_record() { recordBegin = &recordBeginTx; }
29
30 static void recordBeginTx(SCVNS scv_tr_handle& handle, tlm::tlm_extension_base* e, std::string const& prefix) {
31 if(auto ext = dynamic_cast<cxs_packet_extension*>(e)) {
32 auto idx = 0U;
33 for(auto const& pkt : ext->packets) {
34 auto prf = fmt::format("{}packet{}.", prefix, idx++);
35 handle.record_attribute(fmt::format("{}size", prf).c_str(), pkt->get_data().size());
36 if(pkt->get_extension_count()) {
37 auto size = tlm_extension_record_registry::get().size();
38 for(auto i = 0u; i < size; ++i)
39 if(auto orig_ext = pkt->get_extension(i))
40 tlm_extension_record_registry::get().recordBeginTx(i, handle, orig_ext, prf);
41 }
42 }
43 }
44 }
45};
46
47struct cxs_ext_recording : public tlm_extensions_recording_if<cxs_flit_types> {
48
49 cxs_ext_recording() { recordBegin = &recordBeginTx; }
50
51 static void recordBeginTx(SCVNS scv_tr_handle& h, cxs_flit_types::tlm_payload_type& trans) {
52 tlm_extension_record_registry::get().recordBeginTx(cxs_packet_extension::ID, h, trans.get_extension<cxs_packet_extension>(),
53 "flit.");
54 }
55};
56#if defined(__GNUG__)
57__attribute__((constructor))
58#endif
59bool register_extensions() {
60 cxs::cxs_packet_extension ext; // NOLINT
61 if(!tlm_extension_recording_registry<cxs::cxs_flit_types>::get().is_ext_registered(ext.ID))
62 tlm_extension_recording_registry<cxs::cxs_flit_types>::get().register_ext_rec(
63 ext.ID,
64 util::make_unique<cxs::cxs_ext_recording>()); // NOLINT
65 if(!tlm_extension_record_registry::get().is_ext_registered(ext.ID))
66 tlm_extension_record_registry::get().register_ext_rec(ext.ID, util::make_unique<cxs_ext_record>()); // NOLINT
67 return true; // NOLINT
68}
69bool registered = register_extensions();
70} // namespace cxs
CXS TLM utilities.
Definition cxs_tlm.cpp:23
SCC SCV4TLM classes and functions.
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
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