summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2010-09-09 14:26:29 -0700
committerNathan Binkert <nate@binkert.org>2010-09-09 14:26:29 -0700
commit47ef97b9caad0a72751523855d145dcd96fc5738 (patch)
tree9c221cdf3826302b1a908c06ea279fe4c6d8b722 /src/python
parente6ee56c6571999631ce31b05d0e563d66a7bbdd8 (diff)
downloadgem5-47ef97b9caad0a72751523855d145dcd96fc5738.tar.xz
scons: Stop building the big monolithic swigged params module
kill params.i and create a separate .i for each object (param, enums, etc.)
Diffstat (limited to 'src/python')
-rw-r--r--src/python/SConscript5
-rw-r--r--src/python/m5/SimObject.py49
-rw-r--r--src/python/m5/internal/enums/__init__.py36
-rw-r--r--src/python/m5/internal/params/__init__.py36
-rw-r--r--src/python/m5/internal/swig/__init__.py27
-rw-r--r--src/python/m5/objects/params.py29
-rw-r--r--src/python/m5/params.py62
-rw-r--r--src/python/swig/inet.i3
-rw-r--r--src/python/swig/range.i12
-rw-r--r--src/python/swig/sim_object.i3
-rw-r--r--src/python/swig/system.i7
11 files changed, 229 insertions, 40 deletions
diff --git a/src/python/SConscript b/src/python/SConscript
index e68058f40..d995d0091 100644
--- a/src/python/SConscript
+++ b/src/python/SConscript
@@ -50,6 +50,7 @@ PySource('m5', 'm5/stats.py')
PySource('m5', 'm5/ticks.py')
PySource('m5', 'm5/trace.py')
PySource('m5.objects', 'm5/objects/__init__.py')
+PySource('m5.objects', 'm5/objects/params.py')
PySource('m5.util', 'm5/util/__init__.py')
PySource('m5.util', 'm5/util/attrdict.py')
PySource('m5.util', 'm5/util/code_formatter.py')
@@ -65,6 +66,10 @@ SwigSource('m5.internal', 'swig/core.i')
SwigSource('m5.internal', 'swig/debug.i')
SwigSource('m5.internal', 'swig/event.i')
SwigSource('m5.internal', 'swig/random.i')
+SwigSource('m5.internal', 'swig/range.i')
SwigSource('m5.internal', 'swig/stats.i')
SwigSource('m5.internal', 'swig/trace.i')
PySource('m5.internal', 'm5/internal/__init__.py')
+PySource('m5.internal.enums', 'm5/internal/enums/__init__.py')
+PySource('m5.internal.params', 'm5/internal/params/__init__.py')
+PySource('m5.internal.swig', 'm5/internal/swig/__init__.py')
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index d26a99051..e370bf8b5 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -98,15 +98,10 @@ allClasses = {}
instanceDict = {}
def default_cxx_predecls(cls, code):
- '''A forward class declaration is sufficient since we are
- just declaring a pointer.'''
+ code('#include "params/$cls.hh"')
- class_path = cls._value_dict['cxx_class'].split('::')
- for ns in class_path[:-1]:
- code('namespace $ns {')
- code('class $0;', class_path[-1])
- for ns in reversed(class_path[:-1]):
- code('/* namespace $ns */ }')
+def default_swig_predecls(cls, code):
+ code('%import "params/$cls.i"')
def default_swig_objdecls(cls, code):
class_path = cls.cxx_class.split('::')
@@ -233,7 +228,8 @@ class MetaSimObject(type):
setattr(cls, 'cxx_predecls', m)
if 'swig_predecls' not in cls.__dict__:
- setattr(cls, 'swig_predecls', getattr(cls, 'cxx_predecls'))
+ m = MethodType(default_swig_predecls, cls, MetaSimObject)
+ setattr(cls, 'swig_predecls', m)
if 'swig_objdecls' not in cls.__dict__:
m = MethodType(default_swig_objdecls, cls, MetaSimObject)
@@ -346,6 +342,15 @@ class MetaSimObject(type):
"Class %s has no parameter \'%s\'" % (cls.__name__, attr)
def __getattr__(cls, attr):
+ if attr == 'cxx_class_path':
+ return cls.cxx_class.split('::')
+
+ if attr == 'cxx_class_name':
+ return cls.cxx_class_path[-1]
+
+ if attr == 'cxx_namespaces':
+ return cls.cxx_class_path[:-1]
+
if cls._values.has_key(attr):
return cls._values[attr]
@@ -359,12 +364,6 @@ class MetaSimObject(type):
return cls.__name__
def cxx_decl(cls, code):
- code('''\
-#ifndef __PARAMS__${cls}__
-#define __PARAMS__${cls}__
-
-''')
-
# The 'dict' attribute restricts us to the params declared in
# the object itself, not including inherited params (which
# will also be inherited from the base class's param struct
@@ -377,8 +376,23 @@ class MetaSimObject(type):
print params
raise
- # get all predeclarations
- cls.cxx_predecls(code)
+ class_path = cls._value_dict['cxx_class'].split('::')
+
+ code('''\
+#ifndef __PARAMS__${cls}__
+#define __PARAMS__${cls}__
+
+''')
+
+ # A forward class declaration is sufficient since we are just
+ # declaring a pointer.
+ for ns in class_path[:-1]:
+ code('namespace $ns {')
+ code('class $0;', class_path[-1])
+ for ns in reversed(class_path[:-1]):
+ code('/* namespace $ns */ }')
+ code()
+
for param in params:
param.cxx_predecls(code)
code()
@@ -394,7 +408,6 @@ class MetaSimObject(type):
cls.cxx_struct(code, cls._base, params)
- # close #ifndef __PARAMS__* guard
code()
code('#endif // __PARAMS__${cls}__')
return code
diff --git a/src/python/m5/internal/enums/__init__.py b/src/python/m5/internal/enums/__init__.py
new file mode 100644
index 000000000..95bd61395
--- /dev/null
+++ b/src/python/m5/internal/enums/__init__.py
@@ -0,0 +1,36 @@
+# 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
+
+try:
+ modules = __loader__.modules
+except NameError:
+ modules = { }
+
+for module in modules.iterkeys():
+ if module.startswith('m5.internal.enums.'):
+ exec "from %s import *" % module
diff --git a/src/python/m5/internal/params/__init__.py b/src/python/m5/internal/params/__init__.py
new file mode 100644
index 000000000..d424298ab
--- /dev/null
+++ b/src/python/m5/internal/params/__init__.py
@@ -0,0 +1,36 @@
+# 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
+
+try:
+ modules = __loader__.modules
+except NameError:
+ modules = { }
+
+for module in modules.iterkeys():
+ if module.startswith('m5.internal.params.'):
+ exec "from %s import *" % module
diff --git a/src/python/m5/internal/swig/__init__.py b/src/python/m5/internal/swig/__init__.py
new file mode 100644
index 000000000..ac299f99c
--- /dev/null
+++ b/src/python/m5/internal/swig/__init__.py
@@ -0,0 +1,27 @@
+# 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
diff --git a/src/python/m5/objects/params.py b/src/python/m5/objects/params.py
new file mode 100644
index 000000000..4bae9fa3b
--- /dev/null
+++ b/src/python/m5/objects/params.py
@@ -0,0 +1,29 @@
+# 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.params import *
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 00bba636b..0143fe2e7 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -241,18 +241,43 @@ class VectorParamDesc(ParamDesc):
return VectorParamValue(tmp_list)
def swig_predecls(self, code):
- code('%include "${{self.ptype_str}}_vptype.i"')
+ code('%import "${{self.ptype_str}}_vptype.i"')
def swig_decl(self, code):
- cxx_type = re.sub('std::', '', self.ptype.cxx_type)
- code('%include "std_vector.i"')
+ code('%{')
+ self.ptype.cxx_predecls(code)
+ code('%}')
+ code()
self.ptype.swig_predecls(code)
+ code()
+ code('%include "std_vector.i"')
+ code()
+
+ ptype = self.ptype_str
+ cxx_type = self.ptype.cxx_type
+
code('''\
-namespace std {
-%template(vector_${{self.ptype_str}}) vector< $cxx_type >;
+%typemap(in) std::vector< $cxx_type >::value_type {
+ if (SWIG_ConvertPtr($$input, (void **)&$$1, $$1_descriptor, 0) == -1) {
+ if (SWIG_ConvertPtr($$input, (void **)&$$1,
+ $$descriptor($cxx_type), 0) == -1) {
+ return NULL;
+ }
+ }
+}
+
+%typemap(in) std::vector< $cxx_type >::value_type * {
+ if (SWIG_ConvertPtr($$input, (void **)&$$1, $$1_descriptor, 0) == -1) {
+ if (SWIG_ConvertPtr($$input, (void **)&$$1,
+ $$descriptor($cxx_type *), 0) == -1) {
+ return NULL;
+ }
+ }
}
''')
+ code('%template(vector_$ptype) std::vector< $cxx_type >;')
+
def cxx_predecls(self, code):
code('#include <vector>')
self.ptype.cxx_predecls(code)
@@ -537,18 +562,19 @@ class Range(ParamValue):
@classmethod
def cxx_predecls(cls, code):
- code('#include "base/range.hh"')
cls.type.cxx_predecls(code)
-
-class AddrRange(Range):
- type = Addr
+ code('#include "base/range.hh"')
@classmethod
def swig_predecls(cls, code):
- code('%include "python/swig/range.i"')
+ cls.type.swig_predecls(code)
+ code('%import "python/swig/range.i"')
+
+class AddrRange(Range):
+ type = Addr
def getValue(self):
- from m5.objects.params import AddrRange
+ from m5.internal.range import AddrRange
value = AddrRange()
value.start = long(self.first)
@@ -558,12 +584,8 @@ class AddrRange(Range):
class TickRange(Range):
type = Tick
- @classmethod
- def swig_predecls(cls, code):
- code('%include "python/swig/range.i"')
-
def getValue(self):
- from m5.objects.params import TickRange
+ from m5.internal.range import TickRange
value = TickRange()
value.start = long(self.first)
@@ -838,6 +860,14 @@ class Enum(ParamValue):
% (value, self.vals)
self.value = value
+ @classmethod
+ def cxx_predecls(cls, code):
+ code('#include "enums/$0.hh"', cls.__name__)
+
+ @classmethod
+ def swig_predecls(cls, code):
+ code('%import "enums/$0.i"', cls.__name__)
+
def getValue(self):
return int(self.map[self.value])
diff --git a/src/python/swig/inet.i b/src/python/swig/inet.i
index 96b4b85d0..e92b44597 100644
--- a/src/python/swig/inet.i
+++ b/src/python/swig/inet.i
@@ -32,6 +32,9 @@
#include "base/inet.hh"
%}
+%import "stdint.i"
+%import "std_string.i"
+
namespace Net {
struct EthAddr
{
diff --git a/src/python/swig/range.i b/src/python/swig/range.i
index 659bde8d7..f0cf43be4 100644
--- a/src/python/swig/range.i
+++ b/src/python/swig/range.i
@@ -28,10 +28,18 @@
* Authors: Nathan Binkert
*/
-%rename(assign) *::operator=;
+%module(package="m5.internal") range
-%include "base/range.hh"
+%{
+#include "base/range.hh"
+#include "base/types.hh"
+%}
+
+%include "stdint.i"
%include "base/types.hh"
+%rename(assign) *::operator=;
+%include "base/range.hh"
+
%template(AddrRange) Range<Addr>;
%template(TickRange) Range<Tick>;
diff --git a/src/python/swig/sim_object.i b/src/python/swig/sim_object.i
index af9afd057..76d312417 100644
--- a/src/python/swig/sim_object.i
+++ b/src/python/swig/sim_object.i
@@ -28,8 +28,6 @@
* Authors: Nathan Binkert
*/
-%module sim_object
-
%{
#include "python/swig/pyobject.hh"
%}
@@ -39,6 +37,7 @@
%include "std_string.i"
%include "base/types.hh"
+%include "sim/sim_object_params.hh"
class BaseCPU;
diff --git a/src/python/swig/system.i b/src/python/swig/system.i
index a95101bf7..5e36b4ac5 100644
--- a/src/python/swig/system.i
+++ b/src/python/swig/system.i
@@ -28,9 +28,12 @@
* Authors: Nathan Binkert
*/
-%module sim_object
+%{
+#include "sim/system.hh"
+%}
-%include "enums/MemoryMode.hh"
+%import "python/swig/sim_object.i"
+%import "enums/MemoryMode.hh"
class System : public SimObject
{