Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/2941
Change subject: scons: config: Add a SimModel source type and m5.models
package.
......................................................................
scons: config: Add a SimModel source type and m5.models package.
These are very similar to SimObject() and m5.objects, but they're in a
different namespace.
Change-Id: I3dc84620f78657af69c13ac45ec5ef9df6efea38
---
M src/SConscript
M src/python/SConscript
M src/python/m5/__init__.py
A src/python/m5/models/__init__.py
4 files changed, 75 insertions(+), 14 deletions(-)
diff --git a/src/SConscript b/src/SConscript
index 645b925..84d8374 100755
--- a/src/SConscript
+++ b/src/SConscript
@@ -211,21 +211,32 @@
PySource.tnodes[self.tnode] = self
PySource.symnames[self.symname] = self
-class SimObject(PySource):
- '''Add a SimObject python file as a python source object and add
- it to a list of sim object modules'''
+class _SimBase(PySource):
+ '''Base class shared by SimObject and SimModel'''
fixed = False
+
+ def __init__(self, package, source, **guards):
+ '''Specify the source file and any guards (automatically in
+ the m5.{package} package)'''
+ super(_SimBase, self).__init__('m5.%s' % package, source, **guards)
+ cls = self.__class__
+ if _SimBase.fixed:
+ raise AttributeError, "Too late to call %s now." % cls.name
+
+ bisect.insort_right(cls.modnames, self.modname)
+
+class SimObject(_SimBase):
modnames = []
def __init__(self, source, **guards):
- '''Specify the source file and any guards (automatically in
- the m5.objects package)'''
- super(SimObject, self).__init__('m5.objects', source, **guards)
- if self.fixed:
- raise AttributeError, "Too late to call SimObject now."
+ super(SimObject, self).__init__('objects', source, **guards)
- bisect.insort_right(SimObject.modnames, self.modname)
+class SimModel(_SimBase):
+ modnames = []
+
+ def __init__(self, source, **guards):
+ super(SimModel, self).__init__('models', source, **guards)
class SwigSource(SourceFile):
'''Add a swig file to build'''
@@ -287,6 +298,7 @@
Export('Source')
Export('PySource')
Export('SimObject')
+Export('SimModel')
Export('SwigSource')
Export('ProtoBuf')
Export('UnitTest')
@@ -456,10 +468,10 @@
########################################################################
#
-# Prevent any SimObjects from being added after this point, they
+# Prevent any SimObjects or SimModels from being added after this point,
they
# should all have been added in the SConscripts above
#
-SimObject.fixed = True
+_SimBase.fixed = True
class DictImporter(object):
'''This importer takes a dictionary of arbitrary module names that
@@ -484,11 +496,15 @@
if fullname == 'm5.objects':
return self
+ if fullname == 'm5.models':
+ return self
+
if fullname.startswith('_m5'):
return None
source = self.modules.get(fullname, None)
- if source is not None and fullname.startswith('m5.objects'):
+ if source is not None and (fullname.startswith('m5.objects') or
+ fullname.startswith('m5.models')):
return self
return None
@@ -499,7 +515,7 @@
self.installed.add(fullname)
mod.__loader__ = self
- if fullname == 'm5.objects':
+ if fullname in ('m5.objects', 'm5.models'):
mod.__path__ = fullname.split('.')
return mod
@@ -529,10 +545,12 @@
importer = DictImporter(PySource.modules)
sys.meta_path[0:0] = [ importer ]
-# import all sim objects so we can populate the all_objects list
+# import all sim objects and models so we can populate the all_objects list
# make sure that we're working with a list, then let's sort it
for modname in SimObject.modnames:
exec('from m5.objects import %s' % modname)
+for modname in SimModel.modnames:
+ exec('from m5.models import %s' % modname)
# we need to unload all of the currently imported modules so that they
# will be re-imported the next time the sconscript is run
diff --git a/src/python/SConscript b/src/python/SConscript
index c1868f4..ecb912f 100644
--- a/src/python/SConscript
+++ b/src/python/SConscript
@@ -48,6 +48,7 @@
PySource('m5', 'm5/simulate.py')
PySource('m5', 'm5/ticks.py')
PySource('m5', 'm5/trace.py')
+PySource('m5.models', 'm5/models/__init__.py')
PySource('m5.objects', 'm5/objects/__init__.py')
PySource('m5.stats', 'm5/stats/__init__.py')
PySource('m5.util', 'm5/util/__init__.py')
diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py
index 1edf933..c06574f 100644
--- a/src/python/m5/__init__.py
+++ b/src/python/m5/__init__.py
@@ -44,6 +44,7 @@
if in_gem5:
import SimObject
import core
+ import models
import objects
import params
import stats
diff --git a/src/python/m5/models/__init__.py
b/src/python/m5/models/__init__.py
new file mode 100644
index 0000000..a27037b
--- /dev/null
+++ b/src/python/m5/models/__init__.py
@@ -0,0 +1,41 @@
+# Copyright (c) 2010 The Hewlett-Packard Development Company
+# All rights reserved.
+#
+# 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: Nathan Binkert
+
+from m5.internal import params
+from m5.SimObject import *
+
+print 'Importing models...'
+
+try:
+ modules = __loader__.modules
+except NameError:
+ modules = { }
+
+for module in modules.iterkeys():
+ if module.startswith('m5.models.'):
+ exec "from %s import *" % module
--
To view, visit https://gem5-review.googlesource.com/2941
To unsubscribe, visit https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3dc84620f78657af69c13ac45ec5ef9df6efea38
Gerrit-Change-Number: 2941
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev