192a193,206
> # 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)
>
342a357,377
> # 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
>
362a398
> cls.export_method_cxx_predecls(code)
367a404
> cls.export_method_swig_predecls(code)
383,392c420,429
< 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('};')
432a470,483
> # 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;
> ''')
446a498,506
> 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()
448,456c508,514
< 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('''
> SimObjectParams()
> {
> extern EventQueue mainEventQueue;
> eventq = &mainEventQueue;
> }
> virtual ~SimObjectParams() {}
458,462c516,523
< code.indent()
< for param in params:
< param.cxx_decl(code)
< code.dedent()
< code('};')
---
> std::string name;
> PyObject *pyobj;
> EventQueue *eventq;
> ''')
> for param in params:
> param.cxx_decl(code)
> code.dedent()
> code('};')
479a541,578
> @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);
> ''')
>