scc  2024.06
SystemC components library
path_trace.h
1 /*****************************************************************************
2  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
3  more contributor license agreements. See the NOTICE file distributed
4  with this work for additional information regarding copyright ownership.
5  Accellera licenses this file to you under the Apache License, Version 2.0
6  (the "License"); you may not use this file except in compliance with the
7  License. You may obtain a copy of the License at
8  http://www.apache.org/licenses/LICENSE-2.0
9  Unless required by applicable law or agreed to in writing, software
10  distributed under the License is distributed on an "AS IS" BASIS,
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  implied. See the License for the specific language governing
13  permissions and limitations under the License.
14  ****************************************************************************/
15 
16 #ifndef _SCP_PATHTRACE_EXTENSION_H
17 #define _SCP_PATHTRACE_EXTENSION_H
18 
19 #include <sstream>
20 #include <systemc>
21 #include <tlm>
22 
23 namespace scp {
24 namespace tlm_extensions {
25 
35 class path_trace : public tlm::tlm_extension<path_trace> {
36  std::vector<sc_core::sc_object*> m_path;
37 
38 public:
39  path_trace() = default;
40  path_trace(const path_trace&) = default;
41 
42  virtual tlm_extension_base* clone() const override { return new path_trace(*this); }
43 
44  virtual void copy_from(const tlm_extension_base& ext) override {
45  const path_trace& other = static_cast<const path_trace&>(ext);
46  *this = other;
47  }
48 
53  void stamp(sc_core::sc_object* obj) { m_path.push_back(obj); }
54 
59  void reset() { m_path.clear(); }
66  std::string to_string(std::string separator = "->") {
67  std::stringstream info;
68  std::string s;
69  for(auto o : m_path) {
70  info << s << o->name();
71  s = separator;
72  }
73  return info.str();
74  }
75 };
76 } // namespace tlm_extensions
77 } // namespace scp
78 #endif
void reset()
Convenience function to clear vector (eg. before returning to a pool)
Definition: path_trace.h:59
std::string to_string(std::string separator="->")
convert extension to a string
Definition: path_trace.h:66
void stamp(sc_core::sc_object *obj)
Stamp object into the PathTrace.
Definition: path_trace.h:53