summaryrefslogtreecommitdiff
path: root/src/python/swig
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2007-08-02 22:50:02 -0700
committerNathan Binkert <nate@binkert.org>2007-08-02 22:50:02 -0700
commit0536d0cde931e89d33b10228950d455dd54d8a5f (patch)
treee4d8335f239b5216942768a48d6879f184182f6c /src/python/swig
parentdc7a38dce785cf0deabb35022bb2dbfc1cc8ea3a (diff)
downloadgem5-0536d0cde931e89d33b10228950d455dd54d8a5f.tar.xz
python: Improve support for python calling back to C++ member functions.
Add support for declaring SimObjects to swig so their members can be wrapped. Make sim_object.i only contain declarations for SimObject. Create system.i to contain declarations for System. Update python code to properly call the C++ given the new changes. --HG-- extra : convert_revision : 82076ee69e8122d56e91b92d6767e356baae420a
Diffstat (limited to 'src/python/swig')
-rw-r--r--src/python/swig/core.i6
-rw-r--r--src/python/swig/pyobject.hh20
-rw-r--r--src/python/swig/sim_object.i22
-rw-r--r--src/python/swig/system.i43
4 files changed, 49 insertions, 42 deletions
diff --git a/src/python/swig/core.i b/src/python/swig/core.i
index 3edfa4c7e..8960fb228 100644
--- a/src/python/swig/core.i
+++ b/src/python/swig/core.i
@@ -58,6 +58,12 @@ void setClockFrequency(Tick ticksPerSecond);
%immutable curTick;
Tick curTick;
+void serializeAll(const std::string &cpt_dir);
+void unserializeAll(const std::string &cpt_dir);
+
+void initAll();
+void regAllStats();
+
%wrapper %{
// fix up module name to reflect the fact that it's inside the m5 package
#undef SWIG_name
diff --git a/src/python/swig/pyobject.hh b/src/python/swig/pyobject.hh
index da609e07e..8e3a96994 100644
--- a/src/python/swig/pyobject.hh
+++ b/src/python/swig/pyobject.hh
@@ -47,26 +47,6 @@ void loadIniFile(PyObject *_resolveFunc);
int connectPorts(SimObject *o1, const std::string &name1, int i1,
SimObject *o2, const std::string &name2, int i2);
-inline BaseCPU *
-convertToBaseCPUPtr(SimObject *obj)
-{
- BaseCPU *ptr = dynamic_cast<BaseCPU *>(obj);
-
- if (ptr == NULL)
- warn("Casting to BaseCPU pointer failed");
- return ptr;
-}
-
-inline System *
-convertToSystemPtr(SimObject *obj)
-{
- System *ptr = dynamic_cast<System *>(obj);
-
- if (ptr == NULL)
- warn("Casting to System pointer failed");
- return ptr;
-}
-
inline void
initAll()
{
diff --git a/src/python/swig/sim_object.i b/src/python/swig/sim_object.i
index ebd019ca3..7f71550c6 100644
--- a/src/python/swig/sim_object.i
+++ b/src/python/swig/sim_object.i
@@ -31,7 +31,6 @@
%module sim_object
%{
-#include "enums/MemoryMode.hh"
#include "python/swig/pyobject.hh"
%}
@@ -57,31 +56,10 @@ class SimObject {
SimObject(const std::string &_name);
};
-class System {
- private:
- System();
- public:
- Enums::MemoryMode getMemoryMode();
- void setMemoryMode(Enums::MemoryMode mode);
-};
-
int connectPorts(SimObject *o1, const std::string &name1, int i1,
SimObject *o2, const std::string &name2, int i2);
-BaseCPU *convertToBaseCPUPtr(SimObject *obj);
-System *convertToSystemPtr(SimObject *obj);
-
-void serializeAll(const std::string &cpt_dir);
-void unserializeAll(const std::string &cpt_dir);
-
-void initAll();
-void regAllStats();
-
%wrapper %{
-// fix up module name to reflect the fact that it's inside the m5 package
-#undef SWIG_name
-#define SWIG_name "m5.internal._sim_object"
-
// Convert a pointer to the Python object that SWIG wraps around a
// C++ SimObject pointer back to the actual C++ pointer.
SimObject *
diff --git a/src/python/swig/system.i b/src/python/swig/system.i
new file mode 100644
index 000000000..a95101bf7
--- /dev/null
+++ b/src/python/swig/system.i
@@ -0,0 +1,43 @@
+/*
+ * 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 sim_object
+
+%include "enums/MemoryMode.hh"
+
+class System : public SimObject
+{
+ private:
+ System();
+ public:
+ Enums::MemoryMode getMemoryMode();
+ void setMemoryMode(Enums::MemoryMode mode);
+};
+