SimObject.py revision 10911
18840Sandreas.hansson@arm.com# Copyright (c) 2012 ARM Limited 28840Sandreas.hansson@arm.com# All rights reserved. 38840Sandreas.hansson@arm.com# 48840Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall 58840Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual 68840Sandreas.hansson@arm.com# property including but not limited to intellectual property relating 78840Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software 88840Sandreas.hansson@arm.com# licensed hereunder. You may use the software subject to the license 98840Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated 108840Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software, 118840Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form. 128840Sandreas.hansson@arm.com# 132740SN/A# Copyright (c) 2004-2006 The Regents of The University of Michigan 149983Sstever@gmail.com# Copyright (c) 2010-20013 Advanced Micro Devices, Inc. 159983Sstever@gmail.com# Copyright (c) 2013 Mark D. Hill and David A. Wood 161046SN/A# All rights reserved. 171046SN/A# 181046SN/A# Redistribution and use in source and binary forms, with or without 191046SN/A# modification, are permitted provided that the following conditions are 201046SN/A# met: redistributions of source code must retain the above copyright 211046SN/A# notice, this list of conditions and the following disclaimer; 221046SN/A# redistributions in binary form must reproduce the above copyright 231046SN/A# notice, this list of conditions and the following disclaimer in the 241046SN/A# documentation and/or other materials provided with the distribution; 251046SN/A# neither the name of the copyright holders nor the names of its 261046SN/A# contributors may be used to endorse or promote products derived from 271046SN/A# this software without specific prior written permission. 281046SN/A# 291046SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 301046SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 311046SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 321046SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 331046SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 341046SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 351046SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 361046SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 371046SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 381046SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 391046SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665SN/A# 412665SN/A# Authors: Steve Reinhardt 422665SN/A# Nathan Binkert 438840Sandreas.hansson@arm.com# Andreas Hansson 441046SN/A 455766Snate@binkert.orgimport sys 468331Ssteve.reinhardt@amd.comfrom types import FunctionType, MethodType, ModuleType 471438SN/A 484762Snate@binkert.orgimport m5 496654Snate@binkert.orgfrom m5.util import * 503102Sstever@eecs.umich.edu 513102Sstever@eecs.umich.edu# Have to import params up top since Param is referenced on initial 523102Sstever@eecs.umich.edu# load (when SimObject class references Param to create a class 533102Sstever@eecs.umich.edu# variable, the 'name' param)... 546654Snate@binkert.orgfrom m5.params import * 553102Sstever@eecs.umich.edu# There are a few things we need that aren't in params.__all__ since 563102Sstever@eecs.umich.edu# normal users don't need them 577528Ssteve.reinhardt@amd.comfrom m5.params import ParamDesc, VectorParamDesc, \ 588839Sandreas.hansson@arm.com isNullPointer, SimObjectVector, Port 593102Sstever@eecs.umich.edu 606654Snate@binkert.orgfrom m5.proxy import * 616654Snate@binkert.orgfrom m5.proxy import isproxy 62679SN/A 63679SN/A##################################################################### 64679SN/A# 65679SN/A# M5 Python Configuration Utility 66679SN/A# 67679SN/A# The basic idea is to write simple Python programs that build Python 681692SN/A# objects corresponding to M5 SimObjects for the desired simulation 69679SN/A# configuration. For now, the Python emits a .ini file that can be 70679SN/A# parsed by M5. In the future, some tighter integration between M5 71679SN/A# and the Python interpreter may allow bypassing the .ini file. 72679SN/A# 73679SN/A# Each SimObject class in M5 is represented by a Python class with the 74679SN/A# same name. The Python inheritance tree mirrors the M5 C++ tree 75679SN/A# (e.g., SimpleCPU derives from BaseCPU in both cases, and all 76679SN/A# SimObjects inherit from a single SimObject base class). To specify 77679SN/A# an instance of an M5 SimObject in a configuration, the user simply 78679SN/A# instantiates the corresponding Python object. The parameters for 79679SN/A# that SimObject are given by assigning to attributes of the Python 80679SN/A# object, either using keyword assignment in the constructor or in 81679SN/A# separate assignment statements. For example: 82679SN/A# 831692SN/A# cache = BaseCache(size='64KB') 84679SN/A# cache.hit_latency = 3 85679SN/A# cache.assoc = 8 86679SN/A# 87679SN/A# The magic lies in the mapping of the Python attributes for SimObject 88679SN/A# classes to the actual SimObject parameter specifications. This 89679SN/A# allows parameter validity checking in the Python code. Continuing 90679SN/A# the example above, the statements "cache.blurfl=3" or 91679SN/A# "cache.assoc='hello'" would both result in runtime errors in Python, 92679SN/A# since the BaseCache object has no 'blurfl' parameter and the 'assoc' 93679SN/A# parameter requires an integer, respectively. This magic is done 94679SN/A# primarily by overriding the special __setattr__ method that controls 95679SN/A# assignment to object attributes. 96679SN/A# 97679SN/A# Once a set of Python objects have been instantiated in a hierarchy, 98679SN/A# calling 'instantiate(obj)' (where obj is the root of the hierarchy) 992740SN/A# will generate a .ini file. 100679SN/A# 101679SN/A##################################################################### 102679SN/A 1034762Snate@binkert.org# list of all SimObject classes 1044762Snate@binkert.orgallClasses = {} 1054762Snate@binkert.org 1062738SN/A# dict to look up SimObjects based on path 1072738SN/AinstanceDict = {} 1082738SN/A 1099338SAndreas.Sandberg@arm.com# Did any of the SimObjects lack a header file? 1109338SAndreas.Sandberg@arm.comnoCxxHeader = False 1119338SAndreas.Sandberg@arm.com 1127673Snate@binkert.orgdef public_value(key, value): 1137673Snate@binkert.org return key.startswith('_') or \ 1148331Ssteve.reinhardt@amd.com isinstance(value, (FunctionType, MethodType, ModuleType, 1158331Ssteve.reinhardt@amd.com classmethod, type)) 1167673Snate@binkert.org 11710458Sandreas.hansson@arm.comdef createCxxConfigDirectoryEntryFile(code, name, simobj, is_header): 11810458Sandreas.hansson@arm.com entry_class = 'CxxConfigDirectoryEntry_%s' % name 11910458Sandreas.hansson@arm.com param_class = '%sCxxConfigParams' % name 12010458Sandreas.hansson@arm.com 12110458Sandreas.hansson@arm.com code('#include "params/%s.hh"' % name) 12210458Sandreas.hansson@arm.com 12310458Sandreas.hansson@arm.com if not is_header: 12410458Sandreas.hansson@arm.com for param in simobj._params.values(): 12510458Sandreas.hansson@arm.com if isSimObjectClass(param.ptype): 12610458Sandreas.hansson@arm.com code('#include "%s"' % param.ptype._value_dict['cxx_header']) 12710458Sandreas.hansson@arm.com code('#include "params/%s.hh"' % param.ptype.__name__) 12810458Sandreas.hansson@arm.com else: 12910458Sandreas.hansson@arm.com param.ptype.cxx_ini_predecls(code) 13010458Sandreas.hansson@arm.com 13110458Sandreas.hansson@arm.com if is_header: 13210458Sandreas.hansson@arm.com member_prefix = '' 13310458Sandreas.hansson@arm.com end_of_decl = ';' 13410458Sandreas.hansson@arm.com code('#include "sim/cxx_config.hh"') 13510458Sandreas.hansson@arm.com code() 13610458Sandreas.hansson@arm.com code('class ${param_class} : public CxxConfigParams,' 13710458Sandreas.hansson@arm.com ' public ${name}Params') 13810458Sandreas.hansson@arm.com code('{') 13910458Sandreas.hansson@arm.com code(' private:') 14010458Sandreas.hansson@arm.com code.indent() 14110458Sandreas.hansson@arm.com code('class DirectoryEntry : public CxxConfigDirectoryEntry') 14210458Sandreas.hansson@arm.com code('{') 14310458Sandreas.hansson@arm.com code(' public:') 14410458Sandreas.hansson@arm.com code.indent() 14510458Sandreas.hansson@arm.com code('DirectoryEntry();'); 14610458Sandreas.hansson@arm.com code() 14710458Sandreas.hansson@arm.com code('CxxConfigParams *makeParamsObject() const') 14810458Sandreas.hansson@arm.com code('{ return new ${param_class}; }') 14910458Sandreas.hansson@arm.com code.dedent() 15010458Sandreas.hansson@arm.com code('};') 15110458Sandreas.hansson@arm.com code() 15210458Sandreas.hansson@arm.com code.dedent() 15310458Sandreas.hansson@arm.com code(' public:') 15410458Sandreas.hansson@arm.com code.indent() 15510458Sandreas.hansson@arm.com else: 15610458Sandreas.hansson@arm.com member_prefix = '%s::' % param_class 15710458Sandreas.hansson@arm.com end_of_decl = '' 15810458Sandreas.hansson@arm.com code('#include "%s"' % simobj._value_dict['cxx_header']) 15910458Sandreas.hansson@arm.com code('#include "base/str.hh"') 16010458Sandreas.hansson@arm.com code('#include "cxx_config/${name}.hh"') 16110458Sandreas.hansson@arm.com 16210458Sandreas.hansson@arm.com if simobj._ports.values() != []: 16310458Sandreas.hansson@arm.com code('#include "mem/mem_object.hh"') 16410458Sandreas.hansson@arm.com code('#include "mem/port.hh"') 16510458Sandreas.hansson@arm.com 16610458Sandreas.hansson@arm.com code() 16710458Sandreas.hansson@arm.com code('${member_prefix}DirectoryEntry::DirectoryEntry()'); 16810458Sandreas.hansson@arm.com code('{') 16910458Sandreas.hansson@arm.com 17010458Sandreas.hansson@arm.com def cxx_bool(b): 17110458Sandreas.hansson@arm.com return 'true' if b else 'false' 17210458Sandreas.hansson@arm.com 17310458Sandreas.hansson@arm.com code.indent() 17410458Sandreas.hansson@arm.com for param in simobj._params.values(): 17510458Sandreas.hansson@arm.com is_vector = isinstance(param, m5.params.VectorParamDesc) 17610458Sandreas.hansson@arm.com is_simobj = issubclass(param.ptype, m5.SimObject.SimObject) 17710458Sandreas.hansson@arm.com 17810458Sandreas.hansson@arm.com code('parameters["%s"] = new ParamDesc("%s", %s, %s);' % 17910458Sandreas.hansson@arm.com (param.name, param.name, cxx_bool(is_vector), 18010458Sandreas.hansson@arm.com cxx_bool(is_simobj))); 18110458Sandreas.hansson@arm.com 18210458Sandreas.hansson@arm.com for port in simobj._ports.values(): 18310458Sandreas.hansson@arm.com is_vector = isinstance(port, m5.params.VectorPort) 18410458Sandreas.hansson@arm.com is_master = port.role == 'MASTER' 18510458Sandreas.hansson@arm.com 18610458Sandreas.hansson@arm.com code('ports["%s"] = new PortDesc("%s", %s, %s);' % 18710458Sandreas.hansson@arm.com (port.name, port.name, cxx_bool(is_vector), 18810458Sandreas.hansson@arm.com cxx_bool(is_master))) 18910458Sandreas.hansson@arm.com 19010458Sandreas.hansson@arm.com code.dedent() 19110458Sandreas.hansson@arm.com code('}') 19210458Sandreas.hansson@arm.com code() 19310458Sandreas.hansson@arm.com 19410458Sandreas.hansson@arm.com code('bool ${member_prefix}setSimObject(const std::string &name,') 19510458Sandreas.hansson@arm.com code(' SimObject *simObject)${end_of_decl}') 19610458Sandreas.hansson@arm.com 19710458Sandreas.hansson@arm.com if not is_header: 19810458Sandreas.hansson@arm.com code('{') 19910458Sandreas.hansson@arm.com code.indent() 20010458Sandreas.hansson@arm.com code('bool ret = true;') 20110458Sandreas.hansson@arm.com code() 20210458Sandreas.hansson@arm.com code('if (false) {') 20310458Sandreas.hansson@arm.com for param in simobj._params.values(): 20410458Sandreas.hansson@arm.com is_vector = isinstance(param, m5.params.VectorParamDesc) 20510458Sandreas.hansson@arm.com is_simobj = issubclass(param.ptype, m5.SimObject.SimObject) 20610458Sandreas.hansson@arm.com 20710458Sandreas.hansson@arm.com if is_simobj and not is_vector: 20810458Sandreas.hansson@arm.com code('} else if (name == "${{param.name}}") {') 20910458Sandreas.hansson@arm.com code.indent() 21010458Sandreas.hansson@arm.com code('this->${{param.name}} = ' 21110458Sandreas.hansson@arm.com 'dynamic_cast<${{param.ptype.cxx_type}}>(simObject);') 21210458Sandreas.hansson@arm.com code('if (simObject && !this->${{param.name}})') 21310458Sandreas.hansson@arm.com code(' ret = false;') 21410458Sandreas.hansson@arm.com code.dedent() 21510458Sandreas.hansson@arm.com code('} else {') 21610458Sandreas.hansson@arm.com code(' ret = false;') 21710458Sandreas.hansson@arm.com code('}') 21810458Sandreas.hansson@arm.com code() 21910458Sandreas.hansson@arm.com code('return ret;') 22010458Sandreas.hansson@arm.com code.dedent() 22110458Sandreas.hansson@arm.com code('}') 22210458Sandreas.hansson@arm.com 22310458Sandreas.hansson@arm.com code() 22410458Sandreas.hansson@arm.com code('bool ${member_prefix}setSimObjectVector(' 22510458Sandreas.hansson@arm.com 'const std::string &name,') 22610458Sandreas.hansson@arm.com code(' const std::vector<SimObject *> &simObjects)${end_of_decl}') 22710458Sandreas.hansson@arm.com 22810458Sandreas.hansson@arm.com if not is_header: 22910458Sandreas.hansson@arm.com code('{') 23010458Sandreas.hansson@arm.com code.indent() 23110458Sandreas.hansson@arm.com code('bool ret = true;') 23210458Sandreas.hansson@arm.com code() 23310458Sandreas.hansson@arm.com code('if (false) {') 23410458Sandreas.hansson@arm.com for param in simobj._params.values(): 23510458Sandreas.hansson@arm.com is_vector = isinstance(param, m5.params.VectorParamDesc) 23610458Sandreas.hansson@arm.com is_simobj = issubclass(param.ptype, m5.SimObject.SimObject) 23710458Sandreas.hansson@arm.com 23810458Sandreas.hansson@arm.com if is_simobj and is_vector: 23910458Sandreas.hansson@arm.com code('} else if (name == "${{param.name}}") {') 24010458Sandreas.hansson@arm.com code.indent() 24110458Sandreas.hansson@arm.com code('this->${{param.name}}.clear();') 24210458Sandreas.hansson@arm.com code('for (auto i = simObjects.begin(); ' 24310458Sandreas.hansson@arm.com 'ret && i != simObjects.end(); i ++)') 24410458Sandreas.hansson@arm.com code('{') 24510458Sandreas.hansson@arm.com code.indent() 24610458Sandreas.hansson@arm.com code('${{param.ptype.cxx_type}} object = ' 24710458Sandreas.hansson@arm.com 'dynamic_cast<${{param.ptype.cxx_type}}>(*i);') 24810458Sandreas.hansson@arm.com code('if (*i && !object)') 24910458Sandreas.hansson@arm.com code(' ret = false;') 25010458Sandreas.hansson@arm.com code('else') 25110458Sandreas.hansson@arm.com code(' this->${{param.name}}.push_back(object);') 25210458Sandreas.hansson@arm.com code.dedent() 25310458Sandreas.hansson@arm.com code('}') 25410458Sandreas.hansson@arm.com code.dedent() 25510458Sandreas.hansson@arm.com code('} else {') 25610458Sandreas.hansson@arm.com code(' ret = false;') 25710458Sandreas.hansson@arm.com code('}') 25810458Sandreas.hansson@arm.com code() 25910458Sandreas.hansson@arm.com code('return ret;') 26010458Sandreas.hansson@arm.com code.dedent() 26110458Sandreas.hansson@arm.com code('}') 26210458Sandreas.hansson@arm.com 26310458Sandreas.hansson@arm.com code() 26410458Sandreas.hansson@arm.com code('void ${member_prefix}setName(const std::string &name_)' 26510458Sandreas.hansson@arm.com '${end_of_decl}') 26610458Sandreas.hansson@arm.com 26710458Sandreas.hansson@arm.com if not is_header: 26810458Sandreas.hansson@arm.com code('{') 26910458Sandreas.hansson@arm.com code.indent() 27010458Sandreas.hansson@arm.com code('this->name = name_;') 27110458Sandreas.hansson@arm.com code('this->pyobj = NULL;') 27210458Sandreas.hansson@arm.com code.dedent() 27310458Sandreas.hansson@arm.com code('}') 27410458Sandreas.hansson@arm.com 27510458Sandreas.hansson@arm.com if is_header: 27610458Sandreas.hansson@arm.com code('const std::string &${member_prefix}getName()') 27710458Sandreas.hansson@arm.com code('{ return this->name; }') 27810458Sandreas.hansson@arm.com 27910458Sandreas.hansson@arm.com code() 28010458Sandreas.hansson@arm.com code('bool ${member_prefix}setParam(const std::string &name,') 28110458Sandreas.hansson@arm.com code(' const std::string &value, const Flags flags)${end_of_decl}') 28210458Sandreas.hansson@arm.com 28310458Sandreas.hansson@arm.com if not is_header: 28410458Sandreas.hansson@arm.com code('{') 28510458Sandreas.hansson@arm.com code.indent() 28610458Sandreas.hansson@arm.com code('bool ret = true;') 28710458Sandreas.hansson@arm.com code() 28810458Sandreas.hansson@arm.com code('if (false) {') 28910458Sandreas.hansson@arm.com for param in simobj._params.values(): 29010458Sandreas.hansson@arm.com is_vector = isinstance(param, m5.params.VectorParamDesc) 29110458Sandreas.hansson@arm.com is_simobj = issubclass(param.ptype, m5.SimObject.SimObject) 29210458Sandreas.hansson@arm.com 29310458Sandreas.hansson@arm.com if not is_simobj and not is_vector: 29410458Sandreas.hansson@arm.com code('} else if (name == "${{param.name}}") {') 29510458Sandreas.hansson@arm.com code.indent() 29610458Sandreas.hansson@arm.com param.ptype.cxx_ini_parse(code, 29710458Sandreas.hansson@arm.com 'value', 'this->%s' % param.name, 'ret =') 29810458Sandreas.hansson@arm.com code.dedent() 29910458Sandreas.hansson@arm.com code('} else {') 30010458Sandreas.hansson@arm.com code(' ret = false;') 30110458Sandreas.hansson@arm.com code('}') 30210458Sandreas.hansson@arm.com code() 30310458Sandreas.hansson@arm.com code('return ret;') 30410458Sandreas.hansson@arm.com code.dedent() 30510458Sandreas.hansson@arm.com code('}') 30610458Sandreas.hansson@arm.com 30710458Sandreas.hansson@arm.com code() 30810458Sandreas.hansson@arm.com code('bool ${member_prefix}setParamVector(' 30910458Sandreas.hansson@arm.com 'const std::string &name,') 31010458Sandreas.hansson@arm.com code(' const std::vector<std::string> &values,') 31110458Sandreas.hansson@arm.com code(' const Flags flags)${end_of_decl}') 31210458Sandreas.hansson@arm.com 31310458Sandreas.hansson@arm.com if not is_header: 31410458Sandreas.hansson@arm.com code('{') 31510458Sandreas.hansson@arm.com code.indent() 31610458Sandreas.hansson@arm.com code('bool ret = true;') 31710458Sandreas.hansson@arm.com code() 31810458Sandreas.hansson@arm.com code('if (false) {') 31910458Sandreas.hansson@arm.com for param in simobj._params.values(): 32010458Sandreas.hansson@arm.com is_vector = isinstance(param, m5.params.VectorParamDesc) 32110458Sandreas.hansson@arm.com is_simobj = issubclass(param.ptype, m5.SimObject.SimObject) 32210458Sandreas.hansson@arm.com 32310458Sandreas.hansson@arm.com if not is_simobj and is_vector: 32410458Sandreas.hansson@arm.com code('} else if (name == "${{param.name}}") {') 32510458Sandreas.hansson@arm.com code.indent() 32610458Sandreas.hansson@arm.com code('${{param.name}}.clear();') 32710458Sandreas.hansson@arm.com code('for (auto i = values.begin(); ' 32810458Sandreas.hansson@arm.com 'ret && i != values.end(); i ++)') 32910458Sandreas.hansson@arm.com code('{') 33010458Sandreas.hansson@arm.com code.indent() 33110458Sandreas.hansson@arm.com code('${{param.ptype.cxx_type}} elem;') 33210458Sandreas.hansson@arm.com param.ptype.cxx_ini_parse(code, 33310458Sandreas.hansson@arm.com '*i', 'elem', 'ret =') 33410458Sandreas.hansson@arm.com code('if (ret)') 33510458Sandreas.hansson@arm.com code(' this->${{param.name}}.push_back(elem);') 33610458Sandreas.hansson@arm.com code.dedent() 33710458Sandreas.hansson@arm.com code('}') 33810458Sandreas.hansson@arm.com code.dedent() 33910458Sandreas.hansson@arm.com code('} else {') 34010458Sandreas.hansson@arm.com code(' ret = false;') 34110458Sandreas.hansson@arm.com code('}') 34210458Sandreas.hansson@arm.com code() 34310458Sandreas.hansson@arm.com code('return ret;') 34410458Sandreas.hansson@arm.com code.dedent() 34510458Sandreas.hansson@arm.com code('}') 34610458Sandreas.hansson@arm.com 34710458Sandreas.hansson@arm.com code() 34810458Sandreas.hansson@arm.com code('bool ${member_prefix}setPortConnectionCount(' 34910458Sandreas.hansson@arm.com 'const std::string &name,') 35010458Sandreas.hansson@arm.com code(' unsigned int count)${end_of_decl}') 35110458Sandreas.hansson@arm.com 35210458Sandreas.hansson@arm.com if not is_header: 35310458Sandreas.hansson@arm.com code('{') 35410458Sandreas.hansson@arm.com code.indent() 35510458Sandreas.hansson@arm.com code('bool ret = true;') 35610458Sandreas.hansson@arm.com code() 35710458Sandreas.hansson@arm.com code('if (false)') 35810458Sandreas.hansson@arm.com code(' ;') 35910458Sandreas.hansson@arm.com for port in simobj._ports.values(): 36010458Sandreas.hansson@arm.com code('else if (name == "${{port.name}}")') 36110458Sandreas.hansson@arm.com code(' this->port_${{port.name}}_connection_count = count;') 36210458Sandreas.hansson@arm.com code('else') 36310458Sandreas.hansson@arm.com code(' ret = false;') 36410458Sandreas.hansson@arm.com code() 36510458Sandreas.hansson@arm.com code('return ret;') 36610458Sandreas.hansson@arm.com code.dedent() 36710458Sandreas.hansson@arm.com code('}') 36810458Sandreas.hansson@arm.com 36910458Sandreas.hansson@arm.com code() 37010458Sandreas.hansson@arm.com code('SimObject *${member_prefix}simObjectCreate()${end_of_decl}') 37110458Sandreas.hansson@arm.com 37210458Sandreas.hansson@arm.com if not is_header: 37310458Sandreas.hansson@arm.com code('{') 37410458Sandreas.hansson@arm.com if hasattr(simobj, 'abstract') and simobj.abstract: 37510458Sandreas.hansson@arm.com code(' return NULL;') 37610458Sandreas.hansson@arm.com else: 37710458Sandreas.hansson@arm.com code(' return this->create();') 37810458Sandreas.hansson@arm.com code('}') 37910458Sandreas.hansson@arm.com 38010458Sandreas.hansson@arm.com if is_header: 38110458Sandreas.hansson@arm.com code() 38210458Sandreas.hansson@arm.com code('static CxxConfigDirectoryEntry' 38310458Sandreas.hansson@arm.com ' *${member_prefix}makeDirectoryEntry()') 38410458Sandreas.hansson@arm.com code('{ return new DirectoryEntry; }') 38510458Sandreas.hansson@arm.com 38610458Sandreas.hansson@arm.com if is_header: 38710458Sandreas.hansson@arm.com code.dedent() 38810458Sandreas.hansson@arm.com code('};') 38910458Sandreas.hansson@arm.com 3902740SN/A# The metaclass for SimObject. This class controls how new classes 3912740SN/A# that derive from SimObject are instantiated, and provides inherited 3922740SN/A# class behavior (just like a class controls how instances of that 3932740SN/A# class are instantiated, and provides inherited instance behavior). 3941692SN/Aclass MetaSimObject(type): 3951427SN/A # Attributes that can be set only at initialization time 3967493Ssteve.reinhardt@amd.com init_keywords = { 'abstract' : bool, 3977493Ssteve.reinhardt@amd.com 'cxx_class' : str, 3987493Ssteve.reinhardt@amd.com 'cxx_type' : str, 3999338SAndreas.Sandberg@arm.com 'cxx_header' : str, 4009342SAndreas.Sandberg@arm.com 'type' : str, 4019342SAndreas.Sandberg@arm.com 'cxx_bases' : list } 4021427SN/A # Attributes that can be set any time 4037493Ssteve.reinhardt@amd.com keywords = { 'check' : FunctionType } 404679SN/A 405679SN/A # __new__ is called before __init__, and is where the statements 406679SN/A # in the body of the class definition get loaded into the class's 4072740SN/A # __dict__. We intercept this to filter out parameter & port assignments 408679SN/A # and only allow "private" attributes to be passed to the base 409679SN/A # __new__ (starting with underscore). 4101310SN/A def __new__(mcls, name, bases, dict): 4116654Snate@binkert.org assert name not in allClasses, "SimObject %s already present" % name 4124762Snate@binkert.org 4132740SN/A # Copy "private" attributes, functions, and classes to the 4142740SN/A # official dict. Everything else goes in _init_dict to be 4152740SN/A # filtered in __init__. 4162740SN/A cls_dict = {} 4172740SN/A value_dict = {} 4182740SN/A for key,val in dict.items(): 4197673Snate@binkert.org if public_value(key, val): 4202740SN/A cls_dict[key] = val 4212740SN/A else: 4222740SN/A # must be a param/port setting 4232740SN/A value_dict[key] = val 4244762Snate@binkert.org if 'abstract' not in value_dict: 4254762Snate@binkert.org value_dict['abstract'] = False 4269342SAndreas.Sandberg@arm.com if 'cxx_bases' not in value_dict: 4279342SAndreas.Sandberg@arm.com value_dict['cxx_bases'] = [] 4282740SN/A cls_dict['_value_dict'] = value_dict 4294762Snate@binkert.org cls = super(MetaSimObject, mcls).__new__(mcls, name, bases, cls_dict) 4304762Snate@binkert.org if 'type' in value_dict: 4314762Snate@binkert.org allClasses[name] = cls 4324762Snate@binkert.org return cls 433679SN/A 4342711SN/A # subclass initialization 435679SN/A def __init__(cls, name, bases, dict): 4362711SN/A # calls type.__init__()... I think that's a no-op, but leave 4372711SN/A # it here just in case it's not. 4381692SN/A super(MetaSimObject, cls).__init__(name, bases, dict) 4391310SN/A 4401427SN/A # initialize required attributes 4412740SN/A 4422740SN/A # class-only attributes 4432740SN/A cls._params = multidict() # param descriptions 4442740SN/A cls._ports = multidict() # port descriptions 4452740SN/A 4462740SN/A # class or instance attributes 4472740SN/A cls._values = multidict() # param values 44810267SGeoffrey.Blake@arm.com cls._hr_values = multidict() # human readable param values 4497528Ssteve.reinhardt@amd.com cls._children = multidict() # SimObject children 4503105Sstever@eecs.umich.edu cls._port_refs = multidict() # port ref objects 4512740SN/A cls._instantiated = False # really instantiated, cloned, or subclassed 4521310SN/A 4539100SBrad.Beckmann@amd.com # We don't support multiple inheritance of sim objects. If you want 4549100SBrad.Beckmann@amd.com # to, you must fix multidict to deal with it properly. Non sim-objects 4559100SBrad.Beckmann@amd.com # are ok, though 4569100SBrad.Beckmann@amd.com bTotal = 0 4579100SBrad.Beckmann@amd.com for c in bases: 4589100SBrad.Beckmann@amd.com if isinstance(c, MetaSimObject): 4599100SBrad.Beckmann@amd.com bTotal += 1 4609100SBrad.Beckmann@amd.com if bTotal > 1: 4619100SBrad.Beckmann@amd.com raise TypeError, "SimObjects do not support multiple inheritance" 4621692SN/A 4631692SN/A base = bases[0] 4641692SN/A 4652740SN/A # Set up general inheritance via multidicts. A subclass will 4662740SN/A # inherit all its settings from the base class. The only time 4672740SN/A # the following is not true is when we define the SimObject 4682740SN/A # class itself (in which case the multidicts have no parent). 4691692SN/A if isinstance(base, MetaSimObject): 4705610Snate@binkert.org cls._base = base 4711692SN/A cls._params.parent = base._params 4722740SN/A cls._ports.parent = base._ports 4731692SN/A cls._values.parent = base._values 47410267SGeoffrey.Blake@arm.com cls._hr_values.parent = base._hr_values 4757528Ssteve.reinhardt@amd.com cls._children.parent = base._children 4763105Sstever@eecs.umich.edu cls._port_refs.parent = base._port_refs 4772740SN/A # mark base as having been subclassed 4782712SN/A base._instantiated = True 4795610Snate@binkert.org else: 4805610Snate@binkert.org cls._base = None 4811692SN/A 4824762Snate@binkert.org # default keyword values 4834762Snate@binkert.org if 'type' in cls._value_dict: 4844762Snate@binkert.org if 'cxx_class' not in cls._value_dict: 4855610Snate@binkert.org cls._value_dict['cxx_class'] = cls._value_dict['type'] 4864762Snate@binkert.org 4875610Snate@binkert.org cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class'] 4884859Snate@binkert.org 4899338SAndreas.Sandberg@arm.com if 'cxx_header' not in cls._value_dict: 4909338SAndreas.Sandberg@arm.com global noCxxHeader 4919338SAndreas.Sandberg@arm.com noCxxHeader = True 4929528Ssascha.bischoff@arm.com warn("No header file specified for SimObject: %s", name) 4939338SAndreas.Sandberg@arm.com 4948597Ssteve.reinhardt@amd.com # Export methods are automatically inherited via C++, so we 4958597Ssteve.reinhardt@amd.com # don't want the method declarations to get inherited on the 4968597Ssteve.reinhardt@amd.com # python side (and thus end up getting repeated in the wrapped 4978597Ssteve.reinhardt@amd.com # versions of derived classes). The code below basicallly 4988597Ssteve.reinhardt@amd.com # suppresses inheritance by substituting in the base (null) 4998597Ssteve.reinhardt@amd.com # versions of these methods unless a different version is 5008597Ssteve.reinhardt@amd.com # explicitly supplied. 5018597Ssteve.reinhardt@amd.com for method_name in ('export_methods', 'export_method_cxx_predecls', 5028597Ssteve.reinhardt@amd.com 'export_method_swig_predecls'): 5038597Ssteve.reinhardt@amd.com if method_name not in cls.__dict__: 5048597Ssteve.reinhardt@amd.com base_method = getattr(MetaSimObject, method_name) 5058597Ssteve.reinhardt@amd.com m = MethodType(base_method, cls, MetaSimObject) 5068597Ssteve.reinhardt@amd.com setattr(cls, method_name, m) 5078597Ssteve.reinhardt@amd.com 5082740SN/A # Now process the _value_dict items. They could be defining 5092740SN/A # new (or overriding existing) parameters or ports, setting 5102740SN/A # class keywords (e.g., 'abstract'), or setting parameter 5112740SN/A # values or port bindings. The first 3 can only be set when 5122740SN/A # the class is defined, so we handle them here. The others 5132740SN/A # can be set later too, so just emulate that by calling 5142740SN/A # setattr(). 5152740SN/A for key,val in cls._value_dict.items(): 5161527SN/A # param descriptions 5172740SN/A if isinstance(val, ParamDesc): 5181585SN/A cls._new_param(key, val) 5191427SN/A 5202738SN/A # port objects 5212738SN/A elif isinstance(val, Port): 5223105Sstever@eecs.umich.edu cls._new_port(key, val) 5232738SN/A 5241427SN/A # init-time-only keywords 5251427SN/A elif cls.init_keywords.has_key(key): 5261427SN/A cls._set_keyword(key, val, cls.init_keywords[key]) 5271427SN/A 5281427SN/A # default: use normal path (ends up in __setattr__) 5291427SN/A else: 5301427SN/A setattr(cls, key, val) 5311427SN/A 5321427SN/A def _set_keyword(cls, keyword, val, kwtype): 5331427SN/A if not isinstance(val, kwtype): 5341427SN/A raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \ 5351427SN/A (keyword, type(val), kwtype) 5367493Ssteve.reinhardt@amd.com if isinstance(val, FunctionType): 5371427SN/A val = classmethod(val) 5381427SN/A type.__setattr__(cls, keyword, val) 5391427SN/A 5403100SN/A def _new_param(cls, name, pdesc): 5413100SN/A # each param desc should be uniquely assigned to one variable 5423100SN/A assert(not hasattr(pdesc, 'name')) 5433100SN/A pdesc.name = name 5443100SN/A cls._params[name] = pdesc 5453100SN/A if hasattr(pdesc, 'default'): 5463105Sstever@eecs.umich.edu cls._set_param(name, pdesc.default, pdesc) 5473105Sstever@eecs.umich.edu 5483105Sstever@eecs.umich.edu def _set_param(cls, name, value, param): 5493105Sstever@eecs.umich.edu assert(param.name == name) 5503105Sstever@eecs.umich.edu try: 55110267SGeoffrey.Blake@arm.com hr_value = value 5528321Ssteve.reinhardt@amd.com value = param.convert(value) 5533105Sstever@eecs.umich.edu except Exception, e: 5543105Sstever@eecs.umich.edu msg = "%s\nError setting param %s.%s to %s\n" % \ 5553105Sstever@eecs.umich.edu (e, cls.__name__, name, value) 5563105Sstever@eecs.umich.edu e.args = (msg, ) 5573105Sstever@eecs.umich.edu raise 5588321Ssteve.reinhardt@amd.com cls._values[name] = value 5598321Ssteve.reinhardt@amd.com # if param value is a SimObject, make it a child too, so that 5608321Ssteve.reinhardt@amd.com # it gets cloned properly when the class is instantiated 5618321Ssteve.reinhardt@amd.com if isSimObjectOrVector(value) and not value.has_parent(): 5628321Ssteve.reinhardt@amd.com cls._add_cls_child(name, value) 56310267SGeoffrey.Blake@arm.com # update human-readable values of the param if it has a literal 56410267SGeoffrey.Blake@arm.com # value and is not an object or proxy. 56510267SGeoffrey.Blake@arm.com if not (isSimObjectOrVector(value) or\ 56610267SGeoffrey.Blake@arm.com isinstance(value, m5.proxy.BaseProxy)): 56710267SGeoffrey.Blake@arm.com cls._hr_values[name] = hr_value 5688321Ssteve.reinhardt@amd.com 5698321Ssteve.reinhardt@amd.com def _add_cls_child(cls, name, child): 5708321Ssteve.reinhardt@amd.com # It's a little funky to have a class as a parent, but these 5718321Ssteve.reinhardt@amd.com # objects should never be instantiated (only cloned, which 5728321Ssteve.reinhardt@amd.com # clears the parent pointer), and this makes it clear that the 5738321Ssteve.reinhardt@amd.com # object is not an orphan and can provide better error 5748321Ssteve.reinhardt@amd.com # messages. 5758321Ssteve.reinhardt@amd.com child.set_parent(cls, name) 5768321Ssteve.reinhardt@amd.com cls._children[name] = child 5773105Sstever@eecs.umich.edu 5783105Sstever@eecs.umich.edu def _new_port(cls, name, port): 5793105Sstever@eecs.umich.edu # each port should be uniquely assigned to one variable 5803105Sstever@eecs.umich.edu assert(not hasattr(port, 'name')) 5813105Sstever@eecs.umich.edu port.name = name 5823105Sstever@eecs.umich.edu cls._ports[name] = port 5833105Sstever@eecs.umich.edu 5843105Sstever@eecs.umich.edu # same as _get_port_ref, effectively, but for classes 5853105Sstever@eecs.umich.edu def _cls_get_port_ref(cls, attr): 5863105Sstever@eecs.umich.edu # Return reference that can be assigned to another port 5873105Sstever@eecs.umich.edu # via __setattr__. There is only ever one reference 5883105Sstever@eecs.umich.edu # object per port, but we create them lazily here. 5893105Sstever@eecs.umich.edu ref = cls._port_refs.get(attr) 5903105Sstever@eecs.umich.edu if not ref: 5913105Sstever@eecs.umich.edu ref = cls._ports[attr].makeRef(cls) 5923105Sstever@eecs.umich.edu cls._port_refs[attr] = ref 5933105Sstever@eecs.umich.edu return ref 5941585SN/A 5951310SN/A # Set attribute (called on foo.attr = value when foo is an 5961310SN/A # instance of class cls). 5971310SN/A def __setattr__(cls, attr, value): 5981310SN/A # normal processing for private attributes 5997673Snate@binkert.org if public_value(attr, value): 6001310SN/A type.__setattr__(cls, attr, value) 6011310SN/A return 6021310SN/A 6031310SN/A if cls.keywords.has_key(attr): 6041427SN/A cls._set_keyword(attr, value, cls.keywords[attr]) 6051310SN/A return 6061310SN/A 6072738SN/A if cls._ports.has_key(attr): 6083105Sstever@eecs.umich.edu cls._cls_get_port_ref(attr).connect(value) 6092738SN/A return 6102738SN/A 6112740SN/A if isSimObjectOrSequence(value) and cls._instantiated: 6122740SN/A raise RuntimeError, \ 6132740SN/A "cannot set SimObject parameter '%s' after\n" \ 6142740SN/A " class %s has been instantiated or subclassed" \ 6152740SN/A % (attr, cls.__name__) 6162740SN/A 6172740SN/A # check for param 6183105Sstever@eecs.umich.edu param = cls._params.get(attr) 6191310SN/A if param: 6203105Sstever@eecs.umich.edu cls._set_param(attr, value, param) 6213105Sstever@eecs.umich.edu return 6223105Sstever@eecs.umich.edu 6233105Sstever@eecs.umich.edu if isSimObjectOrSequence(value): 6243105Sstever@eecs.umich.edu # If RHS is a SimObject, it's an implicit child assignment. 6258321Ssteve.reinhardt@amd.com cls._add_cls_child(attr, coerceSimObjectOrVector(value)) 6263105Sstever@eecs.umich.edu return 6273105Sstever@eecs.umich.edu 6283105Sstever@eecs.umich.edu # no valid assignment... raise exception 6293105Sstever@eecs.umich.edu raise AttributeError, \ 6303105Sstever@eecs.umich.edu "Class %s has no parameter \'%s\'" % (cls.__name__, attr) 6311310SN/A 6321585SN/A def __getattr__(cls, attr): 6337675Snate@binkert.org if attr == 'cxx_class_path': 6347675Snate@binkert.org return cls.cxx_class.split('::') 6357675Snate@binkert.org 6367675Snate@binkert.org if attr == 'cxx_class_name': 6377675Snate@binkert.org return cls.cxx_class_path[-1] 6387675Snate@binkert.org 6397675Snate@binkert.org if attr == 'cxx_namespaces': 6407675Snate@binkert.org return cls.cxx_class_path[:-1] 6417675Snate@binkert.org 6421692SN/A if cls._values.has_key(attr): 6431692SN/A return cls._values[attr] 6441585SN/A 6457528Ssteve.reinhardt@amd.com if cls._children.has_key(attr): 6467528Ssteve.reinhardt@amd.com return cls._children[attr] 6477528Ssteve.reinhardt@amd.com 6481585SN/A raise AttributeError, \ 6491585SN/A "object '%s' has no attribute '%s'" % (cls.__name__, attr) 6501585SN/A 6513100SN/A def __str__(cls): 6523100SN/A return cls.__name__ 6533100SN/A 6548596Ssteve.reinhardt@amd.com # See ParamValue.cxx_predecls for description. 6558596Ssteve.reinhardt@amd.com def cxx_predecls(cls, code): 6568596Ssteve.reinhardt@amd.com code('#include "params/$cls.hh"') 6578596Ssteve.reinhardt@amd.com 6588596Ssteve.reinhardt@amd.com # See ParamValue.swig_predecls for description. 6598596Ssteve.reinhardt@amd.com def swig_predecls(cls, code): 6608596Ssteve.reinhardt@amd.com code('%import "python/m5/internal/param_$cls.i"') 6618596Ssteve.reinhardt@amd.com 6628597Ssteve.reinhardt@amd.com # Hook for exporting additional C++ methods to Python via SWIG. 6638597Ssteve.reinhardt@amd.com # Default is none, override using @classmethod in class definition. 6648597Ssteve.reinhardt@amd.com def export_methods(cls, code): 6658597Ssteve.reinhardt@amd.com pass 6668597Ssteve.reinhardt@amd.com 6678597Ssteve.reinhardt@amd.com # Generate the code needed as a prerequisite for the C++ methods 6688597Ssteve.reinhardt@amd.com # exported via export_methods() to be compiled in the _wrap.cc 6698597Ssteve.reinhardt@amd.com # file. Typically generates one or more #include statements. If 6708597Ssteve.reinhardt@amd.com # any methods are exported, typically at least the C++ header 6718597Ssteve.reinhardt@amd.com # declaring the relevant SimObject class must be included. 6728597Ssteve.reinhardt@amd.com def export_method_cxx_predecls(cls, code): 6738597Ssteve.reinhardt@amd.com pass 6748597Ssteve.reinhardt@amd.com 6758597Ssteve.reinhardt@amd.com # Generate the code needed as a prerequisite for the C++ methods 6768597Ssteve.reinhardt@amd.com # exported via export_methods() to be processed by SWIG. 6778597Ssteve.reinhardt@amd.com # Typically generates one or more %include or %import statements. 6788597Ssteve.reinhardt@amd.com # If any methods are exported, typically at least the C++ header 6798597Ssteve.reinhardt@amd.com # declaring the relevant SimObject class must be included. 6808597Ssteve.reinhardt@amd.com def export_method_swig_predecls(cls, code): 6818597Ssteve.reinhardt@amd.com pass 6828597Ssteve.reinhardt@amd.com 6838596Ssteve.reinhardt@amd.com # Generate the declaration for this object for wrapping with SWIG. 6848596Ssteve.reinhardt@amd.com # Generates code that goes into a SWIG .i file. Called from 6858596Ssteve.reinhardt@amd.com # src/SConscript. 6868596Ssteve.reinhardt@amd.com def swig_decl(cls, code): 6878596Ssteve.reinhardt@amd.com class_path = cls.cxx_class.split('::') 6888596Ssteve.reinhardt@amd.com classname = class_path[-1] 6898596Ssteve.reinhardt@amd.com namespaces = class_path[:-1] 6908596Ssteve.reinhardt@amd.com 6918596Ssteve.reinhardt@amd.com # The 'local' attribute restricts us to the params declared in 6928596Ssteve.reinhardt@amd.com # the object itself, not including inherited params (which 6938596Ssteve.reinhardt@amd.com # will also be inherited from the base class's param struct 69410584Sandreas.hansson@arm.com # here). Sort the params based on their key 69510584Sandreas.hansson@arm.com params = map(lambda (k, v): v, sorted(cls._params.local.items())) 6968840Sandreas.hansson@arm.com ports = cls._ports.local 6978596Ssteve.reinhardt@amd.com 6988596Ssteve.reinhardt@amd.com code('%module(package="m5.internal") param_$cls') 6998596Ssteve.reinhardt@amd.com code() 7008596Ssteve.reinhardt@amd.com code('%{') 7019342SAndreas.Sandberg@arm.com code('#include "sim/sim_object.hh"') 7028596Ssteve.reinhardt@amd.com code('#include "params/$cls.hh"') 7038596Ssteve.reinhardt@amd.com for param in params: 7048596Ssteve.reinhardt@amd.com param.cxx_predecls(code) 7059338SAndreas.Sandberg@arm.com code('#include "${{cls.cxx_header}}"') 7068597Ssteve.reinhardt@amd.com cls.export_method_cxx_predecls(code) 7078860Sandreas.hansson@arm.com code('''\ 7088860Sandreas.hansson@arm.com/** 7098860Sandreas.hansson@arm.com * This is a workaround for bug in swig. Prior to gcc 4.6.1 the STL 7108860Sandreas.hansson@arm.com * headers like vector, string, etc. used to automatically pull in 7118860Sandreas.hansson@arm.com * the cstddef header but starting with gcc 4.6.1 they no longer do. 7128860Sandreas.hansson@arm.com * This leads to swig generated a file that does not compile so we 7138860Sandreas.hansson@arm.com * explicitly include cstddef. Additionally, including version 2.0.4, 7148860Sandreas.hansson@arm.com * swig uses ptrdiff_t without the std:: namespace prefix which is 7158860Sandreas.hansson@arm.com * required with gcc 4.6.1. We explicitly provide access to it. 7168860Sandreas.hansson@arm.com */ 7178860Sandreas.hansson@arm.com#include <cstddef> 7188860Sandreas.hansson@arm.comusing std::ptrdiff_t; 7198860Sandreas.hansson@arm.com''') 7208596Ssteve.reinhardt@amd.com code('%}') 7218596Ssteve.reinhardt@amd.com code() 7228596Ssteve.reinhardt@amd.com 7238596Ssteve.reinhardt@amd.com for param in params: 7248596Ssteve.reinhardt@amd.com param.swig_predecls(code) 7258597Ssteve.reinhardt@amd.com cls.export_method_swig_predecls(code) 7268596Ssteve.reinhardt@amd.com 7278596Ssteve.reinhardt@amd.com code() 7288596Ssteve.reinhardt@amd.com if cls._base: 7298596Ssteve.reinhardt@amd.com code('%import "python/m5/internal/param_${{cls._base}}.i"') 7308596Ssteve.reinhardt@amd.com code() 7318596Ssteve.reinhardt@amd.com 7328596Ssteve.reinhardt@amd.com for ns in namespaces: 7338596Ssteve.reinhardt@amd.com code('namespace $ns {') 7348596Ssteve.reinhardt@amd.com 7358596Ssteve.reinhardt@amd.com if namespaces: 7368596Ssteve.reinhardt@amd.com code('// avoid name conflicts') 7378596Ssteve.reinhardt@amd.com sep_string = '_COLONS_' 7388596Ssteve.reinhardt@amd.com flat_name = sep_string.join(class_path) 7398596Ssteve.reinhardt@amd.com code('%rename($flat_name) $classname;') 7408596Ssteve.reinhardt@amd.com 7418597Ssteve.reinhardt@amd.com code() 7428597Ssteve.reinhardt@amd.com code('// stop swig from creating/wrapping default ctor/dtor') 7438597Ssteve.reinhardt@amd.com code('%nodefault $classname;') 7448597Ssteve.reinhardt@amd.com code('class $classname') 7458597Ssteve.reinhardt@amd.com if cls._base: 7469342SAndreas.Sandberg@arm.com bases = [ cls._base.cxx_class ] + cls.cxx_bases 7479342SAndreas.Sandberg@arm.com else: 7489342SAndreas.Sandberg@arm.com bases = cls.cxx_bases 7499342SAndreas.Sandberg@arm.com base_first = True 7509342SAndreas.Sandberg@arm.com for base in bases: 7519342SAndreas.Sandberg@arm.com if base_first: 7529342SAndreas.Sandberg@arm.com code(' : public ${{base}}') 7539342SAndreas.Sandberg@arm.com base_first = False 7549342SAndreas.Sandberg@arm.com else: 7559342SAndreas.Sandberg@arm.com code(' , public ${{base}}') 7569342SAndreas.Sandberg@arm.com 7578597Ssteve.reinhardt@amd.com code('{') 7588597Ssteve.reinhardt@amd.com code(' public:') 7598597Ssteve.reinhardt@amd.com cls.export_methods(code) 7608597Ssteve.reinhardt@amd.com code('};') 7618596Ssteve.reinhardt@amd.com 7628596Ssteve.reinhardt@amd.com for ns in reversed(namespaces): 7638596Ssteve.reinhardt@amd.com code('} // namespace $ns') 7648596Ssteve.reinhardt@amd.com 7658596Ssteve.reinhardt@amd.com code() 7668596Ssteve.reinhardt@amd.com code('%include "params/$cls.hh"') 7678596Ssteve.reinhardt@amd.com 7688596Ssteve.reinhardt@amd.com 7698596Ssteve.reinhardt@amd.com # Generate the C++ declaration (.hh file) for this SimObject's 7708596Ssteve.reinhardt@amd.com # param struct. Called from src/SConscript. 7718596Ssteve.reinhardt@amd.com def cxx_param_decl(cls, code): 7728596Ssteve.reinhardt@amd.com # The 'local' attribute restricts us to the params declared in 7733100SN/A # the object itself, not including inherited params (which 7743100SN/A # will also be inherited from the base class's param struct 77510584Sandreas.hansson@arm.com # here). Sort the params based on their key 77610584Sandreas.hansson@arm.com params = map(lambda (k, v): v, sorted(cls._params.local.items())) 7778840Sandreas.hansson@arm.com ports = cls._ports.local 7783100SN/A try: 7793100SN/A ptypes = [p.ptype for p in params] 7803100SN/A except: 7813100SN/A print cls, p, p.ptype_str 7823100SN/A print params 7833100SN/A raise 7843100SN/A 7857675Snate@binkert.org class_path = cls._value_dict['cxx_class'].split('::') 7867675Snate@binkert.org 7877675Snate@binkert.org code('''\ 7887675Snate@binkert.org#ifndef __PARAMS__${cls}__ 7897675Snate@binkert.org#define __PARAMS__${cls}__ 7907675Snate@binkert.org 7917675Snate@binkert.org''') 7927675Snate@binkert.org 7937675Snate@binkert.org # A forward class declaration is sufficient since we are just 7947675Snate@binkert.org # declaring a pointer. 7957675Snate@binkert.org for ns in class_path[:-1]: 7967675Snate@binkert.org code('namespace $ns {') 7977675Snate@binkert.org code('class $0;', class_path[-1]) 7987675Snate@binkert.org for ns in reversed(class_path[:-1]): 7997811Ssteve.reinhardt@amd.com code('} // namespace $ns') 8007675Snate@binkert.org code() 8017675Snate@binkert.org 8028597Ssteve.reinhardt@amd.com # The base SimObject has a couple of params that get 8038597Ssteve.reinhardt@amd.com # automatically set from Python without being declared through 8048597Ssteve.reinhardt@amd.com # the normal Param mechanism; we slip them in here (needed 8058597Ssteve.reinhardt@amd.com # predecls now, actual declarations below) 8068597Ssteve.reinhardt@amd.com if cls == SimObject: 8078597Ssteve.reinhardt@amd.com code(''' 8088597Ssteve.reinhardt@amd.com#ifndef PY_VERSION 8098597Ssteve.reinhardt@amd.comstruct PyObject; 8108597Ssteve.reinhardt@amd.com#endif 8118597Ssteve.reinhardt@amd.com 8128597Ssteve.reinhardt@amd.com#include <string> 8138597Ssteve.reinhardt@amd.com''') 8147673Snate@binkert.org for param in params: 8157673Snate@binkert.org param.cxx_predecls(code) 8168840Sandreas.hansson@arm.com for port in ports.itervalues(): 8178840Sandreas.hansson@arm.com port.cxx_predecls(code) 8187673Snate@binkert.org code() 8194762Snate@binkert.org 8205610Snate@binkert.org if cls._base: 8217673Snate@binkert.org code('#include "params/${{cls._base.type}}.hh"') 8227673Snate@binkert.org code() 8234762Snate@binkert.org 8244762Snate@binkert.org for ptype in ptypes: 8254762Snate@binkert.org if issubclass(ptype, Enum): 8267673Snate@binkert.org code('#include "enums/${{ptype.__name__}}.hh"') 8277673Snate@binkert.org code() 8284762Snate@binkert.org 8298596Ssteve.reinhardt@amd.com # now generate the actual param struct 8308597Ssteve.reinhardt@amd.com code("struct ${cls}Params") 8318597Ssteve.reinhardt@amd.com if cls._base: 8328597Ssteve.reinhardt@amd.com code(" : public ${{cls._base.type}}Params") 8338597Ssteve.reinhardt@amd.com code("{") 8348597Ssteve.reinhardt@amd.com if not hasattr(cls, 'abstract') or not cls.abstract: 8358597Ssteve.reinhardt@amd.com if 'type' in cls.__dict__: 8368597Ssteve.reinhardt@amd.com code(" ${{cls.cxx_type}} create();") 8378597Ssteve.reinhardt@amd.com 8388597Ssteve.reinhardt@amd.com code.indent() 8398596Ssteve.reinhardt@amd.com if cls == SimObject: 8408597Ssteve.reinhardt@amd.com code(''' 8419983Sstever@gmail.com SimObjectParams() {} 8428597Ssteve.reinhardt@amd.com virtual ~SimObjectParams() {} 8438596Ssteve.reinhardt@amd.com 8448597Ssteve.reinhardt@amd.com std::string name; 8458597Ssteve.reinhardt@amd.com PyObject *pyobj; 8468597Ssteve.reinhardt@amd.com ''') 8478597Ssteve.reinhardt@amd.com for param in params: 8488597Ssteve.reinhardt@amd.com param.cxx_decl(code) 8498840Sandreas.hansson@arm.com for port in ports.itervalues(): 8508840Sandreas.hansson@arm.com port.cxx_decl(code) 8518840Sandreas.hansson@arm.com 8528597Ssteve.reinhardt@amd.com code.dedent() 8538597Ssteve.reinhardt@amd.com code('};') 8545488Snate@binkert.org 8557673Snate@binkert.org code() 8567673Snate@binkert.org code('#endif // __PARAMS__${cls}__') 8575488Snate@binkert.org return code 8585488Snate@binkert.org 85910458Sandreas.hansson@arm.com # Generate the C++ declaration/definition files for this SimObject's 86010458Sandreas.hansson@arm.com # param struct to allow C++ initialisation 86110458Sandreas.hansson@arm.com def cxx_config_param_file(cls, code, is_header): 86210458Sandreas.hansson@arm.com createCxxConfigDirectoryEntryFile(code, cls.__name__, cls, is_header) 86310458Sandreas.hansson@arm.com return code 8645488Snate@binkert.org 8659983Sstever@gmail.com# This *temporary* definition is required to support calls from the 8669983Sstever@gmail.com# SimObject class definition to the MetaSimObject methods (in 8679983Sstever@gmail.com# particular _set_param, which gets called for parameters with default 8689983Sstever@gmail.com# values defined on the SimObject class itself). It will get 8699983Sstever@gmail.com# overridden by the permanent definition (which requires that 8709983Sstever@gmail.com# SimObject be defined) lower in this file. 8719983Sstever@gmail.comdef isSimObjectOrVector(value): 8729983Sstever@gmail.com return False 8733100SN/A 87410267SGeoffrey.Blake@arm.com# This class holds information about each simobject parameter 87510267SGeoffrey.Blake@arm.com# that should be displayed on the command line for use in the 87610267SGeoffrey.Blake@arm.com# configuration system. 87710267SGeoffrey.Blake@arm.comclass ParamInfo(object): 87810267SGeoffrey.Blake@arm.com def __init__(self, type, desc, type_str, example, default_val, access_str): 87910267SGeoffrey.Blake@arm.com self.type = type 88010267SGeoffrey.Blake@arm.com self.desc = desc 88110267SGeoffrey.Blake@arm.com self.type_str = type_str 88210267SGeoffrey.Blake@arm.com self.example_str = example 88310267SGeoffrey.Blake@arm.com self.default_val = default_val 88410267SGeoffrey.Blake@arm.com # The string representation used to access this param through python. 88510267SGeoffrey.Blake@arm.com # The method to access this parameter presented on the command line may 88610267SGeoffrey.Blake@arm.com # be different, so this needs to be stored for later use. 88710267SGeoffrey.Blake@arm.com self.access_str = access_str 88810267SGeoffrey.Blake@arm.com self.created = True 88910267SGeoffrey.Blake@arm.com 89010267SGeoffrey.Blake@arm.com # Make it so we can only set attributes at initialization time 89110267SGeoffrey.Blake@arm.com # and effectively make this a const object. 89210267SGeoffrey.Blake@arm.com def __setattr__(self, name, value): 89310267SGeoffrey.Blake@arm.com if not "created" in self.__dict__: 89410267SGeoffrey.Blake@arm.com self.__dict__[name] = value 89510267SGeoffrey.Blake@arm.com 8962740SN/A# The SimObject class is the root of the special hierarchy. Most of 897679SN/A# the code in this class deals with the configuration hierarchy itself 898679SN/A# (parent/child node relationships). 8991692SN/Aclass SimObject(object): 9001692SN/A # Specify metaclass. Any class inheriting from SimObject will 901679SN/A # get this metaclass. 9021692SN/A __metaclass__ = MetaSimObject 9033100SN/A type = 'SimObject' 9044762Snate@binkert.org abstract = True 9059983Sstever@gmail.com 9069338SAndreas.Sandberg@arm.com cxx_header = "sim/sim_object.hh" 9079345SAndreas.Sandberg@ARM.com cxx_bases = [ "Drainable", "Serializable" ] 9089983Sstever@gmail.com eventq_index = Param.UInt32(Parent.eventq_index, "Event Queue Index") 9099342SAndreas.Sandberg@arm.com 9108597Ssteve.reinhardt@amd.com @classmethod 9118597Ssteve.reinhardt@amd.com def export_method_swig_predecls(cls, code): 9128597Ssteve.reinhardt@amd.com code(''' 9138597Ssteve.reinhardt@amd.com%include <std_string.i> 9149342SAndreas.Sandberg@arm.com 9159342SAndreas.Sandberg@arm.com%import "python/swig/drain.i" 9169345SAndreas.Sandberg@ARM.com%import "python/swig/serialize.i" 9178597Ssteve.reinhardt@amd.com''') 9188597Ssteve.reinhardt@amd.com 9198597Ssteve.reinhardt@amd.com @classmethod 9208597Ssteve.reinhardt@amd.com def export_methods(cls, code): 9218597Ssteve.reinhardt@amd.com code(''' 9228597Ssteve.reinhardt@amd.com void init(); 92310905Sandreas.sandberg@arm.com void loadState(CheckpointIn &cp); 9248597Ssteve.reinhardt@amd.com void initState(); 92510911Sandreas.sandberg@arm.com void memInvalidate(); 92610911Sandreas.sandberg@arm.com void memWriteback(); 9278597Ssteve.reinhardt@amd.com void regStats(); 9288597Ssteve.reinhardt@amd.com void resetStats(); 92910023Smatt.horsnell@ARM.com void regProbePoints(); 93010023Smatt.horsnell@ARM.com void regProbeListeners(); 9318597Ssteve.reinhardt@amd.com void startup(); 9328597Ssteve.reinhardt@amd.com''') 9338597Ssteve.reinhardt@amd.com 93410267SGeoffrey.Blake@arm.com # Returns a dict of all the option strings that can be 93510267SGeoffrey.Blake@arm.com # generated as command line options for this simobject instance 93610267SGeoffrey.Blake@arm.com # by tracing all reachable params in the top level instance and 93710267SGeoffrey.Blake@arm.com # any children it contains. 93810267SGeoffrey.Blake@arm.com def enumerateParams(self, flags_dict = {}, 93910267SGeoffrey.Blake@arm.com cmd_line_str = "", access_str = ""): 94010267SGeoffrey.Blake@arm.com if hasattr(self, "_paramEnumed"): 94110267SGeoffrey.Blake@arm.com print "Cycle detected enumerating params" 94210267SGeoffrey.Blake@arm.com else: 94310267SGeoffrey.Blake@arm.com self._paramEnumed = True 94410267SGeoffrey.Blake@arm.com # Scan the children first to pick up all the objects in this SimObj 94510267SGeoffrey.Blake@arm.com for keys in self._children: 94610267SGeoffrey.Blake@arm.com child = self._children[keys] 94710267SGeoffrey.Blake@arm.com next_cmdline_str = cmd_line_str + keys 94810267SGeoffrey.Blake@arm.com next_access_str = access_str + keys 94910267SGeoffrey.Blake@arm.com if not isSimObjectVector(child): 95010267SGeoffrey.Blake@arm.com next_cmdline_str = next_cmdline_str + "." 95110267SGeoffrey.Blake@arm.com next_access_str = next_access_str + "." 95210267SGeoffrey.Blake@arm.com flags_dict = child.enumerateParams(flags_dict, 95310267SGeoffrey.Blake@arm.com next_cmdline_str, 95410267SGeoffrey.Blake@arm.com next_access_str) 95510267SGeoffrey.Blake@arm.com 95610267SGeoffrey.Blake@arm.com # Go through the simple params in the simobject in this level 95710267SGeoffrey.Blake@arm.com # of the simobject hierarchy and save information about the 95810267SGeoffrey.Blake@arm.com # parameter to be used for generating and processing command line 95910267SGeoffrey.Blake@arm.com # options to the simulator to set these parameters. 96010267SGeoffrey.Blake@arm.com for keys,values in self._params.items(): 96110267SGeoffrey.Blake@arm.com if values.isCmdLineSettable(): 96210267SGeoffrey.Blake@arm.com type_str = '' 96310267SGeoffrey.Blake@arm.com ex_str = values.example_str() 96410267SGeoffrey.Blake@arm.com ptype = None 96510267SGeoffrey.Blake@arm.com if isinstance(values, VectorParamDesc): 96610267SGeoffrey.Blake@arm.com type_str = 'Vector_%s' % values.ptype_str 96710267SGeoffrey.Blake@arm.com ptype = values 96810267SGeoffrey.Blake@arm.com else: 96910267SGeoffrey.Blake@arm.com type_str = '%s' % values.ptype_str 97010267SGeoffrey.Blake@arm.com ptype = values.ptype 97110267SGeoffrey.Blake@arm.com 97210267SGeoffrey.Blake@arm.com if keys in self._hr_values\ 97310267SGeoffrey.Blake@arm.com and keys in self._values\ 97410267SGeoffrey.Blake@arm.com and not isinstance(self._values[keys], m5.proxy.BaseProxy): 97510267SGeoffrey.Blake@arm.com cmd_str = cmd_line_str + keys 97610267SGeoffrey.Blake@arm.com acc_str = access_str + keys 97710267SGeoffrey.Blake@arm.com flags_dict[cmd_str] = ParamInfo(ptype, 97810267SGeoffrey.Blake@arm.com self._params[keys].desc, type_str, ex_str, 97910267SGeoffrey.Blake@arm.com values.pretty_print(self._hr_values[keys]), 98010267SGeoffrey.Blake@arm.com acc_str) 98110267SGeoffrey.Blake@arm.com elif not keys in self._hr_values\ 98210267SGeoffrey.Blake@arm.com and not keys in self._values: 98310267SGeoffrey.Blake@arm.com # Empty param 98410267SGeoffrey.Blake@arm.com cmd_str = cmd_line_str + keys 98510267SGeoffrey.Blake@arm.com acc_str = access_str + keys 98610267SGeoffrey.Blake@arm.com flags_dict[cmd_str] = ParamInfo(ptype, 98710267SGeoffrey.Blake@arm.com self._params[keys].desc, 98810267SGeoffrey.Blake@arm.com type_str, ex_str, '', acc_str) 98910267SGeoffrey.Blake@arm.com 99010267SGeoffrey.Blake@arm.com return flags_dict 99110267SGeoffrey.Blake@arm.com 9922740SN/A # Initialize new instance. For objects with SimObject-valued 9932740SN/A # children, we need to recursively clone the classes represented 9942740SN/A # by those param values as well in a consistent "deep copy"-style 9952740SN/A # fashion. That is, we want to make sure that each instance is 9962740SN/A # cloned only once, and that if there are multiple references to 9972740SN/A # the same original object, we end up with the corresponding 9982740SN/A # cloned references all pointing to the same cloned instance. 9992740SN/A def __init__(self, **kwargs): 10002740SN/A ancestor = kwargs.get('_ancestor') 10012740SN/A memo_dict = kwargs.get('_memo') 10022740SN/A if memo_dict is None: 10032740SN/A # prepare to memoize any recursively instantiated objects 10042740SN/A memo_dict = {} 10052740SN/A elif ancestor: 10062740SN/A # memoize me now to avoid problems with recursive calls 10072740SN/A memo_dict[ancestor] = self 10082711SN/A 10092740SN/A if not ancestor: 10102740SN/A ancestor = self.__class__ 10112740SN/A ancestor._instantiated = True 10122711SN/A 10132740SN/A # initialize required attributes 10142740SN/A self._parent = None 10157528Ssteve.reinhardt@amd.com self._name = None 10162740SN/A self._ccObject = None # pointer to C++ object 10174762Snate@binkert.org self._ccParams = None 10182740SN/A self._instantiated = False # really "cloned" 10192712SN/A 10208321Ssteve.reinhardt@amd.com # Clone children specified at class level. No need for a 10218321Ssteve.reinhardt@amd.com # multidict here since we will be cloning everything. 10228321Ssteve.reinhardt@amd.com # Do children before parameter values so that children that 10238321Ssteve.reinhardt@amd.com # are also param values get cloned properly. 10248321Ssteve.reinhardt@amd.com self._children = {} 10258321Ssteve.reinhardt@amd.com for key,val in ancestor._children.iteritems(): 10268321Ssteve.reinhardt@amd.com self.add_child(key, val(_memo=memo_dict)) 10278321Ssteve.reinhardt@amd.com 10282711SN/A # Inherit parameter values from class using multidict so 10297528Ssteve.reinhardt@amd.com # individual value settings can be overridden but we still 10307528Ssteve.reinhardt@amd.com # inherit late changes to non-overridden class values. 10312740SN/A self._values = multidict(ancestor._values) 103210267SGeoffrey.Blake@arm.com self._hr_values = multidict(ancestor._hr_values) 10332740SN/A # clone SimObject-valued parameters 10342740SN/A for key,val in ancestor._values.iteritems(): 10357528Ssteve.reinhardt@amd.com val = tryAsSimObjectOrVector(val) 10367528Ssteve.reinhardt@amd.com if val is not None: 10377528Ssteve.reinhardt@amd.com self._values[key] = val(_memo=memo_dict) 10387528Ssteve.reinhardt@amd.com 10392740SN/A # clone port references. no need to use a multidict here 10402740SN/A # since we will be creating new references for all ports. 10413105Sstever@eecs.umich.edu self._port_refs = {} 10423105Sstever@eecs.umich.edu for key,val in ancestor._port_refs.iteritems(): 10433105Sstever@eecs.umich.edu self._port_refs[key] = val.clone(self, memo_dict) 10441692SN/A # apply attribute assignments from keyword args, if any 10451692SN/A for key,val in kwargs.iteritems(): 10461692SN/A setattr(self, key, val) 1047679SN/A 10482740SN/A # "Clone" the current instance by creating another instance of 10492740SN/A # this instance's class, but that inherits its parameter values 10502740SN/A # and port mappings from the current instance. If we're in a 10512740SN/A # "deep copy" recursive clone, check the _memo dict to see if 10522740SN/A # we've already cloned this instance. 10531692SN/A def __call__(self, **kwargs): 10542740SN/A memo_dict = kwargs.get('_memo') 10552740SN/A if memo_dict is None: 10562740SN/A # no memo_dict: must be top-level clone operation. 10572740SN/A # this is only allowed at the root of a hierarchy 10582740SN/A if self._parent: 10592740SN/A raise RuntimeError, "attempt to clone object %s " \ 10602740SN/A "not at the root of a tree (parent = %s)" \ 10612740SN/A % (self, self._parent) 10622740SN/A # create a new dict and use that. 10632740SN/A memo_dict = {} 10642740SN/A kwargs['_memo'] = memo_dict 10652740SN/A elif memo_dict.has_key(self): 10662740SN/A # clone already done & memoized 10672740SN/A return memo_dict[self] 10682740SN/A return self.__class__(_ancestor = self, **kwargs) 10691343SN/A 10703105Sstever@eecs.umich.edu def _get_port_ref(self, attr): 10713105Sstever@eecs.umich.edu # Return reference that can be assigned to another port 10723105Sstever@eecs.umich.edu # via __setattr__. There is only ever one reference 10733105Sstever@eecs.umich.edu # object per port, but we create them lazily here. 10743105Sstever@eecs.umich.edu ref = self._port_refs.get(attr) 10759940SGeoffrey.Blake@arm.com if ref == None: 10763105Sstever@eecs.umich.edu ref = self._ports[attr].makeRef(self) 10773105Sstever@eecs.umich.edu self._port_refs[attr] = ref 10783105Sstever@eecs.umich.edu return ref 10793105Sstever@eecs.umich.edu 10801692SN/A def __getattr__(self, attr): 10812738SN/A if self._ports.has_key(attr): 10823105Sstever@eecs.umich.edu return self._get_port_ref(attr) 10832738SN/A 10841692SN/A if self._values.has_key(attr): 10851692SN/A return self._values[attr] 10861427SN/A 10877528Ssteve.reinhardt@amd.com if self._children.has_key(attr): 10887528Ssteve.reinhardt@amd.com return self._children[attr] 10897528Ssteve.reinhardt@amd.com 10907500Ssteve.reinhardt@amd.com # If the attribute exists on the C++ object, transparently 10917500Ssteve.reinhardt@amd.com # forward the reference there. This is typically used for 10927500Ssteve.reinhardt@amd.com # SWIG-wrapped methods such as init(), regStats(), 10939195SAndreas.Sandberg@arm.com # resetStats(), startup(), drain(), and 10947527Ssteve.reinhardt@amd.com # resume(). 10957500Ssteve.reinhardt@amd.com if self._ccObject and hasattr(self._ccObject, attr): 10967500Ssteve.reinhardt@amd.com return getattr(self._ccObject, attr) 10977500Ssteve.reinhardt@amd.com 109810002Ssteve.reinhardt@amd.com err_string = "object '%s' has no attribute '%s'" \ 10991692SN/A % (self.__class__.__name__, attr) 11001427SN/A 110110002Ssteve.reinhardt@amd.com if not self._ccObject: 110210002Ssteve.reinhardt@amd.com err_string += "\n (C++ object is not yet constructed," \ 110310002Ssteve.reinhardt@amd.com " so wrapped C++ methods are unavailable.)" 110410002Ssteve.reinhardt@amd.com 110510002Ssteve.reinhardt@amd.com raise AttributeError, err_string 110610002Ssteve.reinhardt@amd.com 11071692SN/A # Set attribute (called on foo.attr = value when foo is an 11081692SN/A # instance of class cls). 11091692SN/A def __setattr__(self, attr, value): 11101692SN/A # normal processing for private attributes 11111692SN/A if attr.startswith('_'): 11121692SN/A object.__setattr__(self, attr, value) 11131692SN/A return 11141427SN/A 11152738SN/A if self._ports.has_key(attr): 11162738SN/A # set up port connection 11173105Sstever@eecs.umich.edu self._get_port_ref(attr).connect(value) 11182738SN/A return 11192738SN/A 11203105Sstever@eecs.umich.edu param = self._params.get(attr) 11211692SN/A if param: 11221310SN/A try: 112310267SGeoffrey.Blake@arm.com hr_value = value 11241692SN/A value = param.convert(value) 11251587SN/A except Exception, e: 11261692SN/A msg = "%s\nError setting param %s.%s to %s\n" % \ 11271692SN/A (e, self.__class__.__name__, attr, value) 11281605SN/A e.args = (msg, ) 11291605SN/A raise 11307528Ssteve.reinhardt@amd.com self._values[attr] = value 11318321Ssteve.reinhardt@amd.com # implicitly parent unparented objects assigned as params 11328321Ssteve.reinhardt@amd.com if isSimObjectOrVector(value) and not value.has_parent(): 11338321Ssteve.reinhardt@amd.com self.add_child(attr, value) 113410267SGeoffrey.Blake@arm.com # set the human-readable value dict if this is a param 113510267SGeoffrey.Blake@arm.com # with a literal value and is not being set as an object 113610267SGeoffrey.Blake@arm.com # or proxy. 113710267SGeoffrey.Blake@arm.com if not (isSimObjectOrVector(value) or\ 113810267SGeoffrey.Blake@arm.com isinstance(value, m5.proxy.BaseProxy)): 113910267SGeoffrey.Blake@arm.com self._hr_values[attr] = hr_value 114010267SGeoffrey.Blake@arm.com 11413105Sstever@eecs.umich.edu return 11421310SN/A 11437528Ssteve.reinhardt@amd.com # if RHS is a SimObject, it's an implicit child assignment 11443105Sstever@eecs.umich.edu if isSimObjectOrSequence(value): 11457528Ssteve.reinhardt@amd.com self.add_child(attr, value) 11463105Sstever@eecs.umich.edu return 11471693SN/A 11483105Sstever@eecs.umich.edu # no valid assignment... raise exception 11493105Sstever@eecs.umich.edu raise AttributeError, "Class %s has no parameter %s" \ 11503105Sstever@eecs.umich.edu % (self.__class__.__name__, attr) 11511310SN/A 11521310SN/A 11531692SN/A # this hack allows tacking a '[0]' onto parameters that may or may 11541692SN/A # not be vectors, and always getting the first element (e.g. cpus) 11551692SN/A def __getitem__(self, key): 11561692SN/A if key == 0: 11571692SN/A return self 115810267SGeoffrey.Blake@arm.com raise IndexError, "Non-zero index '%s' to SimObject" % key 115910267SGeoffrey.Blake@arm.com 116010267SGeoffrey.Blake@arm.com # this hack allows us to iterate over a SimObject that may 116110267SGeoffrey.Blake@arm.com # not be a vector, so we can call a loop over it and get just one 116210267SGeoffrey.Blake@arm.com # element. 116310267SGeoffrey.Blake@arm.com def __len__(self): 116410267SGeoffrey.Blake@arm.com return 1 11651310SN/A 11667528Ssteve.reinhardt@amd.com # Also implemented by SimObjectVector 11677528Ssteve.reinhardt@amd.com def clear_parent(self, old_parent): 11687528Ssteve.reinhardt@amd.com assert self._parent is old_parent 11697528Ssteve.reinhardt@amd.com self._parent = None 11707528Ssteve.reinhardt@amd.com 11717528Ssteve.reinhardt@amd.com # Also implemented by SimObjectVector 11727528Ssteve.reinhardt@amd.com def set_parent(self, parent, name): 11737528Ssteve.reinhardt@amd.com self._parent = parent 11747528Ssteve.reinhardt@amd.com self._name = name 11757528Ssteve.reinhardt@amd.com 11769953Sgeoffrey.blake@arm.com # Return parent object of this SimObject, not implemented by SimObjectVector 11779953Sgeoffrey.blake@arm.com # because the elements in a SimObjectVector may not share the same parent 11789953Sgeoffrey.blake@arm.com def get_parent(self): 11799953Sgeoffrey.blake@arm.com return self._parent 11809953Sgeoffrey.blake@arm.com 11817528Ssteve.reinhardt@amd.com # Also implemented by SimObjectVector 11827528Ssteve.reinhardt@amd.com def get_name(self): 11837528Ssteve.reinhardt@amd.com return self._name 11847528Ssteve.reinhardt@amd.com 11858321Ssteve.reinhardt@amd.com # Also implemented by SimObjectVector 11868321Ssteve.reinhardt@amd.com def has_parent(self): 11878321Ssteve.reinhardt@amd.com return self._parent is not None 11887528Ssteve.reinhardt@amd.com 11897742Sgblack@eecs.umich.edu # clear out child with given name. This code is not likely to be exercised. 11907742Sgblack@eecs.umich.edu # See comment in add_child. 11911693SN/A def clear_child(self, name): 11921693SN/A child = self._children[name] 11937528Ssteve.reinhardt@amd.com child.clear_parent(self) 11941693SN/A del self._children[name] 11951693SN/A 11967528Ssteve.reinhardt@amd.com # Add a new child to this object. 11977528Ssteve.reinhardt@amd.com def add_child(self, name, child): 11987528Ssteve.reinhardt@amd.com child = coerceSimObjectOrVector(child) 11998321Ssteve.reinhardt@amd.com if child.has_parent(): 12009528Ssascha.bischoff@arm.com warn("add_child('%s'): child '%s' already has parent", name, 12019528Ssascha.bischoff@arm.com child.get_name()) 12027528Ssteve.reinhardt@amd.com if self._children.has_key(name): 12037742Sgblack@eecs.umich.edu # This code path had an undiscovered bug that would make it fail 12047742Sgblack@eecs.umich.edu # at runtime. It had been here for a long time and was only 12057742Sgblack@eecs.umich.edu # exposed by a buggy script. Changes here will probably not be 12067742Sgblack@eecs.umich.edu # exercised without specialized testing. 12077738Sgblack@eecs.umich.edu self.clear_child(name) 12087528Ssteve.reinhardt@amd.com child.set_parent(self, name) 12097528Ssteve.reinhardt@amd.com self._children[name] = child 12101310SN/A 12117528Ssteve.reinhardt@amd.com # Take SimObject-valued parameters that haven't been explicitly 12127528Ssteve.reinhardt@amd.com # assigned as children and make them children of the object that 12137528Ssteve.reinhardt@amd.com # they were assigned to as a parameter value. This guarantees 12147528Ssteve.reinhardt@amd.com # that when we instantiate all the parameter objects we're still 12157528Ssteve.reinhardt@amd.com # inside the configuration hierarchy. 12167528Ssteve.reinhardt@amd.com def adoptOrphanParams(self): 12177528Ssteve.reinhardt@amd.com for key,val in self._values.iteritems(): 12187528Ssteve.reinhardt@amd.com if not isSimObjectVector(val) and isSimObjectSequence(val): 12197528Ssteve.reinhardt@amd.com # need to convert raw SimObject sequences to 12208321Ssteve.reinhardt@amd.com # SimObjectVector class so we can call has_parent() 12217528Ssteve.reinhardt@amd.com val = SimObjectVector(val) 12227528Ssteve.reinhardt@amd.com self._values[key] = val 12238321Ssteve.reinhardt@amd.com if isSimObjectOrVector(val) and not val.has_parent(): 12249528Ssascha.bischoff@arm.com warn("%s adopting orphan SimObject param '%s'", self, key) 12257528Ssteve.reinhardt@amd.com self.add_child(key, val) 12263105Sstever@eecs.umich.edu 12271692SN/A def path(self): 12282740SN/A if not self._parent: 12298321Ssteve.reinhardt@amd.com return '<orphan %s>' % self.__class__ 12301692SN/A ppath = self._parent.path() 12311692SN/A if ppath == 'root': 12321692SN/A return self._name 12331692SN/A return ppath + "." + self._name 12341310SN/A 12351692SN/A def __str__(self): 12361692SN/A return self.path() 12371310SN/A 123810380SAndrew.Bardsley@arm.com def config_value(self): 123910380SAndrew.Bardsley@arm.com return self.path() 124010380SAndrew.Bardsley@arm.com 12411692SN/A def ini_str(self): 12421692SN/A return self.path() 12431310SN/A 12441692SN/A def find_any(self, ptype): 12451692SN/A if isinstance(self, ptype): 12461692SN/A return self, True 12471310SN/A 12481692SN/A found_obj = None 12491692SN/A for child in self._children.itervalues(): 125010195SGeoffrey.Blake@arm.com visited = False 125110195SGeoffrey.Blake@arm.com if hasattr(child, '_visited'): 125210195SGeoffrey.Blake@arm.com visited = getattr(child, '_visited') 125310195SGeoffrey.Blake@arm.com 125410195SGeoffrey.Blake@arm.com if isinstance(child, ptype) and not visited: 12551692SN/A if found_obj != None and child != found_obj: 12561692SN/A raise AttributeError, \ 12571692SN/A 'parent.any matched more than one: %s %s' % \ 12581814SN/A (found_obj.path, child.path) 12591692SN/A found_obj = child 12601692SN/A # search param space 12611692SN/A for pname,pdesc in self._params.iteritems(): 12621692SN/A if issubclass(pdesc.ptype, ptype): 12631692SN/A match_obj = self._values[pname] 12641692SN/A if found_obj != None and found_obj != match_obj: 12651692SN/A raise AttributeError, \ 12665952Ssaidi@eecs.umich.edu 'parent.any matched more than one: %s and %s' % (found_obj.path, match_obj.path) 12671692SN/A found_obj = match_obj 12681692SN/A return found_obj, found_obj != None 12691692SN/A 12708459SAli.Saidi@ARM.com def find_all(self, ptype): 12718459SAli.Saidi@ARM.com all = {} 12728459SAli.Saidi@ARM.com # search children 12738459SAli.Saidi@ARM.com for child in self._children.itervalues(): 12749410Sandreas.hansson@arm.com # a child could be a list, so ensure we visit each item 12759410Sandreas.hansson@arm.com if isinstance(child, list): 12769410Sandreas.hansson@arm.com children = child 12779410Sandreas.hansson@arm.com else: 12789410Sandreas.hansson@arm.com children = [child] 12799410Sandreas.hansson@arm.com 12809410Sandreas.hansson@arm.com for child in children: 12819410Sandreas.hansson@arm.com if isinstance(child, ptype) and not isproxy(child) and \ 12829410Sandreas.hansson@arm.com not isNullPointer(child): 12839410Sandreas.hansson@arm.com all[child] = True 12849410Sandreas.hansson@arm.com if isSimObject(child): 12859410Sandreas.hansson@arm.com # also add results from the child itself 12869410Sandreas.hansson@arm.com child_all, done = child.find_all(ptype) 12879410Sandreas.hansson@arm.com all.update(dict(zip(child_all, [done] * len(child_all)))) 12888459SAli.Saidi@ARM.com # search param space 12898459SAli.Saidi@ARM.com for pname,pdesc in self._params.iteritems(): 12908459SAli.Saidi@ARM.com if issubclass(pdesc.ptype, ptype): 12918459SAli.Saidi@ARM.com match_obj = self._values[pname] 12928459SAli.Saidi@ARM.com if not isproxy(match_obj) and not isNullPointer(match_obj): 12938459SAli.Saidi@ARM.com all[match_obj] = True 129410532Sandreas.hansson@arm.com # Also make sure to sort the keys based on the objects' path to 129510532Sandreas.hansson@arm.com # ensure that the order is the same on all hosts 129610532Sandreas.hansson@arm.com return sorted(all.keys(), key = lambda o: o.path()), True 12978459SAli.Saidi@ARM.com 12981815SN/A def unproxy(self, base): 12991815SN/A return self 13001815SN/A 13017527Ssteve.reinhardt@amd.com def unproxyParams(self): 13023105Sstever@eecs.umich.edu for param in self._params.iterkeys(): 13033105Sstever@eecs.umich.edu value = self._values.get(param) 13046654Snate@binkert.org if value != None and isproxy(value): 13053105Sstever@eecs.umich.edu try: 13063105Sstever@eecs.umich.edu value = value.unproxy(self) 13073105Sstever@eecs.umich.edu except: 13083105Sstever@eecs.umich.edu print "Error in unproxying param '%s' of %s" % \ 13093105Sstever@eecs.umich.edu (param, self.path()) 13103105Sstever@eecs.umich.edu raise 13113105Sstever@eecs.umich.edu setattr(self, param, value) 13123105Sstever@eecs.umich.edu 13133107Sstever@eecs.umich.edu # Unproxy ports in sorted order so that 'append' operations on 13143107Sstever@eecs.umich.edu # vector ports are done in a deterministic fashion. 13153107Sstever@eecs.umich.edu port_names = self._ports.keys() 13163107Sstever@eecs.umich.edu port_names.sort() 13173107Sstever@eecs.umich.edu for port_name in port_names: 13183105Sstever@eecs.umich.edu port = self._port_refs.get(port_name) 13193105Sstever@eecs.umich.edu if port != None: 13203105Sstever@eecs.umich.edu port.unproxy(self) 13213105Sstever@eecs.umich.edu 13225037Smilesck@eecs.umich.edu def print_ini(self, ini_file): 13235543Ssaidi@eecs.umich.edu print >>ini_file, '[' + self.path() + ']' # .ini section header 13241692SN/A 13252738SN/A instanceDict[self.path()] = self 13262738SN/A 13274081Sbinkertn@umich.edu if hasattr(self, 'type'): 13285037Smilesck@eecs.umich.edu print >>ini_file, 'type=%s' % self.type 13291692SN/A 13308664SAli.Saidi@ARM.com if len(self._children.keys()): 13317528Ssteve.reinhardt@amd.com print >>ini_file, 'children=%s' % \ 13328664SAli.Saidi@ARM.com ' '.join(self._children[n].get_name() \ 13338664SAli.Saidi@ARM.com for n in sorted(self._children.keys())) 13341692SN/A 13358664SAli.Saidi@ARM.com for param in sorted(self._params.keys()): 13363105Sstever@eecs.umich.edu value = self._values.get(param) 13371692SN/A if value != None: 13385037Smilesck@eecs.umich.edu print >>ini_file, '%s=%s' % (param, 13395037Smilesck@eecs.umich.edu self._values[param].ini_str()) 13401692SN/A 13418664SAli.Saidi@ARM.com for port_name in sorted(self._ports.keys()): 13423105Sstever@eecs.umich.edu port = self._port_refs.get(port_name, None) 13433105Sstever@eecs.umich.edu if port != None: 13445037Smilesck@eecs.umich.edu print >>ini_file, '%s=%s' % (port_name, port.ini_str()) 13453103Sstever@eecs.umich.edu 13465543Ssaidi@eecs.umich.edu print >>ini_file # blank line between objects 13471692SN/A 13488664SAli.Saidi@ARM.com # generate a tree of dictionaries expressing all the parameters in the 13498664SAli.Saidi@ARM.com # instantiated system for use by scripts that want to do power, thermal 13508664SAli.Saidi@ARM.com # visualization, and other similar tasks 13518664SAli.Saidi@ARM.com def get_config_as_dict(self): 13528664SAli.Saidi@ARM.com d = attrdict() 13538664SAli.Saidi@ARM.com if hasattr(self, 'type'): 13548664SAli.Saidi@ARM.com d.type = self.type 13558664SAli.Saidi@ARM.com if hasattr(self, 'cxx_class'): 13568664SAli.Saidi@ARM.com d.cxx_class = self.cxx_class 13579017Sandreas.hansson@arm.com # Add the name and path of this object to be able to link to 13589017Sandreas.hansson@arm.com # the stats 13599017Sandreas.hansson@arm.com d.name = self.get_name() 13609017Sandreas.hansson@arm.com d.path = self.path() 13618664SAli.Saidi@ARM.com 13628664SAli.Saidi@ARM.com for param in sorted(self._params.keys()): 13638664SAli.Saidi@ARM.com value = self._values.get(param) 13648848Ssteve.reinhardt@amd.com if value != None: 136510380SAndrew.Bardsley@arm.com d[param] = value.config_value() 13668664SAli.Saidi@ARM.com 13678664SAli.Saidi@ARM.com for n in sorted(self._children.keys()): 13689017Sandreas.hansson@arm.com child = self._children[n] 13699017Sandreas.hansson@arm.com # Use the name of the attribute (and not get_name()) as 13709017Sandreas.hansson@arm.com # the key in the JSON dictionary to capture the hierarchy 13719017Sandreas.hansson@arm.com # in the Python code that assembled this system 13729017Sandreas.hansson@arm.com d[n] = child.get_config_as_dict() 13738664SAli.Saidi@ARM.com 13748664SAli.Saidi@ARM.com for port_name in sorted(self._ports.keys()): 13758664SAli.Saidi@ARM.com port = self._port_refs.get(port_name, None) 13768664SAli.Saidi@ARM.com if port != None: 13779017Sandreas.hansson@arm.com # Represent each port with a dictionary containing the 13789017Sandreas.hansson@arm.com # prominent attributes 13799017Sandreas.hansson@arm.com d[port_name] = port.get_config_as_dict() 13808664SAli.Saidi@ARM.com 13818664SAli.Saidi@ARM.com return d 13828664SAli.Saidi@ARM.com 13834762Snate@binkert.org def getCCParams(self): 13844762Snate@binkert.org if self._ccParams: 13854762Snate@binkert.org return self._ccParams 13864762Snate@binkert.org 13877677Snate@binkert.org cc_params_struct = getattr(m5.internal.params, '%sParams' % self.type) 13884762Snate@binkert.org cc_params = cc_params_struct() 13895488Snate@binkert.org cc_params.pyobj = self 13904762Snate@binkert.org cc_params.name = str(self) 13914762Snate@binkert.org 13924762Snate@binkert.org param_names = self._params.keys() 13934762Snate@binkert.org param_names.sort() 13944762Snate@binkert.org for param in param_names: 13954762Snate@binkert.org value = self._values.get(param) 13964762Snate@binkert.org if value is None: 13976654Snate@binkert.org fatal("%s.%s without default or user set value", 13986654Snate@binkert.org self.path(), param) 13994762Snate@binkert.org 14004762Snate@binkert.org value = value.getValue() 14014762Snate@binkert.org if isinstance(self._params[param], VectorParamDesc): 14024762Snate@binkert.org assert isinstance(value, list) 14034762Snate@binkert.org vec = getattr(cc_params, param) 14044762Snate@binkert.org assert not len(vec) 14054762Snate@binkert.org for v in value: 14064762Snate@binkert.org vec.append(v) 14074762Snate@binkert.org else: 14084762Snate@binkert.org setattr(cc_params, param, value) 14094762Snate@binkert.org 14104762Snate@binkert.org port_names = self._ports.keys() 14114762Snate@binkert.org port_names.sort() 14124762Snate@binkert.org for port_name in port_names: 14134762Snate@binkert.org port = self._port_refs.get(port_name, None) 14148912Sandreas.hansson@arm.com if port != None: 14158912Sandreas.hansson@arm.com port_count = len(port) 14168912Sandreas.hansson@arm.com else: 14178912Sandreas.hansson@arm.com port_count = 0 14188900Sandreas.hansson@arm.com setattr(cc_params, 'port_' + port_name + '_connection_count', 14198912Sandreas.hansson@arm.com port_count) 14204762Snate@binkert.org self._ccParams = cc_params 14214762Snate@binkert.org return self._ccParams 14222738SN/A 14232740SN/A # Get C++ object corresponding to this object, calling C++ if 14242740SN/A # necessary to construct it. Does *not* recursively create 14252740SN/A # children. 14262740SN/A def getCCObject(self): 14272740SN/A if not self._ccObject: 14287526Ssteve.reinhardt@amd.com # Make sure this object is in the configuration hierarchy 14297526Ssteve.reinhardt@amd.com if not self._parent and not isRoot(self): 14307526Ssteve.reinhardt@amd.com raise RuntimeError, "Attempt to instantiate orphan node" 14317526Ssteve.reinhardt@amd.com # Cycles in the configuration hierarchy are not supported. This 14325244Sgblack@eecs.umich.edu # will catch the resulting recursion and stop. 14335244Sgblack@eecs.umich.edu self._ccObject = -1 143410267SGeoffrey.Blake@arm.com if not self.abstract: 143510267SGeoffrey.Blake@arm.com params = self.getCCParams() 143610267SGeoffrey.Blake@arm.com self._ccObject = params.create() 14372740SN/A elif self._ccObject == -1: 14387526Ssteve.reinhardt@amd.com raise RuntimeError, "%s: Cycle found in configuration hierarchy." \ 14392740SN/A % self.path() 14402740SN/A return self._ccObject 14412740SN/A 14427527Ssteve.reinhardt@amd.com def descendants(self): 14437527Ssteve.reinhardt@amd.com yield self 144410532Sandreas.hansson@arm.com # The order of the dict is implementation dependent, so sort 144510532Sandreas.hansson@arm.com # it based on the key (name) to ensure the order is the same 144610532Sandreas.hansson@arm.com # on all hosts 144710532Sandreas.hansson@arm.com for (name, child) in sorted(self._children.iteritems()): 14487527Ssteve.reinhardt@amd.com for obj in child.descendants(): 14497527Ssteve.reinhardt@amd.com yield obj 14507527Ssteve.reinhardt@amd.com 14517527Ssteve.reinhardt@amd.com # Call C++ to create C++ object corresponding to this object 14524762Snate@binkert.org def createCCObject(self): 14534762Snate@binkert.org self.getCCParams() 14544762Snate@binkert.org self.getCCObject() # force creation 14554762Snate@binkert.org 14564762Snate@binkert.org def getValue(self): 14574762Snate@binkert.org return self.getCCObject() 14584762Snate@binkert.org 14592738SN/A # Create C++ port connections corresponding to the connections in 14607527Ssteve.reinhardt@amd.com # _port_refs 14612738SN/A def connectPorts(self): 146210532Sandreas.hansson@arm.com # Sort the ports based on their attribute name to ensure the 146310532Sandreas.hansson@arm.com # order is the same on all hosts 146410532Sandreas.hansson@arm.com for (attr, portRef) in sorted(self._port_refs.iteritems()): 14653105Sstever@eecs.umich.edu portRef.ccConnect() 14662797SN/A 14673101Sstever@eecs.umich.edu# Function to provide to C++ so it can look up instances based on paths 14683101Sstever@eecs.umich.edudef resolveSimObject(name): 14693101Sstever@eecs.umich.edu obj = instanceDict[name] 14703101Sstever@eecs.umich.edu return obj.getCCObject() 1471679SN/A 14726654Snate@binkert.orgdef isSimObject(value): 14736654Snate@binkert.org return isinstance(value, SimObject) 14746654Snate@binkert.org 14756654Snate@binkert.orgdef isSimObjectClass(value): 14766654Snate@binkert.org return issubclass(value, SimObject) 14776654Snate@binkert.org 14787528Ssteve.reinhardt@amd.comdef isSimObjectVector(value): 14797528Ssteve.reinhardt@amd.com return isinstance(value, SimObjectVector) 14807528Ssteve.reinhardt@amd.com 14816654Snate@binkert.orgdef isSimObjectSequence(value): 14826654Snate@binkert.org if not isinstance(value, (list, tuple)) or len(value) == 0: 14836654Snate@binkert.org return False 14846654Snate@binkert.org 14856654Snate@binkert.org for val in value: 14866654Snate@binkert.org if not isNullPointer(val) and not isSimObject(val): 14876654Snate@binkert.org return False 14886654Snate@binkert.org 14896654Snate@binkert.org return True 14906654Snate@binkert.org 14916654Snate@binkert.orgdef isSimObjectOrSequence(value): 14926654Snate@binkert.org return isSimObject(value) or isSimObjectSequence(value) 14936654Snate@binkert.org 14947526Ssteve.reinhardt@amd.comdef isRoot(obj): 14957526Ssteve.reinhardt@amd.com from m5.objects import Root 14967526Ssteve.reinhardt@amd.com return obj and obj is Root.getInstance() 14977526Ssteve.reinhardt@amd.com 14987528Ssteve.reinhardt@amd.comdef isSimObjectOrVector(value): 14997528Ssteve.reinhardt@amd.com return isSimObject(value) or isSimObjectVector(value) 15007528Ssteve.reinhardt@amd.com 15017528Ssteve.reinhardt@amd.comdef tryAsSimObjectOrVector(value): 15027528Ssteve.reinhardt@amd.com if isSimObjectOrVector(value): 15037528Ssteve.reinhardt@amd.com return value 15047528Ssteve.reinhardt@amd.com if isSimObjectSequence(value): 15057528Ssteve.reinhardt@amd.com return SimObjectVector(value) 15067528Ssteve.reinhardt@amd.com return None 15077528Ssteve.reinhardt@amd.com 15087528Ssteve.reinhardt@amd.comdef coerceSimObjectOrVector(value): 15097528Ssteve.reinhardt@amd.com value = tryAsSimObjectOrVector(value) 15107528Ssteve.reinhardt@amd.com if value is None: 15117528Ssteve.reinhardt@amd.com raise TypeError, "SimObject or SimObjectVector expected" 15127528Ssteve.reinhardt@amd.com return value 15137528Ssteve.reinhardt@amd.com 15146654Snate@binkert.orgbaseClasses = allClasses.copy() 15156654Snate@binkert.orgbaseInstances = instanceDict.copy() 15166654Snate@binkert.org 15176654Snate@binkert.orgdef clear(): 15189338SAndreas.Sandberg@arm.com global allClasses, instanceDict, noCxxHeader 15196654Snate@binkert.org 15206654Snate@binkert.org allClasses = baseClasses.copy() 15216654Snate@binkert.org instanceDict = baseInstances.copy() 15229338SAndreas.Sandberg@arm.com noCxxHeader = False 15236654Snate@binkert.org 15241528SN/A# __all__ defines the list of symbols that get exported when 15251528SN/A# 'from config import *' is invoked. Try to keep this reasonably 15261528SN/A# short to avoid polluting other namespaces. 15274762Snate@binkert.org__all__ = [ 'SimObject' ] 1528