def SimHandle(handle): """ Factory function to create the correct type of SimHandle object """ _type2cls = { simulator.MODULE: HierarchyObject, simulator.STRUCTURE: HierarchyObject, simulator.REG: ModifiableObject, simulator.NETARRAY: ModifiableObject, simulator.REAL: RealObject, simulator.INTEGER: IntegerObject, simulator.ENUM: ModifiableObject, simulator.STRING: StringObject, } # Enforce singletons since it's possible to retrieve handles avoiding # the hierarchy by getting driver/load information global _handle2obj try: return _handle2obj[handle] except KeyError: pass # Special case for constants if simulator.get_const(handle): obj = ConstantObject(handle, simulator.get_type(handle)) _handle2obj[handle] = obj return obj t = simulator.get_type(handle) if t not in _type2cls: raise TestError("Couldn't find a matching object for GPI type %d" % t) obj = _type2cls[t](handle) _handle2obj[handle] = obj return obj
def get_checkpoint_hier(entity): iterator = simulator.iterate(entity._handle, simulator.OBJECTS) while True: try: ii = simulator.next(iterator) except StopIteration: break hdl = SimHandle(ii, entity._path + "." + simulator.get_name_string(ii)) if ((simulator.get_type(ii) is simulator.MODULE) or (simulator.get_type(ii) is simulator.NETARRAY) or (simulator.get_type(ii) is simulator.GENARRAY)): get_checkpoint_hier(hdl) elif simulator.get_type(ii) is simulator.REG: checkpoint_hier.append(hdl)
def __getitem__(self, index): if index in self._sub_handles: return self._sub_handles[index] new_handle = simulator.get_handle_by_index(self._handle, index) if not new_handle: self._raise_testerror( "%s %s contains no object at index %d" % (self._name, simulator.get_type(self._handle), index)) self._sub_handles[index] = SimHandle(new_handle) return self._sub_handles[index]
def SimHandle(handle, path=None): """Factory function to create the correct type of `SimHandle` object. Args: handle (int): The GPI handle to the simulator object. path (str): Path to this handle, ``None`` if root. Returns: The `SimHandle` object. Raises: TestError: If no matching object for GPI type could be found. """ _type2cls = { simulator.MODULE: HierarchyObject, simulator.STRUCTURE: HierarchyObject, simulator.REG: ModifiableObject, simulator.NET: ModifiableObject, simulator.NETARRAY: NonHierarchyIndexableObject, simulator.REAL: RealObject, simulator.INTEGER: IntegerObject, simulator.ENUM: EnumObject, simulator.STRING: StringObject, simulator.GENARRAY: HierarchyArrayObject, } # Enforce singletons since it's possible to retrieve handles avoiding # the hierarchy by getting driver/load information global _handle2obj try: return _handle2obj[handle] except KeyError: pass t = simulator.get_type(handle) # Special case for constants if simulator.get_const(handle) and t not in [ simulator.MODULE, simulator.STRUCTURE, simulator.NETARRAY, simulator.GENARRAY ]: obj = ConstantObject(handle, path, t) _handle2obj[handle] = obj return obj if t not in _type2cls: raise TestError( "Couldn't find a matching object for GPI type %d (path=%s)" % (t, path)) obj = _type2cls[t](handle, path) _handle2obj[handle] = obj return obj
def SimHandle(handle, path=None): """Factory function to create the correct type of :any:`SimHandle` object.""" _type2cls = { simulator.MODULE: HierarchyObject, simulator.STRUCTURE: HierarchyObject, simulator.REG: ModifiableObject, simulator.NETARRAY: NonHierarchyIndexableObject, simulator.REAL: RealObject, simulator.INTEGER: IntegerObject, simulator.ENUM: EnumObject, simulator.STRING: StringObject, simulator.GENARRAY: HierarchyArrayObject, } # Enforce singletons since it's possible to retrieve handles avoiding # the hierarchy by getting driver/load information global _handle2obj try: return _handle2obj[handle] except KeyError: pass t = simulator.get_type(handle) # Special case for constants if simulator.get_const(handle) and not t in [simulator.MODULE, simulator.STRUCTURE, simulator.NETARRAY, simulator.GENARRAY]: obj = ConstantObject(handle, path, t) _handle2obj[handle] = obj return obj if t not in _type2cls: raise TestError("Couldn't find a matching object for GPI type %d (path=%s)" % (t, path)) obj = _type2cls[t](handle, path) _handle2obj[handle] = obj return obj
def __getitem__(self, index): if index in self._sub_handles: return self._sub_handles[index] new_handle = simulator.get_handle_by_index(self._handle, index) if not new_handle: self._raise_testerror("%s %s contains no object at index %d" % (self._name, simulator.get_type(self._handle), index)) self._sub_handles[index] = SimHandle(new_handle) return self._sub_handles[index]