Daniel Carvalho has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/46328 )
Change subject: misc: Adopt the gem5 namespace in generated files
......................................................................
misc: Adopt the gem5 namespace in generated files
Adopt the gem5 namespace in the files that are
automatically generated.
Change-Id: Ie7b1204f3518ff3cd2c14798b10e983965176d4b
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
---
M src/SConscript
M src/mem/slicc/symbols/StateMachine.py
M src/mem/slicc/symbols/Type.py
M src/python/m5/SimObject.py
M src/python/m5/params.py
M util/cpt_upgrader.py
6 files changed, 136 insertions(+), 29 deletions(-)
diff --git a/src/SConscript b/src/SConscript
index b1aa8bf..10f9a25 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1312,7 +1312,10 @@
code('''\
#include "sim/init.hh"
-namespace {
+namespace gem5
+{
+namespace
+{
''')
blobToCpp(data, 'data_' + sym, code)
@@ -1328,6 +1331,7 @@
${{len(marshalled)}});
} // anonymous namespace
+} // namespace gem5
''')
code.write(str(target[0]))
diff --git a/src/mem/slicc/symbols/StateMachine.py
b/src/mem/slicc/symbols/StateMachine.py
index 77c999d..827835d 100644
--- a/src/mem/slicc/symbols/StateMachine.py
+++ b/src/mem/slicc/symbols/StateMachine.py
@@ -244,6 +244,7 @@
class $py_ident(RubyController):
type = '$py_ident'
cxx_header = 'mem/ruby/protocol/${c_ident}.hh'
+ cxx_class = 'gem5::$py_ident'
''')
code.indent()
for param in self.config_parameters:
@@ -301,6 +302,9 @@
# for adding information to the protocol debug trace
code('''
+namespace gem5
+{
+
extern std::stringstream ${ident}_transitionComment;
class $c_ident : public AbstractController
@@ -455,8 +459,14 @@
code('${{var.type.c_ident}}$th* m_${{var.ident}}_ptr;')
code.dedent()
- code('};')
- code('#endif // __${ident}_CONTROLLER_H__')
+ code('''
+};
+
+} // namespace gem5
+
+#endif // __${ident}_CONTROLLER_H__
+''')
+
code.write(path, '%s.hh' % c_ident)
def printControllerCC(self, path, includes):
@@ -535,6 +545,9 @@
num_in_ports = len(self.in_ports)
code('''
+namespace gem5
+{
+
int $c_ident::m_num_controllers = 0;
std::vector<statistics::Vector *> $c_ident::eventVec;
std::vector<std::vector<statistics::Vector *> > $c_ident::transVec;
@@ -1205,6 +1218,8 @@
code('''
return read;
}
+
+} // namespace gem5
''')
code.write(path, "%s.cc" % c_ident)
@@ -1257,6 +1272,8 @@
port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident)
code('''
+namespace gem5
+{
void
${ident}_Controller::wakeup()
@@ -1332,6 +1349,8 @@
break;
}
}
+
+} // namespace gem5
''')
code.write(path, "%s_Wakeup.cc" % self.ident)
@@ -1363,6 +1382,9 @@
#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str())
#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str(""))
+namespace gem5
+{
+
TransitionResult
${ident}_Controller::doTransition(${ident}_Event event,
''')
@@ -1590,6 +1612,8 @@
return TransitionResult_Valid;
}
+
+} // namespace gem5
''')
code.write(path, "%s_Transitions.cc" % self.ident)
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index da6460b..b10e583 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -228,6 +228,11 @@
code('#include "mem/ruby/protocol/$0.hh"', self["interface"])
parent = " : public %s" % self["interface"]
+ code('')
+ code('namespace gem5')
+ code('{')
+ code('')
+
code('''
$klass ${{self.c_ident}}$parent
{
@@ -387,14 +392,16 @@
code('};')
code('''
-inline std::ostream&
-operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
+inline ::std::ostream&
+operator<<(::std::ostream& out, const ${{self.c_ident}}& obj)
{
obj.print(out);
- out << std::flush;
+ out << ::std::flush;
return out;
}
+} // namespace gem5
+
#endif // __${{self.c_ident}}_HH__
''')
@@ -416,6 +423,11 @@
#include "mem/ruby/system/RubySystem.hh"
''')
+ code('')
+ code('namespace gem5')
+ code('{')
+ code('')
+
code('''
/** \\brief Print the state of this object */
void
@@ -444,6 +456,10 @@
for item in self.methods:
code(self.methods[item].generateCode())
+ code('')
+ code('} // namespace gem5')
+ code('')
+
code.write(path, "%s.cc" % self.c_ident)
def printEnumHH(self, path):
@@ -469,6 +485,13 @@
code('#include "base/logging.hh"')
code('#include "mem/ruby/common/Address.hh"')
code('#include "mem/ruby/common/TypeDefines.hh"')
+
+ code('')
+ code('namespace gem5')
+ code('{')
+ code('')
+
+ if self.isMachineType:
code('struct MachineID;')
code('''
@@ -496,30 +519,15 @@
};
// Code to convert from a string to the enumeration
-${{self.c_ident}} string_to_${{self.c_ident}}(const std::string& str);
+${{self.c_ident}} string_to_${{self.c_ident}}(const ::std::string& str);
// Code to convert state to a string
-std::string ${{self.c_ident}}_to_string(const ${{self.c_ident}}& obj);
+::std::string ${{self.c_ident}}_to_string(const ${{self.c_ident}}& obj);
// Code to increment an enumeration type
${{self.c_ident}} &operator++(${{self.c_ident}} &e);
''')
- if self.isMachineType:
- code('''
-
-// define a hash function for the MachineType class
-namespace std {
-template<>
-struct hash<MachineType>
-{
- std::size_t operator()(const MachineType &mtype) const {
- return hash<size_t>()(static_cast<size_t>(mtype));
- }
-};
-}
-
-''')
# MachineType hack used to set the base component id for each
Machine
if self.isMachineType:
code('''
@@ -543,9 +551,32 @@
''')
+ code('')
+ code('} // namespace gem5')
+ code('')
+
+ if self.isMachineType:
+ code('''
+
+// define a hash function for the MachineType class
+namespace std {
+template<>
+struct hash<gem5::MachineType>
+{
+ std::size_t
+ operator()(const gem5::MachineType &mtype) const
+ {
+ return hash<size_t>()(static_cast<size_t>(mtype));
+ }
+};
+}
+
+''')
+
# Trailer
code('''
-std::ostream& operator<<(std::ostream& out, const ${{self.c_ident}}& obj);
+std::ostream&
+operator<<(std::ostream& out, const gem5::${{self.c_ident}}& obj);
#endif // __${{self.c_ident}}_HH__
''')
@@ -571,6 +602,9 @@
if self.isStateDecl:
code('''
+namespace gem5
+{
+
// Code to convert the current state to an access permission
AccessPermission ${{self.c_ident}}_to_permission(const ${{self.c_ident}}&
obj)
{
@@ -589,6 +623,8 @@
return AccessPermission_Invalid;
}
+} // namespace gem5
+
''')
if self.isMachineType:
@@ -599,12 +635,15 @@
code('#include "mem/ruby/common/MachineID.hh"')
code('''
+namespace gem5
+{
+
// Code for output operator
-std::ostream&
-operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
+::std::ostream&
+operator<<(::std::ostream& out, const ${{self.c_ident}}& obj)
{
out << ${{self.c_ident}}_to_string(obj);
- out << std::flush;
+ out << ::std::flush;
return out;
}
@@ -790,6 +829,10 @@
}
''')
+ code('')
+ code('} // namespace gem5')
+ code('')
+
# Write the file
code.write(path, "%s.cc" % self.c_ident)
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index e98baaf..993e655 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -135,6 +135,9 @@
end_of_decl = ';'
code('#include "sim/cxx_config.hh"')
code()
+ code('namespace gem5')
+ code('{')
+ code()
code('class ${param_class} : public CxxConfigParams,'
' public ${name}Params')
code('{')
@@ -161,6 +164,8 @@
code('#include "base/str.hh"')
code('#include "cxx_config/${name}.hh"')
+ code('namespace gem5')
+ code('{')
code()
code('${member_prefix}DirectoryEntry::DirectoryEntry()');
code('{')
@@ -384,6 +389,8 @@
code.dedent()
code('};')
+ code('} // namespace gem5')
+
# The metaclass for SimObject. This class controls how new classes
# that derive from SimObject are instantiated, and provides inherited
# class behavior (just like a class controls how instances of that
@@ -805,6 +812,9 @@
code('''namespace py = pybind11;
+namespace gem5
+{
+
static void
module_init(py::module_ &m_internal)
{
@@ -872,6 +882,8 @@
code()
code('static EmbeddedPyBind embed_obj("${0}",
module_init, "${1}");',
cls, cls._base.type if cls._base else "")
+ code()
+ code('} // namespace gem5')
_warned_about_nested_templates = False
@@ -1189,6 +1201,7 @@
abstract = True
cxx_header = "sim/sim_object.hh"
+ cxx_class = 'gem5::SimObject'
cxx_extra_bases = [ "Drainable", "Serializable", "statistics::Group" ]
eventq_index = Param.UInt32(Parent.eventq_index, "Event Queue Index")
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index bcc2d96..67bba65 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -1325,6 +1325,8 @@
#ifndef $idem_macro
#define $idem_macro
+namespace gem5
+{
''')
if cls.is_class:
code('''\
@@ -1356,7 +1358,10 @@
if not cls.is_class:
code.dedent(1)
- code('};')
+ code('}; // $wrapper_name')
+
+ code()
+ code('} // namespace gem5')
code()
code('#endif // $idem_macro')
@@ -1368,6 +1373,12 @@
code('#include "base/compiler.hh"')
code('#include "enums/$file_name.hh"')
+
+ code()
+ code('namespace gem5')
+ code('{')
+ code()
+
if cls.wrapper_is_struct:
code('const char *${wrapper_name}::${name}Strings'
'[Num_${name}] =')
@@ -1392,7 +1403,9 @@
if not cls.wrapper_is_struct and not cls.is_class:
code.dedent(1)
- code('} // namespace $wrapper_name')
+ code('} // namespace enums')
+
+ code('} // namespace gem5')
def pybind_def(cls, code):
@@ -1407,6 +1420,9 @@
namespace py = pybind11;
+namespace gem5
+{
+
static void
module_init(py::module_ &m_internal)
{
@@ -1432,6 +1448,8 @@
code.dedent()
code()
code('static EmbeddedPyBind embed_enum("enum_${name}",
module_init);')
+ code()
+ code('} // namespace gem5')
# Base class for enum types.
diff --git a/util/cpt_upgrader.py b/util/cpt_upgrader.py
index ee82a7a..0cdcf4c 100755
--- a/util/cpt_upgrader.py
+++ b/util/cpt_upgrader.py
@@ -289,10 +289,15 @@
print("#include <string>")
print("#include <set>")
print()
+ print("namespace gem5")
+ print("{")
+ print()
print("std::set<std::string> version_tags = {")
for tag in Upgrader.tag_set:
print(" \"{}\",".format(tag))
print("};")
+ print()
+ print("} // namespace gem5")
exit(0)
elif not args.checkpoint:
parser.error("You must specify a checkpoint file to modify or a "
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/46328
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ie7b1204f3518ff3cd2c14798b10e983965176d4b
Gerrit-Change-Number: 46328
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s