SimObject.py (13663:9b64aeabf9a5) SimObject.py (13675:afeab32b3655)
1# Copyright (c) 2017-2018 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

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

529 if isinstance(val, ParamDesc):
530 cls._new_param(key, val)
531
532 # port objects
533 elif isinstance(val, Port):
534 cls._new_port(key, val)
535
536 # init-time-only keywords
1# Copyright (c) 2017-2018 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

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

529 if isinstance(val, ParamDesc):
530 cls._new_param(key, val)
531
532 # port objects
533 elif isinstance(val, Port):
534 cls._new_port(key, val)
535
536 # init-time-only keywords
537 elif cls.init_keywords.has_key(key):
537 elif key in cls.init_keywords:
538 cls._set_keyword(key, val, cls.init_keywords[key])
539
540 # default: use normal path (ends up in __setattr__)
541 else:
542 setattr(cls, key, val)
543
544 def _set_keyword(cls, keyword, val, kwtype):
545 if not isinstance(val, kwtype):

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

608 # Set attribute (called on foo.attr = value when foo is an
609 # instance of class cls).
610 def __setattr__(cls, attr, value):
611 # normal processing for private attributes
612 if public_value(attr, value):
613 type.__setattr__(cls, attr, value)
614 return
615
538 cls._set_keyword(key, val, cls.init_keywords[key])
539
540 # default: use normal path (ends up in __setattr__)
541 else:
542 setattr(cls, key, val)
543
544 def _set_keyword(cls, keyword, val, kwtype):
545 if not isinstance(val, kwtype):

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

608 # Set attribute (called on foo.attr = value when foo is an
609 # instance of class cls).
610 def __setattr__(cls, attr, value):
611 # normal processing for private attributes
612 if public_value(attr, value):
613 type.__setattr__(cls, attr, value)
614 return
615
616 if cls.keywords.has_key(attr):
616 if attr in cls.keywords:
617 cls._set_keyword(attr, value, cls.keywords[attr])
618 return
619
617 cls._set_keyword(attr, value, cls.keywords[attr])
618 return
619
620 if cls._ports.has_key(attr):
620 if attr in cls._ports:
621 cls._cls_get_port_ref(attr).connect(value)
622 return
623
624 if isSimObjectOrSequence(value) and cls._instantiated:
625 raise RuntimeError(
626 "cannot set SimObject parameter '%s' after\n" \
627 " class %s has been instantiated or subclassed" \
628 % (attr, cls.__name__))

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

647 return cls.cxx_class.split('::')
648
649 if attr == 'cxx_class_name':
650 return cls.cxx_class_path[-1]
651
652 if attr == 'cxx_namespaces':
653 return cls.cxx_class_path[:-1]
654
621 cls._cls_get_port_ref(attr).connect(value)
622 return
623
624 if isSimObjectOrSequence(value) and cls._instantiated:
625 raise RuntimeError(
626 "cannot set SimObject parameter '%s' after\n" \
627 " class %s has been instantiated or subclassed" \
628 % (attr, cls.__name__))

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

647 return cls.cxx_class.split('::')
648
649 if attr == 'cxx_class_name':
650 return cls.cxx_class_path[-1]
651
652 if attr == 'cxx_namespaces':
653 return cls.cxx_class_path[:-1]
654
655 if cls._values.has_key(attr):
655 if attr in cls._values:
656 return cls._values[attr]
657
656 return cls._values[attr]
657
658 if cls._children.has_key(attr):
658 if attr in cls._children:
659 return cls._children[attr]
660
661 raise AttributeError(
662 "object '%s' has no attribute '%s'" % (cls.__name__, attr))
663
664 def __str__(cls):
665 return cls.__name__
666

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

1153 # this is only allowed at the root of a hierarchy
1154 if self._parent:
1155 raise RuntimeError("attempt to clone object %s " \
1156 "not at the root of a tree (parent = %s)" \
1157 % (self, self._parent))
1158 # create a new dict and use that.
1159 memo_dict = {}
1160 kwargs['_memo'] = memo_dict
659 return cls._children[attr]
660
661 raise AttributeError(
662 "object '%s' has no attribute '%s'" % (cls.__name__, attr))
663
664 def __str__(cls):
665 return cls.__name__
666

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

