changeset be62996c95d1 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=be62996c95d1
description:
        python: Move native wrappers to the _m5 namespace

        Swig wrappers for native objects currently share the _m5.internal name
        space with Python code. This is undesirable if we ever want to switch
        from Swig to some other framework for native binding (e.g., PyBind11
        or Boost::Python). This changeset moves all of such wrappers to the
        _m5 namespace, which is now reserved for native code.

        Change-Id: I2d2bc12dbc05b57b7c5a75f072e08124413d77f3
        Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
        Reviewed-by: Curtis Dunham <curtis.dun...@arm.com>
        Reviewed-by: Jason Lowe-Power <ja...@lowepower.com>

diffstat:

 src/SConscript                   |  20 ++++++++++----------
 src/python/SConscript            |  19 ++++++++++---------
 src/python/_m5/__init__.py       |  39 +++++++++++++++++++++++++++++++++++++++
 src/python/m5/SimObject.py       |   6 +++---
 src/python/m5/__init__.py        |  11 ++++++-----
 src/python/m5/core.py            |   5 +----
 src/python/m5/debug.py           |  11 +++++------
 src/python/m5/event.py           |   8 ++++----
 src/python/m5/internal/params.py |   4 ++--
 src/python/m5/params.py          |  12 ++++++------
 src/python/m5/simulate.py        |  33 +++++++++++++++------------------
 src/python/m5/stats/__init__.py  |  20 ++++++++++----------
 src/python/m5/ticks.py           |   4 ++--
 src/python/m5/trace.py           |  12 ++----------
 src/python/swig/core.i           |   2 +-
 src/python/swig/debug.i          |   2 +-
 src/python/swig/drain.i          |   2 +-
 src/python/swig/event.i          |   2 +-
 src/python/swig/pyobject.i       |   2 +-
 src/python/swig/range.i          |   2 +-
 src/python/swig/serialize.i      |   2 +-
 src/python/swig/stats.i          |   2 +-
 src/python/swig/trace.i          |   2 +-
 src/unittest/SConscript          |   2 +-
 src/unittest/stattest.i          |   2 +-
 src/unittest/stattestmain.py     |   2 +-
 tests/configs/switcheroo.py      |   3 ++-
 27 files changed, 129 insertions(+), 102 deletions(-)

diffs (truncated from 711 to 300 lines):

diff -r cd7f3a1dbf55 -r be62996c95d1 src/SConscript
--- a/src/SConscript    Wed Nov 09 14:27:40 2016 -0600
+++ b/src/SConscript    Fri Jan 27 12:40:01 2017 +0000
@@ -483,7 +483,7 @@
         if fullname == 'm5.objects':
             return self
 
-        if fullname.startswith('m5.internal'):
+        if fullname.startswith('_m5'):
             return None
 
         source = self.modules.get(fullname, None)
