179c179
< def __init__(self, source, Werror=True, swig=False, **guards):
---
> def __init__(self, source, Werror=True, **guards):
184d183
< self.swig = swig
246,263d244
< class SwigSource(SourceFile):
< '''Add a swig file to build'''
<
< def __init__(self, package, source, **guards):
< '''Specify the python package, the source file, and any guards'''
< super(SwigSource, self).__init__(source, skip_no_python=True, **guards)
<
< modname,ext = self.extname
< assert ext == 'i'
<
< self.package = package
< self.module = modname
< cc_file = joinpath(self.dirname, modname + '_wrap.cc')
< py_file = joinpath(self.dirname, modname + '.py')
<
< self.cc_source = Source(cc_file, swig=True, parent=self, **guards)
< self.py_source = PySource(package, py_file, parent=self, **guards)
<
306d286
< Export('SwigSource')
562,574d541
< if m5.SimObject.noCxxHeader:
< print >> sys.stderr, \
< "warning: At least one SimObject lacks a header specification. " \
< "This can cause unexpected results in the generated SWIG " \
< "wrappers."
<
< # Find param types that need to be explicitly wrapped with swig.
< # These will be recognized because the ParamDesc will have a
< # swig_decl() method. Most param types are based on types that don't
< # need this, either because they're based on native types (like Int)
< # or because they're SimObjects (which get swigged independently).
< # For now the only things handled here are VectorParam types.
< params_to_swig = {}
583,588d549
< if not hasattr(param, 'swig_decl'):
< continue
< pname = param.ptype_str
< if pname not in params_to_swig:
< params_to_swig[pname] = param
<
671,680d631
< def createParamSwigWrapper(target, source, env):
< assert len(target) == 1 and len(source) == 1
<
< name = str(source[0].get_contents())
< param = params_to_swig[name]
<
< code = code_formatter()
< param.swig_decl(code)
< code.write(target[0].abspath)
<
688a640,641
> if env['USE_PYTHON']:
> obj.pybind_def(code)
701,711c654
< def createEnumSwigWrapper(target, source, env):
< assert len(target) == 1 and len(source) == 1
<
< name = str(source[0].get_contents())
< obj = all_enums[name]
<
< code = code_formatter()
< obj.swig_decl(code)
< code.write(target[0].abspath)
<
< def createSimObjectSwigWrapper(target, source, env):
---
> def createSimObjectPyBindWrapper(target, source, env):
716c659
< obj.swig_decl(code)
---
> obj.pybind_decl(code)
719,722d661
< # dummy target for generated code
< # we start out with all the Source files so they get copied to build/*/ also.
< SWIG = env.Dummy('swig', [s.tnode for s in Source.get()])
<
734d672
< env.Depends(SWIG, hh_file)
791,801d728
< # Generate any needed param SWIG wrapper files
< params_i_files = []
< for name,param in sorted(params_to_swig.iteritems()):
< i_file = File('python/_m5/%s.i' % (param.swig_module_name()))
< params_i_files.append(i_file)
< env.Command(i_file, Value(name),
< MakeAction(createParamSwigWrapper, Transform("SW PARAM")))
< env.Depends(i_file, depends)
< env.Depends(SWIG, i_file)
< SwigSource('_m5', i_file)
<
811d737
< env.Depends(SWIG, cc_file)
818d743
< env.Depends(SWIG, hh_file)
820,825c745,755
< i_file = File('python/_m5/enum_%s.i' % name)
< env.Command(i_file, Value(name),
< MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG")))
< env.Depends(i_file, depends + extra_deps)
< env.Depends(SWIG, i_file)
< SwigSource('_m5', i_file)
---
> # Generate SimObject Python bindings wrapper files
> if env['USE_PYTHON']:
> for name,simobj in sorted(sim_objects.iteritems()):
> py_source = PySource.modules[simobj.__module__]
> extra_deps = [ py_source.tnode ]
> cc_file = File('python/_m5/param_%s.cc' % name)
> env.Command(cc_file, Value(name),
> MakeAction(createSimObjectPyBindWrapper,
> Transform("SO PyBind")))
> env.Depends(cc_file, depends + extra_deps)
> Source(cc_file)
827,872d756
< # Generate SimObject SWIG wrapper files
< for name,simobj in sorted(sim_objects.iteritems()):
< py_source = PySource.modules[simobj.__module__]
< extra_deps = [ py_source.tnode ]
< i_file = File('python/_m5/param_%s.i' % name)
< env.Command(i_file, Value(name),
< MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG")))
< env.Depends(i_file, depends + extra_deps)
< SwigSource('_m5', i_file)
<
< # Generate the main swig init file
< def makeEmbeddedSwigInit(package):
< def body(target, source, env):
< assert len(target) == 1 and len(source) == 1
<
< code = code_formatter()
< module = source[0].get_contents()
< # Provide the full context so that the swig-generated call to
< # Py_InitModule ends up placing the embedded module in the
< # right package.
< context = str(package) + "._" + str(module)
< code('''\
< #include "sim/init.hh"
<
< extern "C" {
< void init_${module}();
< }
<
< EmbeddedSwig embed_swig_${module}(init_${module}, "${context}");
< ''')
< code.write(str(target[0]))
< return body
<
< # Build all swig modules
< for swig in SwigSource.all:
< env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
< MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
< '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
< cc_file = str(swig.tnode)
< init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file))
< env.Command(init_file, Value(swig.module),
< MakeAction(makeEmbeddedSwigInit(swig.package),
< Transform("EMBED SW")))
< env.Depends(SWIG, init_file)
< Source(init_file, **swig.guards)
<
885d768
< env.Depends(SWIG, [proto.cc_file, proto.hh_file])
985d867
< env.Depends(SWIG, hh_file)
989d870
< env.Depends(SWIG, 'debug/flags.cc')
1055d935
< env.Depends(SWIG, source.cpp)
1090,1095d969
< swig_env = new_env.Clone()
<
< # Both gcc and clang have issues with unused labels and values in
< # the SWIG generated code
< swig_env.Append(CCFLAGS=['-Wno-unused-label', '-Wno-unused-value'])
<
1097,1106d970
< # Depending on the SWIG version, we also need to supress
< # warnings about uninitialized variables and missing field
< # initializers.
< swig_env.Append(CCFLAGS=['-Wno-uninitialized',
< '-Wno-missing-field-initializers',
< '-Wno-unused-but-set-variable',
< '-Wno-maybe-uninitialized',
< '-Wno-type-limits'])
<
<
1128,1131d991
< swig_env.Append(CCFLAGS=['-Wno-sometimes-uninitialized',
< '-Wno-deprecated-register',
< '-Wno-tautological-compare'])
<
1161,1163c1021
< if source.swig:
< env = swig_env
< elif source.Werror:
---
> if source.Werror:
1180,1181c1038,1039
< # Without Python, leave out all SWIG and Python content from the
< # library builds. The option doesn't affect gem5 built as a program
---
> # Without Python, leave out all Python content from the library
> # builds. The option doesn't affect gem5 built as a program