Deleted Added
sdiff udiff text old ( 7811:a8fc35183c10 ) new ( 8321:9f34cf472451 )
full compact
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# Copyright (c) 2010 Advanced Micro Devices, Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

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

273 pdesc.name = name
274 cls._params[name] = pdesc
275 if hasattr(pdesc, 'default'):
276 cls._set_param(name, pdesc.default, pdesc)
277
278 def _set_param(cls, name, value, param):
279 assert(param.name == name)
280 try:
281 cls._values[name] = param.convert(value)
282 except Exception, e:
283 msg = "%s\nError setting param %s.%s to %s\n" % \
284 (e, cls.__name__, name, value)
285 e.args = (msg, )
286 raise
287
288 def _new_port(cls, name, port):
289 # each port should be uniquely assigned to one variable
290 assert(not hasattr(port, 'name'))
291 port.name = name
292 cls._ports[name] = port
293 if hasattr(port, 'default'):
294 cls._cls_get_port_ref(name).connect(port.default)
295

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

329 # check for param
330 param = cls._params.get(attr)
331 if param:
332 cls._set_param(attr, value, param)
333 return
334
335 if isSimObjectOrSequence(value):
336 # If RHS is a SimObject, it's an implicit child assignment.
337 cls._children[attr] = coerceSimObjectOrVector(value)
338 return
339
340 # no valid assignment... raise exception
341 raise AttributeError, \
342 "Class %s has no parameter \'%s\'" % (cls.__name__, attr)
343
344 def __getattr__(cls, attr):
345 if attr == 'cxx_class_path':

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

503
504 # initialize required attributes
505 self._parent = None
506 self._name = None
507 self._ccObject = None # pointer to C++ object
508 self._ccParams = None
509 self._instantiated = False # really "cloned"
510
511 # Inherit parameter values from class using multidict so
512 # individual value settings can be overridden but we still
513 # inherit late changes to non-overridden class values.
514 self._values = multidict(ancestor._values)
515 # clone SimObject-valued parameters
516 for key,val in ancestor._values.iteritems():
517 val = tryAsSimObjectOrVector(val)
518 if val is not None:
519 self._values[key] = val(_memo=memo_dict)
520
521 # Clone children specified at class level. No need for a
522 # multidict here since we will be cloning everything.
523 self._children = {}
524 for key,val in ancestor._children.iteritems():
525 self.add_child(key, val(_memo=memo_dict))
526
527 # clone port references. no need to use a multidict here
528 # since we will be creating new references for all ports.
529 self._port_refs = {}
530 for key,val in ancestor._port_refs.iteritems():
531 self._port_refs[key] = val.clone(self, memo_dict)
532 # apply attribute assignments from keyword args, if any
533 for key,val in kwargs.iteritems():
534 setattr(self, key, val)

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

609 try:
610 value = param.convert(value)
611 except Exception, e:
612 msg = "%s\nError setting param %s.%s to %s\n" % \
613 (e, self.__class__.__name__, attr, value)
614 e.args = (msg, )
615 raise
616 self._values[attr] = value
617 return
618
619 # if RHS is a SimObject, it's an implicit child assignment
620 if isSimObjectOrSequence(value):
621 self.add_child(attr, value)
622 return
623
624 # no valid assignment... raise exception

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

642 def set_parent(self, parent, name):
643 self._parent = parent
644 self._name = name
645
646 # Also implemented by SimObjectVector
647 def get_name(self):
648 return self._name
649
650 # use this rather than directly accessing _parent for symmetry
651 # with SimObjectVector
652 def get_parent(self):
653 return self._parent
654
655 # clear out child with given name. This code is not likely to be exercised.
656 # See comment in add_child.
657 def clear_child(self, name):
658 child = self._children[name]
659 child.clear_parent(self)
660 del self._children[name]
661
662 # Add a new child to this object.
663 def add_child(self, name, child):
664 child = coerceSimObjectOrVector(child)
665 if child.get_parent():
666 raise RuntimeError, \
667 "add_child('%s'): child '%s' already has parent '%s'" % \
668 (name, child._name, child._parent)
669 if self._children.has_key(name):
670 # This code path had an undiscovered bug that would make it fail
671 # at runtime. It had been here for a long time and was only
672 # exposed by a buggy script. Changes here will probably not be
673 # exercised without specialized testing.
674 self.clear_child(name)
675 child.set_parent(self, name)
676 self._children[name] = child
677
678 # Take SimObject-valued parameters that haven't been explicitly
679 # assigned as children and make them children of the object that
680 # they were assigned to as a parameter value. This guarantees
681 # that when we instantiate all the parameter objects we're still
682 # inside the configuration hierarchy.
683 def adoptOrphanParams(self):
684 for key,val in self._values.iteritems():
685 if not isSimObjectVector(val) and isSimObjectSequence(val):
686 # need to convert raw SimObject sequences to
687 # SimObjectVector class so we can call get_parent()
688 val = SimObjectVector(val)
689 self._values[key] = val
690 if isSimObjectOrVector(val) and not val.get_parent():
691 self.add_child(key, val)
692
693 def path(self):
694 if not self._parent:
695 return '(orphan)'
696 ppath = self._parent.path()
697 if ppath == 'root':
698 return self._name
699 return ppath + "." + self._name
700
701 def __str__(self):
702 return self.path()
703

--- 273 unchanged lines hidden ---