From 2edfcbbaee87c1a28351fc0dcd81d52d0d9102a4 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Sun, 12 Sep 2010 15:41:34 -0700 Subject: swig: make all generated files go into the m5.internal package This is necessary because versions of swig older than 1.3.39 fail to do the right thing and try to do relative imports for everything (even with the package= option to %module). Instead of putting params in the m5.internal.params package, put params in the m5.internal package and make all param modules start with param_. Same thing for m5.internal.enums. Also, stop importing all generated params into m5.objects. They are not necessary and now with everything using relative imports we wound up with pollution of the namespace (where builtin-range got overridden). --HG-- rename : src/python/m5/internal/enums/__init__.py => src/python/m5/internal/enums.py rename : src/python/m5/internal/params/__init__.py => src/python/m5/internal/params.py --- src/SConscript | 20 ++++++++--------- src/python/SConscript | 6 ++---- src/python/m5/SimObject.py | 6 +++--- src/python/m5/internal/enums.py | 36 +++++++++++++++++++++++++++++++ src/python/m5/internal/enums/__init__.py | 36 ------------------------------- src/python/m5/internal/params.py | 36 +++++++++++++++++++++++++++++++ src/python/m5/internal/params/__init__.py | 36 ------------------------------- src/python/m5/internal/swig/__init__.py | 27 ----------------------- src/python/m5/objects/__init__.py | 4 ++-- src/python/m5/objects/params.py | 29 ------------------------- src/python/m5/params.py | 12 +++++------ 11 files changed, 95 insertions(+), 153 deletions(-) create mode 100644 src/python/m5/internal/enums.py delete mode 100644 src/python/m5/internal/enums/__init__.py create mode 100644 src/python/m5/internal/params.py delete mode 100644 src/python/m5/internal/params/__init__.py delete mode 100644 src/python/m5/internal/swig/__init__.py delete mode 100644 src/python/m5/objects/params.py diff --git a/src/SConscript b/src/SConscript index 5aa534a80..ec3f5373b 100644 --- a/src/SConscript +++ b/src/SConscript @@ -470,7 +470,7 @@ def createSwigParam(target, source, env): param = all_params[name] code = code_formatter() - code('%module(package="m5.internal.swig") ${name}_$0', param.file_ext) + code('%module(package="m5.internal") $0_${name}', param.file_ext) param.swig_decl(code) code.write(target[0].abspath) @@ -502,7 +502,7 @@ def createEnumSwig(target, source, env): code = code_formatter() code('''\ -%module(package="m5.internal.enums") $name +%module(package="m5.internal") enum_$name %{ #include "enums/$name.hh" @@ -526,11 +526,11 @@ for name,simobj in sorted(sim_objects.iteritems()): # Generate any parameter header files needed params_i_files = [] for name,param in all_params.iteritems(): - i_file = File('params/%s_%s.i' % (name, param.file_ext)) + i_file = File('python/m5/internal/%s_%s.i' % (param.file_ext, name)) params_i_files.append(i_file) env.Command(i_file, Value(name), createSwigParam) env.Depends(i_file, depends) - SwigSource('m5.internal.swig', i_file) + SwigSource('m5.internal', i_file) # Generate all enum header files for name,enum in sorted(all_enums.iteritems()): @@ -546,10 +546,10 @@ for name,enum in sorted(all_enums.iteritems()): env.Command(hh_file, Value(name), createEnumParam) env.Depends(hh_file, depends + extra_deps) - i_file = File('enums/%s.i' % name) + i_file = File('python/m5/internal/enum_%s.i' % name) env.Command(i_file, Value(name), createEnumSwig) env.Depends(i_file, depends + extra_deps) - SwigSource('m5.internal.enums', i_file) + SwigSource('m5.internal', i_file) def buildParam(target, source, env): name = source[0].get_contents() @@ -561,7 +561,7 @@ def buildParam(target, source, env): code = code_formatter() - code('%module(package="m5.internal.params") $name') + code('%module(package="m5.internal") param_$name') code() code('%{') code('#include "params/$obj.hh"') @@ -575,7 +575,7 @@ def buildParam(target, source, env): code() if obj._base: - code('%import "params/${{obj._base}}.i"') + code('%import "python/m5/internal/param_${{obj._base}}.i"') code() obj.swig_objdecls(code) code() @@ -585,10 +585,10 @@ def buildParam(target, source, env): code.write(target[0].abspath) for name in sim_objects.iterkeys(): - params_file = File('params/%s.i' % name) + params_file = File('python/m5/internal/param_%s.i' % name) env.Command(params_file, Value(name), buildParam) env.Depends(params_file, depends) - SwigSource('m5.internal.params', params_file) + SwigSource('m5.internal', params_file) # Generate the main swig init file def makeEmbeddedSwigInit(target, source, env): diff --git a/src/python/SConscript b/src/python/SConscript index d995d0091..8109e945d 100644 --- a/src/python/SConscript +++ b/src/python/SConscript @@ -50,7 +50,6 @@ 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') @@ -70,6 +69,5 @@ 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') +PySource('m5.internal', 'm5/internal/enums.py') +PySource('m5.internal', 'm5/internal/params.py') diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index e370bf8b5..471647776 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -101,7 +101,7 @@ def default_cxx_predecls(cls, code): code('#include "params/$cls.hh"') def default_swig_predecls(cls, code): - code('%import "params/$cls.i"') + code('%import "python/m5/internal/param_$cls.i"') def default_swig_objdecls(cls, code): class_path = cls.cxx_class.split('::') @@ -455,7 +455,7 @@ class MetaSimObject(type): code() if cls._base: - code('%import "params/${{cls._base.type}}.i"') + code('%import "python/m5/internal/param_${{cls._base.type}}.i"') code() for ptype in ptypes: @@ -780,7 +780,7 @@ class SimObject(object): if self._ccParams: return self._ccParams - cc_params_struct = getattr(m5.objects.params, '%sParams' % self.type) + cc_params_struct = getattr(m5.internal.params, '%sParams' % self.type) cc_params = cc_params_struct() cc_params.pyobj = self cc_params.name = str(self) diff --git a/src/python/m5/internal/enums.py b/src/python/m5/internal/enums.py new file mode 100644 index 000000000..d042a445f --- /dev/null +++ b/src/python/m5/internal/enums.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.enum_'): + exec "from %s import *" % module diff --git a/src/python/m5/internal/enums/__init__.py b/src/python/m5/internal/enums/__init__.py deleted file mode 100644 index 95bd61395..000000000 --- a/src/python/m5/internal/enums/__init__.py +++ /dev/null @@ -1,36 +0,0 @@ -# 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.py b/src/python/m5/internal/params.py new file mode 100644 index 000000000..454229bc3 --- /dev/null +++ b/src/python/m5/internal/params.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.param_'): + exec "from %s import *" % module diff --git a/src/python/m5/internal/params/__init__.py b/src/python/m5/internal/params/__init__.py deleted file mode 100644 index d424298ab..000000000 --- a/src/python/m5/internal/params/__init__.py +++ /dev/null @@ -1,36 +0,0 @@ -# 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 deleted file mode 100644 index ac299f99c..000000000 --- a/src/python/m5/internal/swig/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# 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/__init__.py b/src/python/m5/objects/__init__.py index 252ac2b17..29402c581 100644 --- a/src/python/m5/objects/__init__.py +++ b/src/python/m5/objects/__init__.py @@ -26,7 +26,7 @@ # # Authors: Nathan Binkert -from m5.objects.params import * +from m5.internal import params from m5.SimObject import * try: @@ -35,5 +35,5 @@ except NameError: modules = { } for module in modules.iterkeys(): - if module.startswith('m5.objects.') and module != 'm5.objects.params': + if module.startswith('m5.objects.'): exec "from %s import *" % module diff --git a/src/python/m5/objects/params.py b/src/python/m5/objects/params.py deleted file mode 100644 index 4bae9fa3b..000000000 --- a/src/python/m5/objects/params.py +++ /dev/null @@ -1,29 +0,0 @@ -# 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 0143fe2e7..ca75472b0 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -241,7 +241,7 @@ class VectorParamDesc(ParamDesc): return VectorParamValue(tmp_list) def swig_predecls(self, code): - code('%import "${{self.ptype_str}}_vptype.i"') + code('%import "vptype_${{self.ptype_str}}.i"') def swig_decl(self, code): code('%{') @@ -669,7 +669,7 @@ class EthernetAddr(ParamValue): return self def getValue(self): - from m5.objects.params import EthAddr + from m5.internal.params import EthAddr return EthAddr(self.value) def ini_str(self): @@ -728,7 +728,7 @@ class Time(ParamValue): self.value = parse_time(value) def getValue(self): - from m5.objects.params import tm + from m5.internal.params import tm c_time = tm() py_time = self.value @@ -835,7 +835,7 @@ extern const char *${name}Strings[Num_${name}]; def cxx_def(cls, code): name = cls.__name__ code('''\ -#include "enums/${name}.hh" +#include "enums/$name.hh" namespace Enums { const char *${name}Strings[Num_${name}] = { @@ -866,7 +866,7 @@ class Enum(ParamValue): @classmethod def swig_predecls(cls, code): - code('%import "enums/$0.i"', cls.__name__) + code('%import "python/m5/internal/enum_$0.i"', cls.__name__) def getValue(self): return int(self.map[self.value]) @@ -1168,7 +1168,7 @@ class PortRef(object): # Call C++ to create corresponding port connection between C++ objects def ccConnect(self): - from m5.objects.params import connectPorts + from m5.internal.params import connectPorts if self.ccConnected: # already done this return -- cgit v1.2.3