scons/swig: refactor some of the scons/SWIG code

- Move the random bits of SWIG code generation out of src/SConscript
  file and into methods on the objects being wrapped.
- Cleaned up some variable naming and added some comments to make
  the process a little clearer.
- Did a little generated file/module renaming:
   - vptype_Foo now Foo_vector
   - init_Foo is now Foo_init
  This makes it easier to see all the Foo-related files in a
  sorted directory listing.
- Made cxx_predecls and swig_predecls normal SimObject classmethods.
- Got rid of swig_objdecls hook, even though this breaks the System
  objects get/setMemoryMode method exports.  Will be fixing this in
  a future changeset.
This commit is contained in:
Steve Reinhardt
2011-10-20 13:08:49 -07:00
parent f2bfef90c4
commit 45d14e02c4
4 changed files with 153 additions and 176 deletions

View File

@@ -81,10 +81,17 @@ class MetaParamValue(type):
class ParamValue(object):
__metaclass__ = MetaParamValue
# Generate the code needed as a prerequisite for declaring a C++
# object of this type. Typically generates one or more #include
# statements. Used when declaring parameters of this type.
@classmethod
def cxx_predecls(cls, code):
pass
# Generate the code needed as a prerequisite for including a
# reference to a C++ object of this type in a SWIG .i file.
# Typically generates one or more %import or %include statements.
@classmethod
def swig_predecls(cls, code):
pass
@@ -101,8 +108,6 @@ class ParamValue(object):
# Regular parameter description.
class ParamDesc(object):
file_ext = 'ptype'
def __init__(self, ptype_str, ptype, *args, **kwargs):
self.ptype_str = ptype_str
# remember ptype only if it is provided
@@ -223,8 +228,6 @@ class SimObjectVector(VectorParamValue):
yield obj
class VectorParamDesc(ParamDesc):
file_ext = 'vptype'
# Convert assigned value to appropriate type. If the RHS is not a
# list or tuple, it generates a single-element list.
def convert(self, value):
@@ -240,10 +243,14 @@ class VectorParamDesc(ParamDesc):
else:
return VectorParamValue(tmp_list)
def swig_module_name(self):
return "%s_vector" % self.ptype_str
def swig_predecls(self, code):
code('%import "vptype_${{self.ptype_str}}.i"')
code('%import "${{self.swig_module_name()}}.i"')
def swig_decl(self, code):
code('%module(package="m5.internal") ${{self.swig_module_name()}}')
code('%{')
self.ptype.cxx_predecls(code)
code('%}')
@@ -1043,6 +1050,19 @@ namespace Enums {
} // namespace Enums
''')
def swig_decl(cls, code):
name = cls.__name__
code('''\
%module(package="m5.internal") enum_$name
%{
#include "enums/$name.hh"
%}
%include "enums/$name.hh"
''')
# Base class for enum types.
class Enum(ParamValue):
__metaclass__ = MetaEnum