Deleted Added
sdiff udiff text old ( 10195:7d4d0cd3f7e5 ) new ( 10267:ed97f6f2ed7a )
full compact
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 158 unchanged lines hidden (view full) ---

167 # initialize required attributes
168
169 # class-only attributes
170 cls._params = multidict() # param descriptions
171 cls._ports = multidict() # port descriptions
172
173 # class or instance attributes
174 cls._values = multidict() # param values
175 cls._children = multidict() # SimObject children
176 cls._port_refs = multidict() # port ref objects
177 cls._instantiated = False # really instantiated, cloned, or subclassed
178
179 # We don't support multiple inheritance of sim objects. If you want
180 # to, you must fix multidict to deal with it properly. Non sim-objects
181 # are ok, though
182 bTotal = 0

--- 9 unchanged lines hidden (view full) ---

192 # inherit all its settings from the base class. The only time
193 # the following is not true is when we define the SimObject
194 # class itself (in which case the multidicts have no parent).
195 if isinstance(base, MetaSimObject):
196 cls._base = base
197 cls._params.parent = base._params
198 cls._ports.parent = base._ports
199 cls._values.parent = base._values
200 cls._children.parent = base._children
201 cls._port_refs.parent = base._port_refs
202 # mark base as having been subclassed
203 base._instantiated = True
204 else:
205 cls._base = None
206
207 # default keyword values

--- 60 unchanged lines hidden (view full) ---

268 pdesc.name = name
269 cls._params[name] = pdesc
270 if hasattr(pdesc, 'default'):
271 cls._set_param(name, pdesc.default, pdesc)
272
273 def _set_param(cls, name, value, param):
274 assert(param.name == name)
275 try:
276 value = param.convert(value)
277 except Exception, e:
278 msg = "%s\nError setting param %s.%s to %s\n" % \
279 (e, cls.__name__, name, value)
280 e.args = (msg, )
281 raise
282 cls._values[name] = value
283 # if param value is a SimObject, make it a child too, so that
284 # it gets cloned properly when the class is instantiated
285 if isSimObjectOrVector(value) and not value.has_parent():
286 cls._add_cls_child(name, value)
287
288 def _add_cls_child(cls, name, child):
289 # It's a little funky to have a class as a parent, but these
290 # objects should never be instantiated (only cloned, which
291 # clears the parent pointer), and this makes it clear that the
292 # object is not an orphan and can provide better error
293 # messages.
294 child.set_parent(cls, name)

--- 285 unchanged lines hidden (view full) ---

580# SimObject class definition to the MetaSimObject methods (in
581# particular _set_param, which gets called for parameters with default
582# values defined on the SimObject class itself). It will get
583# overridden by the permanent definition (which requires that
584# SimObject be defined) lower in this file.
585def isSimObjectOrVector(value):
586 return False
587
588# The SimObject class is the root of the special hierarchy. Most of
589# the code in this class deals with the configuration hierarchy itself
590# (parent/child node relationships).
591class SimObject(object):
592 # Specify metaclass. Any class inheriting from SimObject will
593 # get this metaclass.
594 __metaclass__ = MetaSimObject
595 type = 'SimObject'

--- 20 unchanged lines hidden (view full) ---

616 void initState();
617 void regStats();
618 void resetStats();
619 void regProbePoints();
620 void regProbeListeners();
621 void startup();
622''')
623
624 # Initialize new instance. For objects with SimObject-valued
625 # children, we need to recursively clone the classes represented
626 # by those param values as well in a consistent "deep copy"-style
627 # fashion. That is, we want to make sure that each instance is
628 # cloned only once, and that if there are multiple references to
629 # the same original object, we end up with the corresponding
630 # cloned references all pointing to the same cloned instance.
631 def __init__(self, **kwargs):

--- 24 unchanged lines hidden (view full) ---

656 self._children = {}
657 for key,val in ancestor._children.iteritems():
658 self.add_child(key, val(_memo=memo_dict))
659
660 # Inherit parameter values from class using multidict so
661 # individual value settings can be overridden but we still
662 # inherit late changes to non-overridden class values.
663 self._values = multidict(ancestor._values)
664 # clone SimObject-valued parameters
665 for key,val in ancestor._values.iteritems():
666 val = tryAsSimObjectOrVector(val)
667 if val is not None:
668 self._values[key] = val(_memo=memo_dict)
669
670 # clone port references. no need to use a multidict here
671 # since we will be creating new references for all ports.

--- 74 unchanged lines hidden (view full) ---

746 if self._ports.has_key(attr):
747 # set up port connection
748 self._get_port_ref(attr).connect(value)
749 return
750
751 param = self._params.get(attr)
752 if param:
753 try:
754 value = param.convert(value)
755 except Exception, e:
756 msg = "%s\nError setting param %s.%s to %s\n" % \
757 (e, self.__class__.__name__, attr, value)
758 e.args = (msg, )
759 raise
760 self._values[attr] = value
761 # implicitly parent unparented objects assigned as params
762 if isSimObjectOrVector(value) and not value.has_parent():
763 self.add_child(attr, value)
764 return
765
766 # if RHS is a SimObject, it's an implicit child assignment
767 if isSimObjectOrSequence(value):
768 self.add_child(attr, value)
769 return
770
771 # no valid assignment... raise exception
772 raise AttributeError, "Class %s has no parameter %s" \
773 % (self.__class__.__name__, attr)
774
775
776 # this hack allows tacking a '[0]' onto parameters that may or may
777 # not be vectors, and always getting the first element (e.g. cpus)
778 def __getitem__(self, key):
779 if key == 0:
780 return self
781 raise TypeError, "Non-zero index '%s' to SimObject" % key
782
783 # Also implemented by SimObjectVector
784 def clear_parent(self, old_parent):
785 assert self._parent is old_parent
786 self._parent = None
787
788 # Also implemented by SimObjectVector
789 def set_parent(self, parent, name):
790 self._parent = parent

--- 258 unchanged lines hidden (view full) ---

1049 def getCCObject(self):
1050 if not self._ccObject:
1051 # Make sure this object is in the configuration hierarchy
1052 if not self._parent and not isRoot(self):
1053 raise RuntimeError, "Attempt to instantiate orphan node"
1054 # Cycles in the configuration hierarchy are not supported. This
1055 # will catch the resulting recursion and stop.
1056 self._ccObject = -1
1057 params = self.getCCParams()
1058 self._ccObject = params.create()
1059 elif self._ccObject == -1:
1060 raise RuntimeError, "%s: Cycle found in configuration hierarchy." \
1061 % self.path()
1062 return self._ccObject
1063
1064 def descendants(self):
1065 yield self
1066 for child in self._children.itervalues():

--- 78 unchanged lines hidden ---