gem5  v20.1.0.0
module.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __SYSTEMC_CORE_MODULE_HH__
29 #define __SYSTEMC_CORE_MODULE_HH__
30 
31 #include <cassert>
32 #include <list>
33 #include <map>
34 #include <sstream>
35 #include <string>
36 #include <vector>
37 
38 #include "systemc/core/object.hh"
40 
41 namespace sc_core
42 {
43 
44 class sc_port_base;
45 class sc_export_base;
46 
47 } // namespace sc_core
48 
49 namespace sc_gem5
50 {
51 
53 {
54  private:
55  std::map<std::string, int> counts;
56  std::string buf;
57 
58  public:
59  const char *
60  gen(std::string seed)
61  {
62  std::ostringstream os;
63  os << seed << "_" << counts[seed]++;
64  buf = os.str();
65  return buf.c_str();
66  }
67 };
68 
69 extern UniqueNameGen globalNameGen;
70 
71 class Module
72 {
73  private:
74  const char *_name;
77  bool _ended;
79 
81 
82  public:
83  Module(const char *name);
84  ~Module();
85 
86  static Module *
88  {
89  return mod->_gem5_module;
90  }
91 
92  void finish(Object *this_obj);
93 
94  const char *name() const { return _name; }
95  void endModule() { _ended = true; }
97 
99  sc_mod() const
100  {
101  assert(_sc_mod);
102  return _sc_mod;
103  }
104 
105  void
107  {
108  assert(!_sc_mod);
109  _sc_mod = sc_mod;
110  }
111 
112  Object *
113  obj()
114  {
115  assert(_obj);
116  return _obj;
117  }
118 
119  void pop();
120 
121  const char *uniqueName(const char *seed) { return nameGen.gen(seed); }
122 
124 
127 
129 
130  void beforeEndOfElaboration();
131  void endOfElaboration();
132  void startOfSimulation();
133  void endOfSimulation();
134 };
135 
138 Module *newModule();
139 
140 static inline Module *
142 {
144  auto mod = dynamic_cast<::sc_core::sc_module *>(obj);
145  if (!mod)
146  return nullptr;
147  return Module::fromScModule(mod);
148 }
149 static inline void
151 {
152  pushParentObj(m->obj()->sc_obj());
153 }
154 static inline void
156 {
157  assert(pickParentModule());
158  popParentObj();
159 }
160 
162 
163 } // namespace sc_gem5
164 
165 #endif //__SYSTEMC_CORE_MODULE_HH__
sc_gem5::globalNameGen
UniqueNameGen globalNameGen
Definition: module.cc:49
sc_gem5::pickParentObj
sc_core::sc_object * pickParentObj()
Definition: object.cc:310
sc_gem5::Module::exports
std::vector<::sc_core::sc_export_base * > exports
Definition: module.hh:126
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
sc_gem5::UniqueNameGen::buf
std::string buf
Definition: module.hh:56
sc_gem5::Module::startOfSimulation
void startOfSimulation()
Definition: module.cc:160
sc_core::sc_module
Definition: sc_module.hh:97
sc_gem5::Module::ports
std::vector<::sc_core::sc_port_base * > ports
Definition: module.hh:125
sc_gem5::Module::pop
void pop()
Definition: module.cc:93
sc_gem5::UniqueNameGen::counts
std::map< std::string, int > counts
Definition: module.hh:55
sc_core
Definition: messages.cc:31
sc_gem5::Module::_obj
Object * _obj
Definition: module.hh:76
mod
int mod(int val, int mod)
Definition: RubySlicc_Util.hh:90
sc_gem5::Module::name
const char * name() const
Definition: module.hh:94
sc_gem5::Module::_name
const char * _name
Definition: module.hh:74
sc_gem5::popParentObj
void popParentObj()
Definition: object.cc:323
sc_gem5::UniqueNameGen
Definition: module.hh:52
sc_gem5::Module::nameGen
UniqueNameGen nameGen
Definition: module.hh:80
std::vector
STL vector class.
Definition: stl.hh:37
sc_gem5::pickParentModule
static Module * pickParentModule()
Definition: module.hh:141
sc_gem5::Module::deprecatedConstructor
void deprecatedConstructor()
Definition: module.hh:96
sc_gem5::Module::_ended
bool _ended
Definition: module.hh:77
sc_gem5::UniqueNameGen::gen
const char * gen(std::string seed)
Definition: module.hh:60
sc_gem5::Module::sc_mod
sc_core::sc_module * sc_mod() const
Definition: module.hh:99
sc_gem5::Module::fromScModule
static Module * fromScModule(::sc_core::sc_module *mod)
Definition: module.hh:87
sc_gem5::Module::Module
Module(const char *name)
Definition: module.cc:51
sc_gem5::Module::finish
void finish(Object *this_obj)
Definition: module.cc:74
sc_gem5::Module::~Module
~Module()
Definition: module.cc:59
sc_gem5::popParentModule
static void popParentModule()
Definition: module.hh:155
sc_gem5::currentModule
Module * currentModule()
Definition: module.cc:190
sc_gem5::Module::bindPorts
void bindPorts(std::vector< const ::sc_core::sc_bind_proxy * > &proxies)
Definition: module.cc:105
sc_gem5::Object
Definition: object.hh:47
sc_gem5::pushParentModule
static void pushParentModule(Module *m)
Definition: module.hh:150
sc_gem5::newModuleChecked
Module * newModuleChecked()
Definition: module.cc:198
sc_core::sc_object
Definition: sc_object.hh:50
sc_module.hh
sc_gem5::Module::endOfElaboration
void endOfElaboration()
Definition: module.cc:141
sc_gem5::pushParentObj
void pushParentObj(sc_core::sc_object *obj)
Definition: object.cc:322
sc_gem5::newModule
Module * newModule()
Definition: module.cc:206
sc_gem5::Module::endOfSimulation
void endOfSimulation()
Definition: module.cc:175
sc_gem5::Module::endModule
void endModule()
Definition: module.hh:95
sc_gem5::Module::_deprecatedConstructor
bool _deprecatedConstructor
Definition: module.hh:78
object.hh
sc_gem5::allModules
std::list< Module * > allModules
Definition: module.cc:211
sc_gem5::Module::obj
Object * obj()
Definition: module.hh:113
sc_gem5
Definition: sc_clock.cc:42
sc_gem5::Module::uniqueName
const char * uniqueName(const char *seed)
Definition: module.hh:121
std::list
STL list class.
Definition: stl.hh:51
sc_gem5::Module::bindingIndex
int bindingIndex
Definition: module.hh:128
sc_gem5::Module::sc_mod
void sc_mod(sc_core::sc_module *sc_mod)
Definition: module.hh:106
sc_gem5::Module::beforeEndOfElaboration
void beforeEndOfElaboration()
Definition: module.cc:126
sc_gem5::Module::_sc_mod
sc_core::sc_module * _sc_mod
Definition: module.hh:75
sc_gem5::Module
Definition: module.hh:71
ArmISA::m
Bitfield< 0 > m
Definition: miscregs_types.hh:389

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17