gem5  v22.1.0.0
phase.cc
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 #include <cstring>
21 #include <map>
22 #include <string>
23 #include <typeindex>
24 
27 
28 namespace tlm
29 {
30 
31 namespace
32 {
33 
34 struct tlm_phase_registry
35 {
36  typedef unsigned int key_type;
37 
38  static tlm_phase_registry &
39  instance()
40  {
41  static tlm_phase_registry inst;
42  return inst;
43  }
44 
45  unsigned int
46  register_phase(std::type_index type, std::string name)
47  {
48  type_map::const_iterator it = ids_.find(type);
49 
50  if (name.empty()) {
52  "unexpected empty tlm_phase name" );
53  return UNINITIALIZED_PHASE;
54  }
55 
56  if (it == ids_.end()) {
57  // new phase - generate/store ID and name
58  type_map::value_type v(type, static_cast<key_type>(names_.size()));
59  names_.push_back(name_table::value_type(name.data(), name.size()));
60  ids_.insert(v);
61  return v.second;
62  }
63 
64  if (names_[it->second] != name) {
66  "tlm_phase registration failed: duplicate type info" );
68  }
69  return it->second;
70  }
71 
72  const char *
73  get_name(key_type id) const
74  {
75  sc_assert(id < names_.size());
76  return names_[id].c_str();
77  }
78 
79  private:
80  typedef std::map<std::type_index, key_type> type_map;
81  typedef std::vector<std::string> name_table;
82 
83  type_map ids_;
84  name_table names_;
85 
86  tlm_phase_registry() : names_(END_RESP + 1)
87  {
88  names_[UNINITIALIZED_PHASE] = "UNINITIALIZED_PHASE";
89  names_[BEGIN_REQ] = "BEGIN_REQ";
90  names_[END_REQ] = "END_REQ";
91  names_[BEGIN_RESP] = "BEGIN_RESP";
92  names_[END_RESP] = "END_RESP";
93  }
94 };
95 
96 } // anonymous namespace
97 
98 tlm_phase::tlm_phase(unsigned int id) : m_id(id)
99 {}
100 
101 tlm_phase::tlm_phase(const std::type_info &type, const char *name) :
102  m_id(tlm_phase_registry::instance().register_phase(type, name))
103 {}
104 
105 const char *
107 {
108  return tlm_phase_registry::instance().get_name(m_id);
109 }
110 
111 } // namespace tlm
const char * get_name() const
Definition: phase.cc:106
unsigned int m_id
Definition: phase.hh:64
Bitfield< 33 > id
Definition: misc_types.hh:257
Bitfield< 0 > v
Definition: pagetable.hh:65
void sc_abort()
Definition: sc_report.cc:178
const char SC_ID_INTERNAL_ERROR_[]
Definition: messages.cc:38
@ BEGIN_RESP
Definition: phase.hh:43
@ END_RESP
Definition: phase.hh:44
@ BEGIN_REQ
Definition: phase.hh:41
@ END_REQ
Definition: phase.hh:42
@ UNINITIALIZED_PHASE
Definition: phase.hh:40
#define SC_REPORT_FATAL(msg_type, msg)
#define sc_assert(expr)
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:50 for gem5 by doxygen 1.9.1