I recently discovered that the old capability to have a python-only SimObject to serve solely as a configuration hierarchy node (basically a SimObject container/cluster/collection/subtree without any C++ counterpart or runtime functionality) went away at some point with Nate's restructuring. Nate and I chatted about this a bit, and it seemed like one reasonable and easy solution would be to create a "collection" object that did have a (negligible) C++ counterpart. The nice thing about this is that it maintains the (new) invariant that all python SimObjects have C++ counterparts, which seems easier than trying to hack up a special-case object in python that magically deflects all the methods that really want to go in to C++.
So here's a stab at that... there's not much code, but I figured it's the kind of thing where people might get opinionated about naming or something, or object to the basic concept, so I'd give you all a chance to chime in before I commit it. I'll put a copyright notice on the .py file before I do that... just noticed that I left that off. Steve ----- From: Steve Reinhardt <[email protected]> Add SimObjectCollection as container for SimObjects. diff -r 7d47716a1a38 src/sim/Collection.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sim/Collection.py Fri Mar 27 09:00:25 2009 -0700 @@ -0,0 +1,5 @@ +from m5.SimObject import SimObject +from m5.params import * + +class SimObjectCollection(SimObject): + type = 'SimObjectCollection' diff -r 7d47716a1a38 src/sim/SConscript --- a/src/sim/SConscript Tue Feb 17 19:23:42 2009 -0800 +++ b/src/sim/SConscript Fri Mar 27 09:00:25 2009 -0700 @@ -31,11 +31,13 @@ Import('*') SimObject('BaseTLB.py') +SimObject('Collection.py') SimObject('Root.py') SimObject('System.py') SimObject('InstTracer.py') Source('async.cc') +Source('collection.cc') Source('compile_info.cc') Source('core.cc') Source('debug.cc') diff -r 7d47716a1a38 src/sim/collection.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sim/collection.cc Fri Mar 27 09:00:25 2009 -0700 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009 Advanced Micro Devices, Inc. + * 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 + */ + +#include "sim/collection.hh" + +SimObjectCollection::SimObjectCollection(Params *p) + : SimObject(p) +{ + // nada +} + + +SimObjectCollection * +SimObjectCollectionParams::create() +{ + return new SimObjectCollection(this); +} diff -r 7d47716a1a38 src/sim/collection.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sim/collection.hh Fri Mar 27 09:00:25 2009 -0700 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2009 Advanced Micro Devices, Inc. + * 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 + */ + +#ifndef __SIM__COLLECTION_HH__ +#define __SIM__COLLECTION_HH__ + +#include "sim/sim_object.hh" +#include "params/SimObjectCollection.hh" + +class SimObjectCollection : public SimObject +{ + public: + typedef SimObjectCollectionParams Params; + + const Params * + params() const + { + return dynamic_cast<const Params *>(_params); + } + + SimObjectCollection(Params *p); +}; + + +#endif //__SIM__COLLECTION_HH__ _______________________________________________ m5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/m5-dev
