summaryrefslogtreecommitdiff
path: root/src/python/m5
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/m5')
-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
6 files changed, 205 insertions, 34 deletions
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])