diff options
Diffstat (limited to 'src/python')
-rw-r--r-- | src/python/SConscript | 1 | ||||
-rw-r--r-- | src/python/m5/SimObject.py | 31 | ||||
-rw-r--r-- | src/python/m5/__init__.py | 1 | ||||
-rw-r--r-- | src/python/m5/internal/__init__.py | 1 | ||||
-rw-r--r-- | src/python/m5/simulate.py | 10 | ||||
-rw-r--r-- | src/python/swig/drain.i | 66 | ||||
-rw-r--r-- | src/python/swig/event.i | 5 | ||||
-rw-r--r-- | src/python/swig/pyevent.cc | 19 | ||||
-rw-r--r-- | src/python/swig/pyevent.hh | 3 |
9 files changed, 94 insertions, 43 deletions
diff --git a/src/python/SConscript b/src/python/SConscript index 751710665..d00432642 100644 --- a/src/python/SConscript +++ b/src/python/SConscript @@ -66,6 +66,7 @@ PySource('m5.util', 'm5/util/terminal.py') SwigSource('m5.internal', 'swig/core.i') SwigSource('m5.internal', 'swig/debug.i') +SwigSource('m5.internal', 'swig/drain.i') SwigSource('m5.internal', 'swig/event.i') SwigSource('m5.internal', 'swig/pyobject.i') SwigSource('m5.internal', 'swig/range.i') diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index c01db2a80..3aea55f5f 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -123,7 +123,8 @@ class MetaSimObject(type): 'cxx_class' : str, 'cxx_type' : str, 'cxx_header' : str, - 'type' : str } + 'type' : str, + 'cxx_bases' : list } # Attributes that can be set any time keywords = { 'check' : FunctionType } @@ -148,6 +149,8 @@ class MetaSimObject(type): value_dict[key] = val if 'abstract' not in value_dict: value_dict['abstract'] = False + if 'cxx_bases' not in value_dict: + value_dict['cxx_bases'] = [] cls_dict['_value_dict'] = value_dict cls = super(MetaSimObject, mcls).__new__(mcls, name, bases, cls_dict) if 'type' in value_dict: @@ -414,6 +417,7 @@ class MetaSimObject(type): code('%module(package="m5.internal") param_$cls') code() code('%{') + code('#include "sim/sim_object.hh"') code('#include "params/$cls.hh"') for param in params: param.cxx_predecls(code) @@ -458,7 +462,17 @@ using std::ptrdiff_t; code('%nodefault $classname;') code('class $classname') if cls._base: - code(' : public ${{cls._base.cxx_class}}') + bases = [ cls._base.cxx_class ] + cls.cxx_bases + else: + bases = cls.cxx_bases + base_first = True + for base in bases: + if base_first: + code(' : public ${{base}}') + base_first = False + else: + code(' , public ${{base}}') + code('{') code(' public:') cls.export_methods(code) @@ -581,30 +595,25 @@ class SimObject(object): abstract = True cxx_header = "sim/sim_object.hh" + cxx_bases = [ "Drainable" ] + @classmethod def export_method_swig_predecls(cls, code): code(''' %include <std_string.i> + +%import "python/swig/drain.i" ''') @classmethod def export_methods(cls, code): code(''' - enum State { - Running, - Draining, - Drained - }; - void init(); void loadState(Checkpoint *cp); void initState(); void regStats(); void resetStats(); void startup(); - - unsigned int drain(Event *drain_event); - void resume(); ''') # Initialize new instance. For objects with SimObject-valued diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 930609b6b..dc6c5a923 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -51,3 +51,4 @@ if internal: from event import * from main import main from simulate import * + diff --git a/src/python/m5/internal/__init__.py b/src/python/m5/internal/__init__.py index ca09ab468..30090549a 100644 --- a/src/python/m5/internal/__init__.py +++ b/src/python/m5/internal/__init__.py @@ -31,3 +31,4 @@ import debug import event import stats import trace +from drain import DrainManager, Drainable diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py index 89b6b1e9d..df30f654a 100644 --- a/src/python/m5/simulate.py +++ b/src/python/m5/simulate.py @@ -169,19 +169,19 @@ def doDrain(root): # be drained. def drain(root): all_drained = False - drain_event = internal.event.createCountedDrain() - unready_objs = sum(obj.drain(drain_event) for obj in root.descendants()) + dm = internal.drain.createDrainManager() + unready_objs = sum(obj.drain(dm) for obj in root.descendants()) # If we've got some objects that can't drain immediately, then simulate if unready_objs > 0: - drain_event.setCount(unready_objs) + dm.setCount(unready_objs) simulate() else: all_drained = True - internal.event.cleanupCountedDrain(drain_event) + internal.drain.cleanupDrainManager(dm) return all_drained def resume(root): - for obj in root.descendants(): obj.resume() + for obj in root.descendants(): obj.drainResume() def checkpoint(dir): root = objects.Root.getInstance() diff --git a/src/python/swig/drain.i b/src/python/swig/drain.i new file mode 100644 index 000000000..4442db207 --- /dev/null +++ b/src/python/swig/drain.i @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012 ARM Limited + * All rights reserved + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * + * 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: Andreas Sandberg + */ + +%module(package="m5.internal") drain + +%{ +#include "sim/drain.hh" +%} + +%nodefaultctor Drainable; + +%include "sim/drain.hh" + +%inline %{ + +DrainManager * +createDrainManager() +{ + return new DrainManager(); +} + +void +cleanupDrainManager(DrainManager *drain_manager) +{ + assert(drain_manager); + assert(drain_manager->getCount() == 0); + delete drain_manager; +} + +%} diff --git a/src/python/swig/event.i b/src/python/swig/event.i index 0af29e449..766dc2769 100644 --- a/src/python/swig/event.i +++ b/src/python/swig/event.i @@ -81,11 +81,6 @@ // This must follow eventq.hh %include "python/swig/pyevent.hh" -struct CountedDrainEvent : public Event -{ - void setCount(int _count); -}; - // minimal definition of SimExitEvent interface to wrap class SimLoopExitEvent : public Event { diff --git a/src/python/swig/pyevent.cc b/src/python/swig/pyevent.cc index 0695ed2d3..4651d252b 100644 --- a/src/python/swig/pyevent.cc +++ b/src/python/swig/pyevent.cc @@ -65,22 +65,3 @@ PythonEvent::process() // reference count must be decremented. Py_DECREF(object); } - -CountedDrainEvent * -createCountedDrain() -{ - return new CountedDrainEvent(); -} - -void -cleanupCountedDrain(Event *counted_drain) -{ - CountedDrainEvent *event = - dynamic_cast<CountedDrainEvent *>(counted_drain); - if (event == NULL) { - fatal("Called cleanupCountedDrain() on an event that was not " - "a CountedDrainEvent."); - } - assert(event->getCount() == 0); - delete event; -} diff --git a/src/python/swig/pyevent.hh b/src/python/swig/pyevent.hh index 9006a0404..f34fbd996 100644 --- a/src/python/swig/pyevent.hh +++ b/src/python/swig/pyevent.hh @@ -49,7 +49,4 @@ class PythonEvent : public Event virtual void process(); }; -CountedDrainEvent *createCountedDrain(); -void cleanupCountedDrain(Event *counted_drain); - #endif // __PYTHON_SWIG_PYEVENT_HH__ |