gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Gabe Black
28  */
29 
30 #ifndef __SYSTEMC_CORE_MODULE_HH__
31 #define __SYSTEMC_CORE_MODULE_HH__
32 
33 #include <cassert>
34 #include <list>
35 #include <map>
36 #include <sstream>
37 #include <string>
38 #include <vector>
39 
40 #include "systemc/core/object.hh"
42 
43 namespace sc_core
44 {
45 
46 class sc_port_base;
47 class sc_export_base;
48 
49 } // namespace sc_core
50 
51 namespace sc_gem5
52 {
53 
55 {
56  private:
57  std::map<std::string, int> counts;
58  std::string buf;
59 
60  public:
61  const char *
62  gen(std::string seed)
63  {
64  std::ostringstream os;
65  os << seed << "_" << counts[seed]++;
66  buf = os.str();
67  return buf.c_str();
68  }
69 };
70 
72 
73 class Module
74 {
75  private:
76  const char *_name;
79  bool _ended;
81 
83 
84  public:
85  Module(const char *name);
86  ~Module();
87 
88  static Module *
90  {
91  return mod->_gem5_module;
92  }
93 
94  void finish(Object *this_obj);
95 
96  const char *name() const { return _name; }
97  void endModule() { _ended = true; }
98  void deprecatedConstructor() { _deprecatedConstructor = true; }
99 
101  sc_mod() const
102  {
103  assert(_sc_mod);
104  return _sc_mod;
105  }
106 
107  void
109  {
110  assert(!_sc_mod);
111  _sc_mod = sc_mod;
112  }
113 
114  Object *
115  obj()
116  {
117  assert(_obj);
118  return _obj;
119  }
120 
121  void pop();
122 
123  const char *uniqueName(const char *seed) { return nameGen.gen(seed); }
124 
125  void bindPorts(std::vector<const ::sc_core::sc_bind_proxy *> &proxies);
126 
129 
131 
132  void beforeEndOfElaboration();
133  void endOfElaboration();
134  void startOfSimulation();
135  void endOfSimulation();
136 };
137 
140 Module *newModule();
141 
142 static inline Module *
144 {
146  auto mod = dynamic_cast<::sc_core::sc_module *>(obj);
147  if (!mod)
148  return nullptr;
149  return Module::fromScModule(mod);
150 }
151 static inline void
153 {
154  pushParentObj(m->obj()->sc_obj());
155 }
156 static inline void
158 {
159  assert(pickParentModule());
160  popParentObj();
161 }
162 
164 
165 } // namespace sc_gem5
166 
167 #endif //__SYSTEMC_CORE_MODULE_HH__
Object * obj()
Definition: module.hh:115
void popParentObj()
Definition: object.cc:325
sc_gem5::Module * _gem5_module
Definition: sc_module.hh:256
const char * name() const
Definition: module.hh:96
std::list< Module * > allModules
Definition: module.cc:213
const std::string & name()
Definition: trace.cc:54
Module * newModuleChecked()
Definition: module.cc:200
Bitfield< 0 > m
static Module * fromScModule(::sc_core::sc_module *mod)
Definition: module.hh:89
std::vector<::sc_core::sc_export_base * > exports
Definition: module.hh:128
Bitfield< 17 > os
Definition: misc.hh:805
STL vector class.
Definition: stl.hh:40
static void pushParentModule(Module *m)
Definition: module.hh:152
const char * uniqueName(const char *seed)
Definition: module.hh:123
const char * _name
Definition: module.hh:76
UniqueNameGen globalNameGen
Definition: module.cc:51
Module * currentModule()
Definition: module.cc:192
Module * newModule()
Definition: module.cc:208
sc_core::sc_module * _sc_mod
Definition: module.hh:77
void sc_mod(sc_core::sc_module *sc_mod)
Definition: module.hh:108
std::map< std::string, int > counts
Definition: module.hh:57
void deprecatedConstructor()
Definition: module.hh:98
void endModule()
Definition: module.hh:97
int bindingIndex
Definition: module.hh:130
sc_core::sc_object * pickParentObj()
Definition: object.cc:312
void pushParentObj(sc_core::sc_object *obj)
Definition: object.cc:324
int mod(int val, int mod)
STL list class.
Definition: stl.hh:54
std::vector<::sc_core::sc_port_base * > ports
Definition: module.hh:127
const char * gen(std::string seed)
Definition: module.hh:62
sc_core::sc_object * sc_obj()
Definition: object.hh:88
bool _deprecatedConstructor
Definition: module.hh:80
UniqueNameGen nameGen
Definition: module.hh:82
std::string buf
Definition: module.hh:58
sc_core::sc_module * sc_mod() const
Definition: module.hh:101
static void popParentModule()
Definition: module.hh:157
static Module * pickParentModule()
Definition: module.hh:143
Object * _obj
Definition: module.hh:78

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13