@@ -588,14 +588,14 @@
 
     code = code_formatter()
     code("""
-import m5.internal
+import _m5.core
 import m5.util
 
 buildEnv = m5.util.SmartDict($build_env)
 
-compileDate = m5.internal.core.compileDate
+compileDate = _m5.core.compileDate
 _globals = globals()
-for key,val in m5.internal.core.__dict__.iteritems():
+for key,val in _m5.core.__dict__.iteritems():
     if key.startswith('flag_'):
         flag = key[5:]
         _globals[flag] = val
@@ -773,13 +773,13 @@
 # Generate any needed param SWIG wrapper files
 params_i_files = []
 for name,param in sorted(params_to_swig.iteritems()):
-    i_file = File('python/m5/internal/%s.i' % (param.swig_module_name()))
+    i_file = File('python/_m5/%s.i' % (param.swig_module_name()))
     params_i_files.append(i_file)
     env.Command(i_file, Value(name),
                 MakeAction(createParamSwigWrapper, Transform("SW PARAM")))
     env.Depends(i_file, depends)
     env.Depends(SWIG, i_file)
-    SwigSource('m5.internal', i_file)
+    SwigSource('_m5', i_file)
 
 # Generate all enum header files
 for name,enum in sorted(all_enums.iteritems()):
@@ -799,22 +799,22 @@
     env.Depends(hh_file, depends + extra_deps)
     env.Depends(SWIG, hh_file)
 
-    i_file = File('python/m5/internal/enum_%s.i' % name)
+    i_file = File('python/_m5/enum_%s.i' % name)
     env.Command(i_file, Value(name),
                 MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG")))
     env.Depends(i_file, depends + extra_deps)
     env.Depends(SWIG, i_file)
-    SwigSource('m5.internal', i_file)
+    SwigSource('_m5', i_file)
 
 # Generate SimObject SWIG wrapper files
 for name,simobj in sorted(sim_objects.iteritems()):
     py_source = PySource.modules[simobj.__module__]
     extra_deps = [ py_source.tnode ]
-    i_file = File('python/m5/internal/param_%s.i' % name)
+    i_file = File('python/_m5/param_%s.i' % name)
     env.Command(i_file, Value(name),
                 MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG")))
     env.Depends(i_file, depends + extra_deps)
-    SwigSource('m5.internal', i_file)
+    SwigSource('_m5', i_file)
 
 # Generate the main swig init file
 def makeEmbeddedSwigInit(package):
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/SConscript
--- a/src/python/SConscript     Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/SConscript     Fri Jan 27 12:40:01 2017 +0000
@@ -63,14 +63,15 @@
 PySource('m5.util', 'm5/util/sorteddict.py')
 PySource('m5.util', 'm5/util/terminal.py')
 
-SwigSource('m5.internal', 'swig/core.i')
-SwigSource('m5.internal', 'swig/debug.i')
-SwigSource('m5.internal', 'swig/drain.i')
-SwigSource('m5.internal', 'swig/event.i')
-SwigSource('m5.internal', 'swig/pyobject.i')
-SwigSource('m5.internal', 'swig/range.i')
-SwigSource('m5.internal', 'swig/serialize.i')
-SwigSource('m5.internal', 'swig/stats.i')
-SwigSource('m5.internal', 'swig/trace.i')
+PySource('_m5', '_m5/__init__.py')
+SwigSource('_m5', 'swig/core.i')
+SwigSource('_m5', 'swig/debug.i')
+SwigSource('_m5', 'swig/drain.i')
+SwigSource('_m5', 'swig/event.i')
+SwigSource('_m5', 'swig/pyobject.i')
+SwigSource('_m5', 'swig/range.i')
+SwigSource('_m5', 'swig/serialize.i')
+SwigSource('_m5', 'swig/stats.i')
+SwigSource('_m5', 'swig/trace.i')
 PySource('m5.internal', 'm5/internal/__init__.py')
 PySource('m5.internal', 'm5/internal/params.py')
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/_m5/__init__.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/python/_m5/__init__.py        Fri Jan 27 12:40:01 2017 +0000
@@ -0,0 +1,39 @@
+# Copyright (c) 2016 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Sandberg
+
+# This is a place holder to create a package for generated code. Don't
+# add any Python code in this name space.
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/m5/SimObject.py
--- a/src/python/m5/SimObject.py        Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/m5/SimObject.py        Fri Jan 27 12:40:01 2017 +0000
@@ -656,7 +656,7 @@
 
     # See ParamValue.swig_predecls for description.
     def swig_predecls(cls, code):
-        code('%import "python/m5/internal/param_$cls.i"')
+        code('%import "python/_m5/param_$cls.i"')
 
     # Hook for exporting additional C++ methods to Python via SWIG.
     # Default is none, override using @classmethod in class definition.
@@ -686,7 +686,7 @@
         params = map(lambda (k, v): v, sorted(cls._params.local.items()))
         ports = cls._ports.local
 
-        code('%module(package="m5.internal") param_$cls')
+        code('%module(package="_m5") param_$cls')
         code()
         code('%{')
         code('#include "sim/sim_object.hh"')
@@ -716,7 +716,7 @@
 
         code()
         if cls._base:
-            code('%import "python/m5/internal/param_${{cls._base}}.i"')
+            code('%import "python/_m5/param_${{cls._base}}.i"')
         code()
 
         for ns in namespaces:
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/m5/__init__.py
--- a/src/python/m5/__init__.py Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/m5/__init__.py Fri Jan 27 12:40:01 2017 +0000
@@ -32,15 +32,16 @@
 
 try:
     # Try to import something that's generated by swig
-    import internal.core
+    import _m5.core
 
     # Try to grab something from it in case demandimport is being used
-    internal.core.curTick
+    _m5.core.curTick
+    in_gem5 = True
 except ImportError:
-    # The import failed
-    internal = None
+    # The import failed, we're being called from the build system
+    in_gem5 = False
 
-if internal:
+if in_gem5:
     import SimObject
     import core
     import objects
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/m5/core.py
--- a/src/python/m5/core.py     Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/m5/core.py     Fri Jan 27 12:40:01 2017 +0000
@@ -26,7 +26,4 @@
 #
 # Authors: Nathan Binkert
 
-import internal
-
-def setOutputDir(dir):
-    internal.core.setOutputDir(dir)
+from _m5.core import setOutputDir
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/m5/debug.py
--- a/src/python/m5/debug.py    Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/m5/debug.py    Fri Jan 27 12:40:01 2017 +0000
@@ -28,10 +28,9 @@
 
 from UserDict import DictMixin
 
-import internal
-
-from internal.debug import SimpleFlag, CompoundFlag
-from internal.debug import schedBreak, setRemoteGDBPort
+import _m5.debug
+from _m5.debug import SimpleFlag, CompoundFlag
+from _m5.debug import schedBreak, setRemoteGDBPort
 from m5.util import printList
 
 def help():
@@ -61,12 +60,12 @@
         self._dict = {}
 
     def _update(self):
-        current_version = internal.debug.getAllFlagsVersion()
+        current_version = _m5.debug.getAllFlagsVersion()
         if self._version == current_version:
             return
 
         self._dict.clear()
-        for flag in internal.debug.getAllFlags():
+        for flag in _m5.debug.getAllFlags():
             self._dict[flag.name()] = flag
         self._version = current_version
 
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/m5/event.py
--- a/src/python/m5/event.py    Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/m5/event.py    Fri Jan 27 12:40:01 2017 +0000
@@ -29,9 +29,9 @@
 # Authors: Nathan Binkert
 
 import m5
-import internal.event
+import _m5.event
 
-from internal.event import PythonEvent, GlobalSimLoopExitEvent as SimExit
+from _m5.event import PythonEvent, GlobalSimLoopExitEvent as SimExit
 
 mainq = None
 
@@ -61,9 +61,9 @@
         self.eventq.schedule(self, m5.curTick() + self.period)
 
 def getEventQueue(index):
-    return internal.event.getEventQueue(index)
+    return _m5.event.getEventQueue(index)
 
 def setEventQueue(eventq):
-    internal.event.curEventQueue(eventq)
+    _m5.event.curEventQueue(eventq)
 
 __all__ = [ 'create', 'Event', 'ProgressEvent', 'SimExit', 'mainq' ]
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/m5/internal/params.py
--- a/src/python/m5/internal/params.py  Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/m5/internal/params.py  Fri Jan 27 12:40:01 2017 +0000
@@ -32,6 +32,6 @@
     modules = { }
 
 for module in modules.iterkeys():
-    if module.startswith('m5.internal.param_') or \
-           module.startswith('m5.internal.enum_'):
+    if module.startswith('_m5.param_') or \
+           module.startswith('_m5.enum_'):
         exec "from %s import *" % module
diff -r cd7f3a1dbf55 -r be62996c95d1 src/python/m5/params.py
--- a/src/python/m5/params.py   Wed Nov 09 14:27:40 2016 -0600
+++ b/src/python/m5/params.py   Fri Jan 27 12:40:01 2017 +0000
@@ -386,7 +386,7 @@
         code('%import "${{self.swig_module_name()}}.i"')
 
     def swig_decl(self, code):
-        code('%module(package="m5.internal") ${{self.swig_module_name()}}')
+        code('%module(package="_m5") ${{self.swig_module_name()}}')
         code('%{')
         self.ptype.cxx_predecls(code)
         code('%}')
@@ -619,7 +619,7 @@
     unsigned = True
 
     def getValue(self):
-        from m5.internal.core import Cycles
+        from _m5.core import Cycles
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to