2006-09-04 19:52:26 +02:00
|
|
|
# Copyright (c) 2004-2006 The Regents of The University of Michigan
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met: redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer;
|
|
|
|
# redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution;
|
|
|
|
# neither the name of the copyright holders nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
# this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# Authors: Steve Reinhardt
|
|
|
|
# Nathan Binkert
|
|
|
|
|
SimObject: change naming of vectors so there are the same numbers of digits.
i.e. we used to have Foo0, Foo1, ..., Foo10, Foo11, ..., Foo100
now we have Foo000, Foo001, ..., Foo010, Foo011, ..., Foo100
2008-12-06 23:18:18 +01:00
|
|
|
import math
|
|
|
|
import sys
|
|
|
|
import types
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
import proxy
|
|
|
|
import m5
|
2006-09-05 02:14:07 +02:00
|
|
|
from util import *
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2006-09-05 02:14:07 +02:00
|
|
|
# These utility functions have to come first because they're
|
|
|
|
# referenced in params.py... otherwise they won't be defined when we
|
|
|
|
# import params below, and the recursive import of this file from
|
|
|
|
# params.py will not find these names.
|
|
|
|
def isSimObject(value):
|
|
|
|
return isinstance(value, SimObject)
|
|
|
|
|
|
|
|
def isSimObjectClass(value):
|
|
|
|
return issubclass(value, SimObject)
|
|
|
|
|
|
|
|
def isSimObjectSequence(value):
|
|
|
|
if not isinstance(value, (list, tuple)) or len(value) == 0:
|
|
|
|
return False
|
|
|
|
|
|
|
|
for val in value:
|
|
|
|
if not isNullPointer(val) and not isSimObject(val):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def isSimObjectOrSequence(value):
|
|
|
|
return isSimObject(value) or isSimObjectSequence(value)
|
|
|
|
|
|
|
|
# Have to import params up top since Param is referenced on initial
|
|
|
|
# load (when SimObject class references Param to create a class
|
|
|
|
# variable, the 'name' param)...
|
|
|
|
from params import *
|
|
|
|
# There are a few things we need that aren't in params.__all__ since
|
|
|
|
# normal users don't need them
|
2007-07-24 06:51:38 +02:00
|
|
|
from params import ParamDesc, VectorParamDesc, isNullPointer, SimObjVector
|
2006-09-05 02:14:07 +02:00
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
noDot = False
|
|
|
|
try:
|
|
|
|
import pydot
|
|
|
|
except:
|
|
|
|
noDot = True
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
#
|
|
|
|
# M5 Python Configuration Utility
|
|
|
|
#
|
|
|
|
# The basic idea is to write simple Python programs that build Python
|
|
|
|
# objects corresponding to M5 SimObjects for the desired simulation
|
|
|
|
# configuration. For now, the Python emits a .ini file that can be
|
|
|
|
# parsed by M5. In the future, some tighter integration between M5
|
|
|
|
# and the Python interpreter may allow bypassing the .ini file.
|
|
|
|
#
|
|
|
|
# Each SimObject class in M5 is represented by a Python class with the
|
|
|
|
# same name. The Python inheritance tree mirrors the M5 C++ tree
|
|
|
|
# (e.g., SimpleCPU derives from BaseCPU in both cases, and all
|
|
|
|
# SimObjects inherit from a single SimObject base class). To specify
|
|
|
|
# an instance of an M5 SimObject in a configuration, the user simply
|
|
|
|
# instantiates the corresponding Python object. The parameters for
|
|
|
|
# that SimObject are given by assigning to attributes of the Python
|
|
|
|
# object, either using keyword assignment in the constructor or in
|
|
|
|
# separate assignment statements. For example:
|
|
|
|
#
|
|
|
|
# cache = BaseCache(size='64KB')
|
|
|
|
# cache.hit_latency = 3
|
|
|
|
# cache.assoc = 8
|
|
|
|
#
|
|
|
|
# The magic lies in the mapping of the Python attributes for SimObject
|
|
|
|
# classes to the actual SimObject parameter specifications. This
|
|
|
|
# allows parameter validity checking in the Python code. Continuing
|
|
|
|
# the example above, the statements "cache.blurfl=3" or
|
|
|
|
# "cache.assoc='hello'" would both result in runtime errors in Python,
|
|
|
|
# since the BaseCache object has no 'blurfl' parameter and the 'assoc'
|
|
|
|
# parameter requires an integer, respectively. This magic is done
|
|
|
|
# primarily by overriding the special __setattr__ method that controls
|
|
|
|
# assignment to object attributes.
|
|
|
|
#
|
|
|
|
# Once a set of Python objects have been instantiated in a hierarchy,
|
|
|
|
# calling 'instantiate(obj)' (where obj is the root of the hierarchy)
|
|
|
|
# will generate a .ini file.
|
|
|
|
#
|
|
|
|
#####################################################################
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
# list of all SimObject classes
|
|
|
|
allClasses = {}
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
# dict to look up SimObjects based on path
|
|
|
|
instanceDict = {}
|
|
|
|
|
|
|
|
# The metaclass for SimObject. This class controls how new classes
|
|
|
|
# that derive from SimObject are instantiated, and provides inherited
|
|
|
|
# class behavior (just like a class controls how instances of that
|
|
|
|
# class are instantiated, and provides inherited instance behavior).
|
|
|
|
class MetaSimObject(type):
|
|
|
|
# Attributes that can be set only at initialization time
|
|
|
|
init_keywords = { 'abstract' : types.BooleanType,
|
2007-07-24 06:51:38 +02:00
|
|
|
'cxx_class' : types.StringType,
|
|
|
|
'cxx_type' : types.StringType,
|
|
|
|
'cxx_predecls' : types.ListType,
|
2007-08-03 07:50:02 +02:00
|
|
|
'swig_objdecls' : types.ListType,
|
2007-07-24 06:51:38 +02:00
|
|
|
'swig_predecls' : types.ListType,
|
2006-09-04 19:52:26 +02:00
|
|
|
'type' : types.StringType }
|
|
|
|
# Attributes that can be set any time
|
2007-07-24 06:51:38 +02:00
|
|
|
keywords = { 'check' : types.FunctionType }
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# __new__ is called before __init__, and is where the statements
|
|
|
|
# in the body of the class definition get loaded into the class's
|
|
|
|
# __dict__. We intercept this to filter out parameter & port assignments
|
|
|
|
# and only allow "private" attributes to be passed to the base
|
|
|
|
# __new__ (starting with underscore).
|
|
|
|
def __new__(mcls, name, bases, dict):
|
2007-07-24 06:51:38 +02:00
|
|
|
assert name not in allClasses
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
# Copy "private" attributes, functions, and classes to the
|
|
|
|
# official dict. Everything else goes in _init_dict to be
|
|
|
|
# filtered in __init__.
|
|
|
|
cls_dict = {}
|
|
|
|
value_dict = {}
|
|
|
|
for key,val in dict.items():
|
|
|
|
if key.startswith('_') or isinstance(val, (types.FunctionType,
|
|
|
|
types.TypeType)):
|
|
|
|
cls_dict[key] = val
|
|
|
|
else:
|
|
|
|
# must be a param/port setting
|
|
|
|
value_dict[key] = val
|
2007-07-24 06:51:38 +02:00
|
|
|
if 'abstract' not in value_dict:
|
|
|
|
value_dict['abstract'] = False
|
2006-09-04 19:52:26 +02:00
|
|
|
cls_dict['_value_dict'] = value_dict
|
2007-07-24 06:51:38 +02:00
|
|
|
cls = super(MetaSimObject, mcls).__new__(mcls, name, bases, cls_dict)
|
|
|
|
if 'type' in value_dict:
|
|
|
|
allClasses[name] = cls
|
|
|
|
return cls
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# subclass initialization
|
|
|
|
def __init__(cls, name, bases, dict):
|
|
|
|
# calls type.__init__()... I think that's a no-op, but leave
|
|
|
|
# it here just in case it's not.
|
|
|
|
super(MetaSimObject, cls).__init__(name, bases, dict)
|
|
|
|
|
|
|
|
# initialize required attributes
|
|
|
|
|
|
|
|
# class-only attributes
|
|
|
|
cls._params = multidict() # param descriptions
|
|
|
|
cls._ports = multidict() # port descriptions
|
|
|
|
|
|
|
|
# class or instance attributes
|
|
|
|
cls._values = multidict() # param values
|
2006-09-06 07:04:34 +02:00
|
|
|
cls._port_refs = multidict() # port ref objects
|
2006-09-04 19:52:26 +02:00
|
|
|
cls._instantiated = False # really instantiated, cloned, or subclassed
|
|
|
|
|
|
|
|
# We don't support multiple inheritance. If you want to, you
|
|
|
|
# must fix multidict to deal with it properly.
|
|
|
|
if len(bases) > 1:
|
|
|
|
raise TypeError, "SimObjects do not support multiple inheritance"
|
|
|
|
|
|
|
|
base = bases[0]
|
|
|
|
|
|
|
|
# Set up general inheritance via multidicts. A subclass will
|
|
|
|
# inherit all its settings from the base class. The only time
|
|
|
|
# the following is not true is when we define the SimObject
|
|
|
|
# class itself (in which case the multidicts have no parent).
|
|
|
|
if isinstance(base, MetaSimObject):
|
2008-10-10 07:19:39 +02:00
|
|
|
cls._base = base
|
2006-09-04 19:52:26 +02:00
|
|
|
cls._params.parent = base._params
|
|
|
|
cls._ports.parent = base._ports
|
|
|
|
cls._values.parent = base._values
|
2006-09-06 07:04:34 +02:00
|
|
|
cls._port_refs.parent = base._port_refs
|
2006-09-04 19:52:26 +02:00
|
|
|
# mark base as having been subclassed
|
|
|
|
base._instantiated = True
|
2008-10-10 07:19:39 +02:00
|
|
|
else:
|
|
|
|
cls._base = None
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
# default keyword values
|
|
|
|
if 'type' in cls._value_dict:
|
|
|
|
if 'cxx_class' not in cls._value_dict:
|
2008-10-10 07:19:39 +02:00
|
|
|
cls._value_dict['cxx_class'] = cls._value_dict['type']
|
2007-07-24 06:51:38 +02:00
|
|
|
|
2008-10-10 07:19:39 +02:00
|
|
|
cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
if 'cxx_predecls' not in cls._value_dict:
|
|
|
|
# A forward class declaration is sufficient since we are
|
|
|
|
# just declaring a pointer.
|
2008-10-10 07:19:39 +02:00
|
|
|
class_path = cls._value_dict['cxx_class'].split('::')
|
|
|
|
class_path.reverse()
|
|
|
|
decl = 'class %s;' % class_path[0]
|
|
|
|
for ns in class_path[1:]:
|
|
|
|
decl = 'namespace %s { %s }' % (ns, decl)
|
2007-07-24 06:51:38 +02:00
|
|
|
cls._value_dict['cxx_predecls'] = [decl]
|
|
|
|
|
|
|
|
if 'swig_predecls' not in cls._value_dict:
|
|
|
|
# A forward class declaration is sufficient since we are
|
|
|
|
# just declaring a pointer.
|
|
|
|
cls._value_dict['swig_predecls'] = \
|
|
|
|
cls._value_dict['cxx_predecls']
|
|
|
|
|
2007-08-03 07:50:02 +02:00
|
|
|
if 'swig_objdecls' not in cls._value_dict:
|
|
|
|
cls._value_dict['swig_objdecls'] = []
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
# Now process the _value_dict items. They could be defining
|
|
|
|
# new (or overriding existing) parameters or ports, setting
|
|
|
|
# class keywords (e.g., 'abstract'), or setting parameter
|
|
|
|
# values or port bindings. The first 3 can only be set when
|
|
|
|
# the class is defined, so we handle them here. The others
|
|
|
|
# can be set later too, so just emulate that by calling
|
|
|
|
# setattr().
|
|
|
|
for key,val in cls._value_dict.items():
|
|
|
|
# param descriptions
|
|
|
|
if isinstance(val, ParamDesc):
|
|
|
|
cls._new_param(key, val)
|
|
|
|
|
|
|
|
# port objects
|
|
|
|
elif isinstance(val, Port):
|
2006-09-06 07:04:34 +02:00
|
|
|
cls._new_port(key, val)
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# init-time-only keywords
|
|
|
|
elif cls.init_keywords.has_key(key):
|
|
|
|
cls._set_keyword(key, val, cls.init_keywords[key])
|
|
|
|
|
|
|
|
# default: use normal path (ends up in __setattr__)
|
|
|
|
else:
|
|
|
|
setattr(cls, key, val)
|
|
|
|
|
|
|
|
def _set_keyword(cls, keyword, val, kwtype):
|
|
|
|
if not isinstance(val, kwtype):
|
|
|
|
raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
|
|
|
|
(keyword, type(val), kwtype)
|
|
|
|
if isinstance(val, types.FunctionType):
|
|
|
|
val = classmethod(val)
|
|
|
|
type.__setattr__(cls, keyword, val)
|
|
|
|
|
|
|
|
def _new_param(cls, name, pdesc):
|
|
|
|
# each param desc should be uniquely assigned to one variable
|
|
|
|
assert(not hasattr(pdesc, 'name'))
|
|
|
|
pdesc.name = name
|
|
|
|
cls._params[name] = pdesc
|
|
|
|
if hasattr(pdesc, 'default'):
|
2006-09-06 07:04:34 +02:00
|
|
|
cls._set_param(name, pdesc.default, pdesc)
|
|
|
|
|
|
|
|
def _set_param(cls, name, value, param):
|
|
|
|
assert(param.name == name)
|
|
|
|
try:
|
|
|
|
cls._values[name] = param.convert(value)
|
|
|
|
except Exception, e:
|
|
|
|
msg = "%s\nError setting param %s.%s to %s\n" % \
|
|
|
|
(e, cls.__name__, name, value)
|
|
|
|
e.args = (msg, )
|
|
|
|
raise
|
|
|
|
|
|
|
|
def _new_port(cls, name, port):
|
|
|
|
# each port should be uniquely assigned to one variable
|
|
|
|
assert(not hasattr(port, 'name'))
|
|
|
|
port.name = name
|
|
|
|
cls._ports[name] = port
|
|
|
|
if hasattr(port, 'default'):
|
|
|
|
cls._cls_get_port_ref(name).connect(port.default)
|
|
|
|
|
|
|
|
# same as _get_port_ref, effectively, but for classes
|
|
|
|
def _cls_get_port_ref(cls, attr):
|
|
|
|
# Return reference that can be assigned to another port
|
|
|
|
# via __setattr__. There is only ever one reference
|
|
|
|
# object per port, but we create them lazily here.
|
|
|
|
ref = cls._port_refs.get(attr)
|
|
|
|
if not ref:
|
|
|
|
ref = cls._ports[attr].makeRef(cls)
|
|
|
|
cls._port_refs[attr] = ref
|
|
|
|
return ref
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# Set attribute (called on foo.attr = value when foo is an
|
|
|
|
# instance of class cls).
|
|
|
|
def __setattr__(cls, attr, value):
|
|
|
|
# normal processing for private attributes
|
|
|
|
if attr.startswith('_'):
|
|
|
|
type.__setattr__(cls, attr, value)
|
|
|
|
return
|
|
|
|
|
|
|
|
if cls.keywords.has_key(attr):
|
|
|
|
cls._set_keyword(attr, value, cls.keywords[attr])
|
|
|
|
return
|
|
|
|
|
|
|
|
if cls._ports.has_key(attr):
|
2006-09-06 07:04:34 +02:00
|
|
|
cls._cls_get_port_ref(attr).connect(value)
|
2006-09-04 19:52:26 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if isSimObjectOrSequence(value) and cls._instantiated:
|
|
|
|
raise RuntimeError, \
|
|
|
|
"cannot set SimObject parameter '%s' after\n" \
|
|
|
|
" class %s has been instantiated or subclassed" \
|
|
|
|
% (attr, cls.__name__)
|
|
|
|
|
|
|
|
# check for param
|
2006-09-06 07:04:34 +02:00
|
|
|
param = cls._params.get(attr)
|
2006-09-04 19:52:26 +02:00
|
|
|
if param:
|
2006-09-06 07:04:34 +02:00
|
|
|
cls._set_param(attr, value, param)
|
|
|
|
return
|
|
|
|
|
|
|
|
if isSimObjectOrSequence(value):
|
|
|
|
# If RHS is a SimObject, it's an implicit child assignment.
|
|
|
|
# Classes don't have children, so we just put this object
|
|
|
|
# in _values; later, each instance will do a 'setattr(self,
|
|
|
|
# attr, _values[attr])' in SimObject.__init__ which will
|
|
|
|
# add this object as a child.
|
2006-09-04 19:52:26 +02:00
|
|
|
cls._values[attr] = value
|
2006-09-06 07:04:34 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
# no valid assignment... raise exception
|
|
|
|
raise AttributeError, \
|
|
|
|
"Class %s has no parameter \'%s\'" % (cls.__name__, attr)
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
def __getattr__(cls, attr):
|
|
|
|
if cls._values.has_key(attr):
|
|
|
|
return cls._values[attr]
|
|
|
|
|
|
|
|
raise AttributeError, \
|
|
|
|
"object '%s' has no attribute '%s'" % (cls.__name__, attr)
|
|
|
|
|
|
|
|
def __str__(cls):
|
|
|
|
return cls.__name__
|
|
|
|
|
2007-08-03 07:50:02 +02:00
|
|
|
def cxx_decl(cls):
|
2007-07-24 06:51:38 +02:00
|
|
|
code = "#ifndef __PARAMS__%s\n" % cls
|
|
|
|
code += "#define __PARAMS__%s\n\n" % cls
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
# The 'dict' attribute restricts us to the params declared in
|
|
|
|
# the object itself, not including inherited params (which
|
|
|
|
# will also be inherited from the base class's param struct
|
|
|
|
# here).
|
2007-07-24 06:51:38 +02:00
|
|
|
params = cls._params.local.values()
|
2006-09-04 19:52:26 +02:00
|
|
|
try:
|
|
|
|
ptypes = [p.ptype for p in params]
|
|
|
|
except:
|
|
|
|
print cls, p, p.ptype_str
|
|
|
|
print params
|
|
|
|
raise
|
|
|
|
|
|
|
|
# get a list of lists of predeclaration lines
|
2007-07-24 06:51:38 +02:00
|
|
|
predecls = []
|
|
|
|
predecls.extend(cls.cxx_predecls)
|
|
|
|
for p in params:
|
|
|
|
predecls.extend(p.cxx_predecls())
|
2006-09-04 19:52:26 +02:00
|
|
|
# remove redundant lines
|
|
|
|
predecls2 = []
|
|
|
|
for pd in predecls:
|
|
|
|
if pd not in predecls2:
|
|
|
|
predecls2.append(pd)
|
|
|
|
predecls2.sort()
|
|
|
|
code += "\n".join(predecls2)
|
|
|
|
code += "\n\n";
|
|
|
|
|
2008-10-10 07:19:39 +02:00
|
|
|
if cls._base:
|
|
|
|
code += '#include "params/%s.hh"\n\n' % cls._base.type
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
for ptype in ptypes:
|
|
|
|
if issubclass(ptype, Enum):
|
|
|
|
code += '#include "enums/%s.hh"\n' % ptype.__name__
|
|
|
|
code += "\n\n"
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2008-10-10 07:19:39 +02:00
|
|
|
code += cls.cxx_struct(cls._base, params)
|
2008-06-18 21:07:15 +02:00
|
|
|
|
|
|
|
# close #ifndef __PARAMS__* guard
|
|
|
|
code += "\n#endif\n"
|
|
|
|
return code
|
|
|
|
|
|
|
|
def cxx_struct(cls, base, params):
|
|
|
|
if cls == SimObject:
|
|
|
|
return '#include "sim/sim_object_params.hh"\n'
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
# now generate the actual param struct
|
2008-06-18 21:07:15 +02:00
|
|
|
code = "struct %sParams" % cls
|
2006-09-04 19:52:26 +02:00
|
|
|
if base:
|
2008-10-10 07:19:39 +02:00
|
|
|
code += " : public %sParams" % base.type
|
2007-07-24 06:51:38 +02:00
|
|
|
code += "\n{\n"
|
|
|
|
if not hasattr(cls, 'abstract') or not cls.abstract:
|
|
|
|
if 'type' in cls.__dict__:
|
|
|
|
code += " %s create();\n" % cls.cxx_type
|
2006-09-04 19:52:26 +02:00
|
|
|
decls = [p.cxx_decl() for p in params]
|
|
|
|
decls.sort()
|
|
|
|
code += "".join([" %s\n" % d for d in decls])
|
|
|
|
code += "};\n"
|
|
|
|
|
|
|
|
return code
|
|
|
|
|
|
|
|
def swig_decl(cls):
|
2007-07-24 06:51:38 +02:00
|
|
|
code = '%%module %s\n' % cls
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
code += '%{\n'
|
|
|
|
code += '#include "params/%s.hh"\n' % cls
|
|
|
|
code += '%}\n\n'
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# The 'dict' attribute restricts us to the params declared in
|
|
|
|
# the object itself, not including inherited params (which
|
|
|
|
# will also be inherited from the base class's param struct
|
|
|
|
# here).
|
2007-07-24 06:51:38 +02:00
|
|
|
params = cls._params.local.values()
|
2006-09-04 19:52:26 +02:00
|
|
|
ptypes = [p.ptype for p in params]
|
|
|
|
|
|
|
|
# get a list of lists of predeclaration lines
|
2007-07-24 06:51:38 +02:00
|
|
|
predecls = []
|
|
|
|
predecls.extend([ p.swig_predecls() for p in params ])
|
2006-09-04 19:52:26 +02:00
|
|
|
# flatten
|
|
|
|
predecls = reduce(lambda x,y:x+y, predecls, [])
|
|
|
|
# remove redundant lines
|
|
|
|
predecls2 = []
|
|
|
|
for pd in predecls:
|
|
|
|
if pd not in predecls2:
|
|
|
|
predecls2.append(pd)
|
|
|
|
predecls2.sort()
|
|
|
|
code += "\n".join(predecls2)
|
|
|
|
code += "\n\n";
|
|
|
|
|
2008-10-10 07:19:39 +02:00
|
|
|
if cls._base:
|
|
|
|
code += '%%import "params/%s.i"\n\n' % cls._base.type
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
for ptype in ptypes:
|
|
|
|
if issubclass(ptype, Enum):
|
|
|
|
code += '%%import "enums/%s.hh"\n' % ptype.__name__
|
|
|
|
code += "\n\n"
|
|
|
|
|
|
|
|
code += '%%import "params/%s_type.hh"\n\n' % cls
|
2006-09-04 19:52:26 +02:00
|
|
|
code += '%%include "params/%s.hh"\n\n' % cls
|
|
|
|
|
|
|
|
return code
|
|
|
|
|
|
|
|
# The SimObject class is the root of the special hierarchy. Most of
|
|
|
|
# the code in this class deals with the configuration hierarchy itself
|
|
|
|
# (parent/child node relationships).
|
|
|
|
class SimObject(object):
|
|
|
|
# Specify metaclass. Any class inheriting from SimObject will
|
|
|
|
# get this metaclass.
|
|
|
|
__metaclass__ = MetaSimObject
|
|
|
|
type = 'SimObject'
|
2007-07-24 06:51:38 +02:00
|
|
|
abstract = True
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2007-08-03 07:50:02 +02:00
|
|
|
swig_objdecls = [ '%include "python/swig/sim_object.i"' ]
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# Initialize new instance. For objects with SimObject-valued
|
|
|
|
# children, we need to recursively clone the classes represented
|
|
|
|
# by those param values as well in a consistent "deep copy"-style
|
|
|
|
# fashion. That is, we want to make sure that each instance is
|
|
|
|
# cloned only once, and that if there are multiple references to
|
|
|
|
# the same original object, we end up with the corresponding
|
|
|
|
# cloned references all pointing to the same cloned instance.
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
ancestor = kwargs.get('_ancestor')
|
|
|
|
memo_dict = kwargs.get('_memo')
|
|
|
|
if memo_dict is None:
|
|
|
|
# prepare to memoize any recursively instantiated objects
|
|
|
|
memo_dict = {}
|
|
|
|
elif ancestor:
|
|
|
|
# memoize me now to avoid problems with recursive calls
|
|
|
|
memo_dict[ancestor] = self
|
|
|
|
|
|
|
|
if not ancestor:
|
|
|
|
ancestor = self.__class__
|
|
|
|
ancestor._instantiated = True
|
|
|
|
|
|
|
|
# initialize required attributes
|
|
|
|
self._parent = None
|
|
|
|
self._children = {}
|
|
|
|
self._ccObject = None # pointer to C++ object
|
2007-07-24 06:51:38 +02:00
|
|
|
self._ccParams = None
|
2006-09-04 19:52:26 +02:00
|
|
|
self._instantiated = False # really "cloned"
|
|
|
|
|
|
|
|
# Inherit parameter values from class using multidict so
|
|
|
|
# individual value settings can be overridden.
|
|
|
|
self._values = multidict(ancestor._values)
|
|
|
|
# clone SimObject-valued parameters
|
|
|
|
for key,val in ancestor._values.iteritems():
|
|
|
|
if isSimObject(val):
|
|
|
|
setattr(self, key, val(_memo=memo_dict))
|
|
|
|
elif isSimObjectSequence(val) and len(val):
|
|
|
|
setattr(self, key, [ v(_memo=memo_dict) for v in val ])
|
|
|
|
# clone port references. no need to use a multidict here
|
|
|
|
# since we will be creating new references for all ports.
|
2006-09-06 07:04:34 +02:00
|
|
|
self._port_refs = {}
|
|
|
|
for key,val in ancestor._port_refs.iteritems():
|
|
|
|
self._port_refs[key] = val.clone(self, memo_dict)
|
2006-09-04 19:52:26 +02:00
|
|
|
# apply attribute assignments from keyword args, if any
|
|
|
|
for key,val in kwargs.iteritems():
|
|
|
|
setattr(self, key, val)
|
|
|
|
|
|
|
|
# "Clone" the current instance by creating another instance of
|
|
|
|
# this instance's class, but that inherits its parameter values
|
|
|
|
# and port mappings from the current instance. If we're in a
|
|
|
|
# "deep copy" recursive clone, check the _memo dict to see if
|
|
|
|
# we've already cloned this instance.
|
|
|
|
def __call__(self, **kwargs):
|
|
|
|
memo_dict = kwargs.get('_memo')
|
|
|
|
if memo_dict is None:
|
|
|
|
# no memo_dict: must be top-level clone operation.
|
|
|
|
# this is only allowed at the root of a hierarchy
|
|
|
|
if self._parent:
|
|
|
|
raise RuntimeError, "attempt to clone object %s " \
|
|
|
|
"not at the root of a tree (parent = %s)" \
|
|
|
|
% (self, self._parent)
|
|
|
|
# create a new dict and use that.
|
|
|
|
memo_dict = {}
|
|
|
|
kwargs['_memo'] = memo_dict
|
|
|
|
elif memo_dict.has_key(self):
|
|
|
|
# clone already done & memoized
|
|
|
|
return memo_dict[self]
|
|
|
|
return self.__class__(_ancestor = self, **kwargs)
|
|
|
|
|
2006-09-06 07:04:34 +02:00
|
|
|
def _get_port_ref(self, attr):
|
|
|
|
# Return reference that can be assigned to another port
|
|
|
|
# via __setattr__. There is only ever one reference
|
|
|
|
# object per port, but we create them lazily here.
|
|
|
|
ref = self._port_refs.get(attr)
|
|
|
|
if not ref:
|
|
|
|
ref = self._ports[attr].makeRef(self)
|
|
|
|
self._port_refs[attr] = ref
|
|
|
|
return ref
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
def __getattr__(self, attr):
|
|
|
|
if self._ports.has_key(attr):
|
2006-09-06 07:04:34 +02:00
|
|
|
return self._get_port_ref(attr)
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
if self._values.has_key(attr):
|
|
|
|
return self._values[attr]
|
|
|
|
|
|
|
|
raise AttributeError, "object '%s' has no attribute '%s'" \
|
|
|
|
% (self.__class__.__name__, attr)
|
|
|
|
|
|
|
|
# Set attribute (called on foo.attr = value when foo is an
|
|
|
|
# instance of class cls).
|
|
|
|
def __setattr__(self, attr, value):
|
|
|
|
# normal processing for private attributes
|
|
|
|
if attr.startswith('_'):
|
|
|
|
object.__setattr__(self, attr, value)
|
|
|
|
return
|
|
|
|
|
|
|
|
if self._ports.has_key(attr):
|
|
|
|
# set up port connection
|
2006-09-06 07:04:34 +02:00
|
|
|
self._get_port_ref(attr).connect(value)
|
2006-09-04 19:52:26 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if isSimObjectOrSequence(value) and self._instantiated:
|
|
|
|
raise RuntimeError, \
|
|
|
|
"cannot set SimObject parameter '%s' after\n" \
|
|
|
|
" instance been cloned %s" % (attr, `self`)
|
|
|
|
|
|
|
|
# must be SimObject param
|
2006-09-06 07:04:34 +02:00
|
|
|
param = self._params.get(attr)
|
2006-09-04 19:52:26 +02:00
|
|
|
if param:
|
|
|
|
try:
|
|
|
|
value = param.convert(value)
|
|
|
|
except Exception, e:
|
|
|
|
msg = "%s\nError setting param %s.%s to %s\n" % \
|
|
|
|
(e, self.__class__.__name__, attr, value)
|
|
|
|
e.args = (msg, )
|
|
|
|
raise
|
2006-09-06 07:04:34 +02:00
|
|
|
self._set_child(attr, value)
|
|
|
|
return
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2006-09-06 07:04:34 +02:00
|
|
|
if isSimObjectOrSequence(value):
|
|
|
|
self._set_child(attr, value)
|
|
|
|
return
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2006-09-06 07:04:34 +02:00
|
|
|
# no valid assignment... raise exception
|
|
|
|
raise AttributeError, "Class %s has no parameter %s" \
|
|
|
|
% (self.__class__.__name__, attr)
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
# this hack allows tacking a '[0]' onto parameters that may or may
|
|
|
|
# not be vectors, and always getting the first element (e.g. cpus)
|
|
|
|
def __getitem__(self, key):
|
|
|
|
if key == 0:
|
|
|
|
return self
|
|
|
|
raise TypeError, "Non-zero index '%s' to SimObject" % key
|
|
|
|
|
|
|
|
# clear out children with given name, even if it's a vector
|
|
|
|
def clear_child(self, name):
|
|
|
|
if not self._children.has_key(name):
|
|
|
|
return
|
|
|
|
child = self._children[name]
|
|
|
|
if isinstance(child, SimObjVector):
|
|
|
|
for i in xrange(len(child)):
|
|
|
|
del self._children["s%d" % (name, i)]
|
|
|
|
del self._children[name]
|
|
|
|
|
|
|
|
def add_child(self, name, value):
|
|
|
|
self._children[name] = value
|
|
|
|
|
2006-09-06 07:04:34 +02:00
|
|
|
def _maybe_set_parent(self, parent, name):
|
2006-09-04 19:52:26 +02:00
|
|
|
if not self._parent:
|
|
|
|
self._parent = parent
|
|
|
|
self._name = name
|
|
|
|
parent.add_child(name, self)
|
|
|
|
|
2006-09-06 07:04:34 +02:00
|
|
|
def _set_child(self, attr, value):
|
|
|
|
# if RHS is a SimObject, it's an implicit child assignment
|
|
|
|
# clear out old child with this name, if any
|
|
|
|
self.clear_child(attr)
|
|
|
|
|
|
|
|
if isSimObject(value):
|
|
|
|
value._maybe_set_parent(self, attr)
|
|
|
|
elif isSimObjectSequence(value):
|
|
|
|
value = SimObjVector(value)
|
2007-07-24 06:51:38 +02:00
|
|
|
if len(value) == 1:
|
|
|
|
value[0]._maybe_set_parent(self, attr)
|
|
|
|
else:
|
SimObject: change naming of vectors so there are the same numbers of digits.
i.e. we used to have Foo0, Foo1, ..., Foo10, Foo11, ..., Foo100
now we have Foo000, Foo001, ..., Foo010, Foo011, ..., Foo100
2008-12-06 23:18:18 +01:00
|
|
|
width = int(math.ceil(math.log(len(value))/math.log(10)))
|
2007-07-24 06:51:38 +02:00
|
|
|
for i,v in enumerate(value):
|
SimObject: change naming of vectors so there are the same numbers of digits.
i.e. we used to have Foo0, Foo1, ..., Foo10, Foo11, ..., Foo100
now we have Foo000, Foo001, ..., Foo010, Foo011, ..., Foo100
2008-12-06 23:18:18 +01:00
|
|
|
v._maybe_set_parent(self, "%s%0*d" % (attr, width, i))
|
2006-09-06 07:04:34 +02:00
|
|
|
|
|
|
|
self._values[attr] = value
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
def path(self):
|
|
|
|
if not self._parent:
|
|
|
|
return 'root'
|
|
|
|
ppath = self._parent.path()
|
|
|
|
if ppath == 'root':
|
|
|
|
return self._name
|
|
|
|
return ppath + "." + self._name
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.path()
|
|
|
|
|
|
|
|
def ini_str(self):
|
|
|
|
return self.path()
|
|
|
|
|
|
|
|
def find_any(self, ptype):
|
|
|
|
if isinstance(self, ptype):
|
|
|
|
return self, True
|
|
|
|
|
|
|
|
found_obj = None
|
|
|
|
for child in self._children.itervalues():
|
|
|
|
if isinstance(child, ptype):
|
|
|
|
if found_obj != None and child != found_obj:
|
|
|
|
raise AttributeError, \
|
|
|
|
'parent.any matched more than one: %s %s' % \
|
|
|
|
(found_obj.path, child.path)
|
|
|
|
found_obj = child
|
|
|
|
# search param space
|
|
|
|
for pname,pdesc in self._params.iteritems():
|
|
|
|
if issubclass(pdesc.ptype, ptype):
|
|
|
|
match_obj = self._values[pname]
|
|
|
|
if found_obj != None and found_obj != match_obj:
|
|
|
|
raise AttributeError, \
|
|
|
|
'parent.any matched more than one: %s' % obj.path
|
|
|
|
found_obj = match_obj
|
|
|
|
return found_obj, found_obj != None
|
|
|
|
|
|
|
|
def unproxy(self, base):
|
|
|
|
return self
|
|
|
|
|
2006-09-06 07:04:34 +02:00
|
|
|
def unproxy_all(self):
|
|
|
|
for param in self._params.iterkeys():
|
|
|
|
value = self._values.get(param)
|
|
|
|
if value != None and proxy.isproxy(value):
|
|
|
|
try:
|
|
|
|
value = value.unproxy(self)
|
|
|
|
except:
|
|
|
|
print "Error in unproxying param '%s' of %s" % \
|
|
|
|
(param, self.path())
|
|
|
|
raise
|
|
|
|
setattr(self, param, value)
|
|
|
|
|
2006-09-07 07:37:35 +02:00
|
|
|
# Unproxy ports in sorted order so that 'append' operations on
|
|
|
|
# vector ports are done in a deterministic fashion.
|
|
|
|
port_names = self._ports.keys()
|
|
|
|
port_names.sort()
|
|
|
|
for port_name in port_names:
|
2006-09-06 07:04:34 +02:00
|
|
|
port = self._port_refs.get(port_name)
|
|
|
|
if port != None:
|
|
|
|
port.unproxy(self)
|
|
|
|
|
2006-09-07 07:37:35 +02:00
|
|
|
# Unproxy children in sorted order for determinism also.
|
|
|
|
child_names = self._children.keys()
|
|
|
|
child_names.sort()
|
|
|
|
for child in child_names:
|
|
|
|
self._children[child].unproxy_all()
|
2006-09-06 07:04:34 +02:00
|
|
|
|
2007-08-30 21:16:59 +02:00
|
|
|
def print_ini(self, ini_file):
|
2008-09-10 20:26:15 +02:00
|
|
|
print >>ini_file, '[' + self.path() + ']' # .ini section header
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
instanceDict[self.path()] = self
|
|
|
|
|
2007-02-18 18:31:25 +01:00
|
|
|
if hasattr(self, 'type'):
|
2007-08-30 21:16:59 +02:00
|
|
|
print >>ini_file, 'type=%s' % self.type
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
child_names = self._children.keys()
|
|
|
|
child_names.sort()
|
2007-02-18 18:31:25 +01:00
|
|
|
if len(child_names):
|
2007-08-30 21:16:59 +02:00
|
|
|
print >>ini_file, 'children=%s' % ' '.join(child_names)
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
param_names = self._params.keys()
|
|
|
|
param_names.sort()
|
|
|
|
for param in param_names:
|
2006-09-06 07:04:34 +02:00
|
|
|
value = self._values.get(param)
|
2006-09-04 19:52:26 +02:00
|
|
|
if value != None:
|
2007-08-30 21:16:59 +02:00
|
|
|
print >>ini_file, '%s=%s' % (param,
|
|
|
|
self._values[param].ini_str())
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2006-09-05 21:22:47 +02:00
|
|
|
port_names = self._ports.keys()
|
|
|
|
port_names.sort()
|
|
|
|
for port_name in port_names:
|
2006-09-06 07:04:34 +02:00
|
|
|
port = self._port_refs.get(port_name, None)
|
|
|
|
if port != None:
|
2007-08-30 21:16:59 +02:00
|
|
|
print >>ini_file, '%s=%s' % (port_name, port.ini_str())
|
2006-09-05 21:22:47 +02:00
|
|
|
|
2008-09-10 20:26:15 +02:00
|
|
|
print >>ini_file # blank line between objects
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
for child in child_names:
|
2007-08-30 21:16:59 +02:00
|
|
|
self._children[child].print_ini(ini_file)
|
2006-09-04 19:52:26 +02:00
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
def getCCParams(self):
|
|
|
|
if self._ccParams:
|
|
|
|
return self._ccParams
|
|
|
|
|
2007-08-30 21:16:58 +02:00
|
|
|
cc_params_struct = getattr(m5.objects.params, '%sParams' % self.type)
|
2007-07-24 06:51:38 +02:00
|
|
|
cc_params = cc_params_struct()
|
2008-06-18 21:07:15 +02:00
|
|
|
cc_params.pyobj = self
|
2007-07-24 06:51:38 +02:00
|
|
|
cc_params.name = str(self)
|
|
|
|
|
|
|
|
param_names = self._params.keys()
|
|
|
|
param_names.sort()
|
|
|
|
for param in param_names:
|
|
|
|
value = self._values.get(param)
|
|
|
|
if value is None:
|
2009-01-31 02:04:15 +01:00
|
|
|
m5.fatal("%s.%s without default or user set value",
|
|
|
|
self.path(), param)
|
2007-07-24 06:51:38 +02:00
|
|
|
|
|
|
|
value = value.getValue()
|
|
|
|
if isinstance(self._params[param], VectorParamDesc):
|
|
|
|
assert isinstance(value, list)
|
|
|
|
vec = getattr(cc_params, param)
|
|
|
|
assert not len(vec)
|
|
|
|
for v in value:
|
|
|
|
vec.append(v)
|
|
|
|
else:
|
|
|
|
setattr(cc_params, param, value)
|
|
|
|
|
|
|
|
port_names = self._ports.keys()
|
|
|
|
port_names.sort()
|
|
|
|
for port_name in port_names:
|
|
|
|
port = self._port_refs.get(port_name, None)
|
|
|
|
if port != None:
|
|
|
|
setattr(cc_params, port_name, port)
|
|
|
|
self._ccParams = cc_params
|
|
|
|
return self._ccParams
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# Get C++ object corresponding to this object, calling C++ if
|
|
|
|
# necessary to construct it. Does *not* recursively create
|
|
|
|
# children.
|
|
|
|
def getCCObject(self):
|
|
|
|
if not self._ccObject:
|
2007-11-13 03:06:02 +01:00
|
|
|
# Cycles in the configuration heirarchy are not supported. This
|
|
|
|
# will catch the resulting recursion and stop.
|
|
|
|
self._ccObject = -1
|
|
|
|
params = self.getCCParams()
|
2007-07-24 06:51:38 +02:00
|
|
|
self._ccObject = params.create()
|
2006-09-04 19:52:26 +02:00
|
|
|
elif self._ccObject == -1:
|
2007-11-13 03:06:02 +01:00
|
|
|
raise RuntimeError, "%s: Cycle found in configuration heirarchy." \
|
2006-09-04 19:52:26 +02:00
|
|
|
% self.path()
|
|
|
|
return self._ccObject
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
# Call C++ to create C++ object corresponding to this object and
|
|
|
|
# (recursively) all its children
|
|
|
|
def createCCObject(self):
|
|
|
|
self.getCCParams()
|
|
|
|
self.getCCObject() # force creation
|
|
|
|
for child in self._children.itervalues():
|
|
|
|
child.createCCObject()
|
|
|
|
|
|
|
|
def getValue(self):
|
|
|
|
return self.getCCObject()
|
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
# Create C++ port connections corresponding to the connections in
|
2006-09-06 07:04:34 +02:00
|
|
|
# _port_refs (& recursively for all children)
|
2006-09-04 19:52:26 +02:00
|
|
|
def connectPorts(self):
|
2006-09-06 07:04:34 +02:00
|
|
|
for portRef in self._port_refs.itervalues():
|
|
|
|
portRef.ccConnect()
|
2006-09-04 19:52:26 +02:00
|
|
|
for child in self._children.itervalues():
|
|
|
|
child.connectPorts()
|
|
|
|
|
|
|
|
def startDrain(self, drain_event, recursive):
|
|
|
|
count = 0
|
2007-02-18 18:31:25 +01:00
|
|
|
if isinstance(self, SimObject):
|
2006-09-04 19:52:26 +02:00
|
|
|
count += self._ccObject.drain(drain_event)
|
|
|
|
if recursive:
|
|
|
|
for child in self._children.itervalues():
|
|
|
|
count += child.startDrain(drain_event, True)
|
|
|
|
return count
|
|
|
|
|
|
|
|
def resume(self):
|
2007-02-18 18:31:25 +01:00
|
|
|
if isinstance(self, SimObject):
|
2006-09-04 19:52:26 +02:00
|
|
|
self._ccObject.resume()
|
|
|
|
for child in self._children.itervalues():
|
|
|
|
child.resume()
|
|
|
|
|
2007-06-10 22:52:21 +02:00
|
|
|
def getMemoryMode(self):
|
|
|
|
if not isinstance(self, m5.objects.System):
|
|
|
|
return None
|
|
|
|
|
2007-08-03 07:50:02 +02:00
|
|
|
return self._ccObject.getMemoryMode()
|
2007-06-10 22:52:21 +02:00
|
|
|
|
2006-09-04 19:52:26 +02:00
|
|
|
def changeTiming(self, mode):
|
2006-10-12 00:53:50 +02:00
|
|
|
if isinstance(self, m5.objects.System):
|
|
|
|
# i don't know if there's a better way to do this - calling
|
|
|
|
# setMemoryMode directly from self._ccObject results in calling
|
|
|
|
# SimObject::setMemoryMode, not the System::setMemoryMode
|
2007-08-03 07:50:02 +02:00
|
|
|
self._ccObject.setMemoryMode(mode)
|
2006-09-04 19:52:26 +02:00
|
|
|
for child in self._children.itervalues():
|
|
|
|
child.changeTiming(mode)
|
|
|
|
|
|
|
|
def takeOverFrom(self, old_cpu):
|
2007-08-03 07:50:02 +02:00
|
|
|
self._ccObject.takeOverFrom(old_cpu._ccObject)
|
2006-09-04 19:52:26 +02:00
|
|
|
|
|
|
|
# generate output file for 'dot' to display as a pretty graph.
|
|
|
|
# this code is currently broken.
|
|
|
|
def outputDot(self, dot):
|
|
|
|
label = "{%s|" % self.path
|
|
|
|
if isSimObject(self.realtype):
|
|
|
|
label += '%s|' % self.type
|
|
|
|
|
|
|
|
if self.children:
|
|
|
|
# instantiate children in same order they were added for
|
|
|
|
# backward compatibility (else we can end up with cpu1
|
|
|
|
# before cpu0).
|
|
|
|
for c in self.children:
|
|
|
|
dot.add_edge(pydot.Edge(self.path,c.path, style="bold"))
|
|
|
|
|
|
|
|
simobjs = []
|
|
|
|
for param in self.params:
|
|
|
|
try:
|
|
|
|
if param.value is None:
|
|
|
|
raise AttributeError, 'Parameter with no value'
|
|
|
|
|
|
|
|
value = param.value
|
|
|
|
string = param.string(value)
|
|
|
|
except Exception, e:
|
|
|
|
msg = 'exception in %s:%s\n%s' % (self.name, param.name, e)
|
|
|
|
e.args = (msg, )
|
|
|
|
raise
|
|
|
|
|
|
|
|
if isSimObject(param.ptype) and string != "Null":
|
|
|
|
simobjs.append(string)
|
|
|
|
else:
|
|
|
|
label += '%s = %s\\n' % (param.name, string)
|
|
|
|
|
|
|
|
for so in simobjs:
|
|
|
|
label += "|<%s> %s" % (so, so)
|
|
|
|
dot.add_edge(pydot.Edge("%s:%s" % (self.path, so), so,
|
|
|
|
tailport="w"))
|
|
|
|
label += '}'
|
|
|
|
dot.add_node(pydot.Node(self.path,shape="Mrecord",label=label))
|
|
|
|
|
|
|
|
# recursively dump out children
|
|
|
|
for c in self.children:
|
|
|
|
c.outputDot(dot)
|
|
|
|
|
|
|
|
# Function to provide to C++ so it can look up instances based on paths
|
|
|
|
def resolveSimObject(name):
|
|
|
|
obj = instanceDict[name]
|
|
|
|
return obj.getCCObject()
|
|
|
|
|
|
|
|
# __all__ defines the list of symbols that get exported when
|
|
|
|
# 'from config import *' is invoked. Try to keep this reasonably
|
|
|
|
# short to avoid polluting other namespaces.
|
2007-07-24 06:51:38 +02:00
|
|
|
__all__ = [ 'SimObject' ]
|