SwigSource('m5.internal', 'swig/core.i')
SwigSource('m5.internal', 'swig/debug.i')
SwigSource('m5.internal', 'swig/event.i')
+SwigSource('m5.internal', 'swig/pyobject.i')
SwigSource('m5.internal', 'swig/range.i')
SwigSource('m5.internal', 'swig/stats.i')
SwigSource('m5.internal', 'swig/trace.i')
cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
+ # Export methods are automatically inherited via C++, so we
+ # don't want the method declarations to get inherited on the
+ # python side (and thus end up getting repeated in the wrapped
+ # versions of derived classes). The code below basicallly
+ # suppresses inheritance by substituting in the base (null)
+ # versions of these methods unless a different version is
+ # explicitly supplied.
+ for method_name in ('export_methods', 'export_method_cxx_predecls',
+ 'export_method_swig_predecls'):
+ if method_name not in cls.__dict__:
+ base_method = getattr(MetaSimObject, method_name)
+ m = MethodType(base_method, cls, MetaSimObject)
+ setattr(cls, method_name, m)
+
# Now process the _value_dict items. They could be defining
# new (or overriding existing) parameters or ports, setting
# class keywords (e.g., 'abstract'), or setting parameter
def swig_predecls(cls, code):
code('%import "python/m5/internal/param_$cls.i"')
+ # Hook for exporting additional C++ methods to Python via SWIG.
+ # Default is none, override using @classmethod in class definition.
+ def export_methods(cls, code):
+ pass
+
+ # Generate the code needed as a prerequisite for the C++ methods
+ # exported via export_methods() to be compiled in the _wrap.cc
+ # file. Typically generates one or more #include statements. If
+ # any methods are exported, typically at least the C++ header
+ # declaring the relevant SimObject class must be included.
+ def export_method_cxx_predecls(cls, code):
+ pass
+
+ # Generate the code needed as a prerequisite for the C++ methods
+ # exported via export_methods() to be processed by SWIG.
+ # Typically generates one or more %include or %import statements.
+ # If any methods are exported, typically at least the C++ header
+ # declaring the relevant SimObject class must be included.
+ def export_method_swig_predecls(cls, code):
+ pass
+
# Generate the declaration for this object for wrapping with SWIG.
# Generates code that goes into a SWIG .i file. Called from
# src/SConscript.
code('#include "params/$cls.hh"')
for param in params:
param.cxx_predecls(code)
+ cls.export_method_cxx_predecls(code)
code('%}')
code()
for param in params:
param.swig_predecls(code)
+ cls.export_method_swig_predecls(code)
code()
if cls._base:
flat_name = sep_string.join(class_path)
code('%rename($flat_name) $classname;')
- if cls == SimObject:
- code('%include "python/swig/sim_object.i"')
- else:
- code()
- code('// stop swig from creating/wrapping default ctor/dtor')
- code('%nodefault $classname;')
- code('class $classname')
- if cls._base:
- code(' : public ${{cls._base.cxx_class}}')
- code('{};')
+ code()
+ code('// stop swig from creating/wrapping default ctor/dtor')
+ code('%nodefault $classname;')
+ code('class $classname')
+ if cls._base:
+ code(' : public ${{cls._base.cxx_class}}')
+ code('{')
+ code(' public:')
+ cls.export_methods(code)
+ code('};')
for ns in reversed(namespaces):
code('} // namespace $ns')
code('} // namespace $ns')
code()
+ # The base SimObject has a couple of params that get
+ # automatically set from Python without being declared through
+ # the normal Param mechanism; we slip them in here (needed
+ # predecls now, actual declarations below)
+ if cls == SimObject:
+ code('''
+#ifndef PY_VERSION
+struct PyObject;
+#endif
+
+#include <string>
+
+struct EventQueue;
+''')
for param in params:
param.cxx_predecls(code)
code()
code()
# now generate the actual param struct
+ code("struct ${cls}Params")
+ if cls._base:
+ code(" : public ${{cls._base.type}}Params")
+ code("{")
+ if not hasattr(cls, 'abstract') or not cls.abstract:
+ if 'type' in cls.__dict__:
+ code(" ${{cls.cxx_type}} create();")
+
+ code.indent()
if cls == SimObject:
- code('#include "sim/sim_object_params.hh"')
- else:
- code("struct ${cls}Params")
- if cls._base:
- code(" : public ${{cls._base.type}}Params")
- code("{")
- if not hasattr(cls, 'abstract') or not cls.abstract:
- if 'type' in cls.__dict__:
- code(" ${{cls.cxx_type}} create();")
-
- code.indent()
- for param in params:
- param.cxx_decl(code)
- code.dedent()
- code('};')
+ code('''
+ SimObjectParams()
+ {
+ extern EventQueue mainEventQueue;
+ eventq = &mainEventQueue;
+ }
+ virtual ~SimObjectParams() {}
+
+ std::string name;
+ PyObject *pyobj;
+ EventQueue *eventq;
+ ''')
+ for param in params:
+ param.cxx_decl(code)
+ code.dedent()
+ code('};')
code()
code('#endif // __PARAMS__${cls}__')
type = 'SimObject'
abstract = True
+ @classmethod
+ def export_method_cxx_predecls(cls, code):
+ code('''
+#include <Python.h>
+
+#include "sim/serialize.hh"
+#include "sim/sim_object.hh"
+''')
+
+ @classmethod
+ def export_method_swig_predecls(cls, code):
+ code('''
+%include <std_string.i>
+''')
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ enum State {
+ Running,
+ Draining,
+ Drained
+ };
+
+ void init();
+ void loadState(Checkpoint *cp);
+ void initState();
+ void regStats();
+ void regFormulas();
+ void resetStats();
+ void startup();
+
+ unsigned int drain(Event *drain_event);
+ void resume();
+ void switchOut();
+ void takeOverFrom(BaseCPU *cpu);
+''')
+
# Initialize new instance. For objects with SimObject-valued
# children, we need to recursively clone the classes represented
# by those param values as well in a consistent "deep copy"-style
# Call C++ to create corresponding port connection between C++ objects
def ccConnect(self):
- from m5.internal.params import connectPorts
+ from m5.internal.pyobject import connectPorts
if self.ccConnected: # already done this
return
--- /dev/null
+/*
+ * Copyright (c) 2006 The Regents of The University of Michigan
+ * 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
+ */
+
+%module(package="m5.internal") pyobject
+
+%{
+#include "python/swig/pyobject.hh"
+%}
+
+// import these files for SWIG to wrap
+%include <std_string.i>
+%include <stdint.i>
+
+int connectPorts(SimObject *o1, const std::string &name1, int i1,
+ SimObject *o2, const std::string &name2, int i2);
+
+%wrapper %{
+// Convert a pointer to the Python object that SWIG wraps around a
+// C++ SimObject pointer back to the actual C++ pointer.
+SimObject *
+convertSwigSimObjectPtr(PyObject *pyObj)
+{
+ SimObject *so;
+ if (SWIG_ConvertPtr(pyObj, (void **) &so, SWIGTYPE_p_SimObject, 0) == -1)
+ return NULL;
+ return so;
+}
+%}
+++ /dev/null
-/*
- * Copyright (c) 2006 The Regents of The University of Michigan
- * 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
- */
-
-%{
-#include "python/swig/pyobject.hh"
-%}
-
-// import these files for SWIG to wrap
-%include <std_string.i>
-%include <stdint.i>
-
-%include "base/types.hh"
-%include "sim/sim_object_params.hh"
-
-class BaseCPU;
-
-class SimObject {
- public:
- enum State {
- Running,
- Draining,
- Drained
- };
-
- void init();
- void loadState(Checkpoint *cp);
- void initState();
- void regStats();
- void regFormulas();
- void resetStats();
- void startup();
-
- unsigned int drain(Event *drain_event);
- void resume();
- void switchOut();
- void takeOverFrom(BaseCPU *cpu);
- SimObject(const SimObjectParams *p);
-};
-
-int connectPorts(SimObject *o1, const std::string &name1, int i1,
- SimObject *o2, const std::string &name2, int i2);
-
-%wrapper %{
-// Convert a pointer to the Python object that SWIG wraps around a
-// C++ SimObject pointer back to the actual C++ pointer.
-SimObject *
-convertSwigSimObjectPtr(PyObject *pyObj)
-{
- SimObject *so;
- if (SWIG_ConvertPtr(pyObj, (void **) &so, SWIGTYPE_p_SimObject, 0) == -1)
- return NULL;
- return so;
-}
-%}
+++ /dev/null
-/*
- * Copyright (c) 2006 The Regents of The University of Michigan
- * 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
- */
-
-%{
-#include "sim/system.hh"
-%}
-
-%import "enums/MemoryMode.hh"
-%import "python/swig/sim_object.i"
-
-class System : public SimObject
-{
- private:
- System();
- public:
- Enums::MemoryMode getMemoryMode();
- void setMemoryMode(Enums::MemoryMode mode);
-};
-
class System(SimObject):
type = 'System'
- # This method is temporarily obsolete. Its functionality will be
- # restored in a future changeset.
@classmethod
- def swig_objdecls(cls, code):
- code('%include "python/swig/system.i"')
+ def export_method_cxx_predecls(cls, code):
+ code('#include "sim/system.hh"')
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ Enums::MemoryMode getMemoryMode();
+ void setMemoryMode(Enums::MemoryMode mode);
+''')
physmem = Param.PhysicalMemory("Physical Memory")
mem_mode = Param.MemoryMode('atomic', "The mode the memory system is in")
+++ /dev/null
-/*
- * Copyright (c) 2001-2005 The Regents of The University of Michigan
- * 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: Steve Reinhardt
- * Nathan Binkert
- */
-
-#ifndef __SIM_SIM_OBJECT_PARAMS_HH__
-#define __SIM_SIM_OBJECT_PARAMS_HH__
-
-#ifndef PY_VERSION
-struct PyObject;
-#endif
-
-#include <string>
-
-struct EventQueue;
-
-struct SimObjectParams
-{
- SimObjectParams()
- {
- extern EventQueue mainEventQueue;
- eventq = &mainEventQueue;
- }
- virtual ~SimObjectParams() {}
-
- std::string name;
- PyObject *pyobj;
- EventQueue *eventq;
-};
-
-
-#endif // __SIM_SIM_OBJECT_PARAMS_HH__