scc 2026.07
SystemC components library
tlm_id.h
1/*******************************************************************************
2 * Copyright 2021 - 2022 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#pragma once
18
19#include "tlm_gp_shared.h"
20#include <cstdint>
21
23namespace tlm {
25namespace scc {
26
27struct tlm_id_extension : public tlm_extension<tlm_id_extension> {
28 tlm_extension_base* clone() const override { return new tlm_id_extension(this->id); }
29 void copy_from(tlm_extension_base const& from) override { id = static_cast<tlm_id_extension const&>(from).id; }
30 tlm_id_extension(tlm_gp_shared_ptr& i)
31 : tlm_id_extension(reinterpret_cast<uintptr_t>(i.get())) {}
32 tlm_id_extension(void* i)
33 : tlm_id_extension(reinterpret_cast<uintptr_t>(i)) {}
34 tlm_id_extension(uintptr_t i)
35 : id(i) {}
36 uintptr_t id;
37};
38
39inline uintptr_t getId(tlm::tlm_generic_payload& gp) {
40 if(auto ext = gp.get_extension<tlm_id_extension>())
41 return ext->id;
42 else
43 return (uintptr_t)&gp;
44}
45
46inline uintptr_t getId(tlm::tlm_generic_payload* gp) {
47 if(!gp)
48 return 0;
49 if(auto ext = gp->get_extension<tlm_id_extension>())
50 return ext->id;
51 else
52 return (uintptr_t)gp;
53}
54
55inline void setId(tlm::tlm_generic_payload& gp, uintptr_t id) {
56 if(auto ext = gp.get_extension<tlm_id_extension>())
57 ext->id = id;
58 else if(gp.has_mm())
59 gp.set_auto_extension(new tlm_id_extension(id));
60 else
61 gp.set_extension(new tlm_id_extension(id));
62}
63
64struct initiator_id_extension : public tlm_extension<tlm_id_extension> {
65 tlm_extension_base* clone() const override { return new initiator_id_extension(*this); }
66 void copy_from(tlm_extension_base const& from) override {}
67
68 initiator_id_extension(uint64_t i)
69 : id(i) {}
70
71 initiator_id_extension(initiator_id_extension const& o)
72 : id(o.id) {}
73
74 virtual ~initiator_id_extension() = default;
75
76 const uint64_t id;
77};
78
79} // namespace scc
80} // namespace tlm
T * get() const noexcept
Return the stored pointer.
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19