1153 # this is only allowed at the root of a hierarchy
1154 if self._parent:
1155 raise RuntimeError("attempt to clone object %s " \
1156 "not at the root of a tree (parent = %s)" \
1157 % (self, self._parent))
1158 # create a new dict and use that.
1159 memo_dict = {}
1160 kwargs['_memo'] = memo_dict
1161 elif memo_dict.has_key(self):
1161 elif self in memo_dict:
1162 # clone already done & memoized
1163 return memo_dict[self]
1164 return self.__class__(_ancestor = self, **kwargs)
1165
1166 def _get_port_ref(self, attr):
1167 # Return reference that can be assigned to another port
1168 # via __setattr__. There is only ever one reference
1169 # object per port, but we create them lazily here.
1170 ref = self._port_refs.get(attr)
1171 if ref == None:
1172 ref = self._ports[attr].makeRef(self)
1173 self._port_refs[attr] = ref
1174 return ref
1175
1176 def __getattr__(self, attr):
1162 # clone already done & memoized
1163 return memo_dict[self]
1164 return self.__class__(_ancestor = self, **kwargs)
1165
1166 def _get_port_ref(self, attr):
1167 # Return reference that can be assigned to another port
1168 # via __setattr__. There is only ever one reference
1169 # object per port, but we create them lazily here.
1170 ref = self._port_refs.get(attr)
1171 if ref == None:
1172 ref = self._ports[attr].makeRef(self)
1173 self._port_refs[attr] = ref
1174 return ref
1175
1176 def __getattr__(self, attr):
1177 if self._ports.has_key(attr):
1177 if attr in self._ports:
1178 return self._get_port_ref(attr)
1179
1178 return self._get_port_ref(attr)
1179
1180 if self._values.has_key(attr):
1180 if attr in self._values:
1181 return self._values[attr]
1182
1181 return self._values[attr]
1182
1183 if self._children.has_key(attr):
1183 if attr in self._children:
1184 return self._children[attr]
1185
1186 # If the attribute exists on the C++ object, transparently
1187 # forward the reference there. This is typically used for
1188 # methods exported to Python (e.g., init(), and startup())
1189 if self._ccObject and hasattr(self._ccObject, attr):
1190 return getattr(self._ccObject, attr)
1191

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

1201 # Set attribute (called on foo.attr = value when foo is an
1202 # instance of class cls).
1203 def __setattr__(self, attr, value):
1204 # normal processing for private attributes
1205 if attr.startswith('_'):
1206 object.__setattr__(self, attr, value)
1207 return
1208
1184 return self._children[attr]
1185
1186 # If the attribute exists on the C++ object, transparently
1187 # forward the reference there. This is typically used for
1188 # methods exported to Python (e.g., init(), and startup())
1189 if self._ccObject and hasattr(self._ccObject, attr):
1190 return getattr(self._ccObject, attr)
1191

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

1201 # Set attribute (called on foo.attr = value when foo is an
1202 # instance of class cls).
1203 def __setattr__(self, attr, value):
1204 # normal processing for private attributes
1205 if attr.startswith('_'):
1206 object.__setattr__(self, attr, value)
1207 return
1208
1209 if self._ports.has_key(attr):
1209 if attr in self._ports:
1210 # set up port connection
1211 self._get_port_ref(attr).connect(value)
1212 return
1213
1214 param = self._params.get(attr)
1215 if param:
1216 try:
1217 hr_value = value

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

1289 del self._children[name]
1290
1291 # Add a new child to this object.
1292 def add_child(self, name, child):
1293 child = coerceSimObjectOrVector(child)
1294 if child.has_parent():
1295 warn("add_child('%s'): child '%s' already has parent", name,
1296 child.get_name())
1210 # set up port connection
1211 self._get_port_ref(attr).connect(value)
1212 return
1213
1214 param = self._params.get(attr)
1215 if param:
1216 try:
1217 hr_value = value

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

1289 del self._children[name]
1290
1291 # Add a new child to this object.
1292 def add_child(self, name, child):
1293 child = coerceSimObjectOrVector(child)
1294 if child.has_parent():
1295 warn("add_child('%s'): child '%s' already has parent", name,
1296 child.get_name())
1297 if self._children.has_key(name):
1297 if name in self._children:
1298 # This code path had an undiscovered bug that would make it fail
1299 # at runtime. It had been here for a long time and was only
1300 # exposed by a buggy script. Changes here will probably not be
1301 # exercised without specialized testing.
1302 self.clear_child(name)
1303 child.set_parent(self, name)
1304 if not isNullPointer(child):
1305 self._children[name] = child

--- 369 unchanged lines hidden ---
1298 # This code path had an undiscovered bug that would make it fail
1299 # at runtime. It had been here for a long time and was only
1300 # exposed by a buggy script. Changes here will probably not be
1301 # exercised without specialized testing.
1302 self.clear_child(name)
1303 child.set_parent(self, name)
1304 if not isNullPointer(child):
1305 self._children[name] = child

--- 369 unchanged lines hidden ---