Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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