gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
40
41namespace sc_core
42{
43
44class sc_port_base;
45class sc_export_base;
46
47} // namespace sc_core
48
49namespace 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
69extern UniqueNameGen globalNameGen;
70
71class 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 *
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
131 void endOfElaboration();
132 void startOfSimulation();
133 void endOfSimulation();
134};
135
139
140static 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}
149static inline void
151{
152 pushParentObj(m->obj()->sc_obj());
153}
154static inline void
156{
157 assert(pickParentModule());
158 popParentObj();
159}
160
162
163} // namespace sc_gem5
164
165#endif //__SYSTEMC_CORE_MODULE_HH__
bool _deprecatedConstructor
Definition module.hh:78
sc_core::sc_module * sc_mod() const
Definition module.hh:99
void endModule()
Definition module.hh:95
void endOfElaboration()
Definition module.cc:144
void endOfSimulation()
Definition module.cc:178
std::vector<::sc_core::sc_export_base * > exports
Definition module.hh:126
sc_core::sc_module * _sc_mod
Definition module.hh:75
void deprecatedConstructor()
Definition module.hh:96
void beforeEndOfElaboration()
Definition module.cc:129
void startOfSimulation()
Definition module.cc:163
void bindPorts(std::vector< const ::sc_core::sc_bind_proxy * > &proxies)
Definition module.cc:107
static Module * fromScModule(::sc_core::sc_module *mod)
Definition module.hh:87
const char * _name
Definition module.hh:74
const char * name() const
Definition module.hh:94
Object * _obj
Definition module.hh:76
std::vector<::sc_core::sc_port_base * > ports
Definition module.hh:125
Module(const char *name)
Definition module.cc:51
void sc_mod(sc_core::sc_module *sc_mod)
Definition module.hh:106
Object * obj()
Definition module.hh:113
void finish(Object *this_obj)
Definition module.cc:75
UniqueNameGen nameGen
Definition module.hh:80
const char * uniqueName(const char *seed)
Definition module.hh:121
std::map< std::string, int > counts
Definition module.hh:55
const char * gen(std::string seed)
Definition module.hh:60
std::string buf
Definition module.hh:56
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
void popParentObj()
Definition object.cc:323
UniqueNameGen globalNameGen
Definition module.cc:49
static Module * pickParentModule()
Definition module.hh:141
sc_core::sc_object * pickParentObj()
Definition object.cc:310
static void popParentModule()
Definition module.hh:155
Module * newModule()
Definition module.cc:209
Module * currentModule()
Definition module.cc:193
static void pushParentModule(Module *m)
Definition module.hh:150
Module * newModuleChecked()
Definition module.cc:201
void pushParentObj(sc_core::sc_object *obj)
Definition object.cc:322
std::list< Module * > allModules
Definition module.cc:214

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0