scons: Stop building the big monolithic swigged params module
kill params.i and create a separate .i for each object (param, enums, etc.)
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
36
src/python/m5/internal/enums/__init__.py
Normal file
36
src/python/m5/internal/enums/__init__.py
Normal file
@@ -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
|
||||
36
src/python/m5/internal/params/__init__.py
Normal file
36
src/python/m5/internal/params/__init__.py
Normal file
@@ -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
|
||||
27
src/python/m5/internal/swig/__init__.py
Normal file
27
src/python/m5/internal/swig/__init__.py
Normal file
@@ -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
|
||||
29
src/python/m5/objects/params.py
Normal file
29
src/python/m5/objects/params.py
Normal file
@@ -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 *
|
||||
@@ -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)
|
||||
code('#include "base/range.hh"')
|
||||
|
||||
@classmethod
|
||||
def swig_predecls(cls, code):
|
||||
cls.type.swig_predecls(code)
|
||||
code('%import "python/swig/range.i"')
|
||||
|
||||
class AddrRange(Range):
|
||||
type = Addr
|
||||
|
||||
@classmethod
|
||||
def swig_predecls(cls, code):
|
||||
code('%include "python/swig/range.i"')
|
||||
|
||||
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])
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
#include "base/inet.hh"
|
||||
%}
|
||||
|
||||
%import "stdint.i"
|
||||
%import "std_string.i"
|
||||
|
||||
namespace Net {
|
||||
struct EthAddr
|
||||
{
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user