示例#1
0
def _load_tags(n):
    res = []
    for t in n.findall("p:T", ns):
        key = get_attrib(t, "key")
        pre = False if "0" == get_attrib(t, "pre") else True
        res.append((pre, key))
    return res
示例#2
0
def load_graph_instance(graphTypes, graphNode):
    devITag = "{{{}}}DevI".format(ns["p"])
    extITag = "{{{}}}ExtI".format(ns["p"])
    edgeITag = "{{{}}}EdgeI".format(ns["p"])

    id = get_attrib(graphNode, "id")
    graphTypeId = get_attrib(graphNode, "graphTypeId")
    graphType = graphTypes[graphTypeId]

    properties = load_struct_instance(graphType.properties, graphNode, "P")
    metadata = None  # TODO: Load metadata
    documentation = None

    graph = GraphInstance(id, graphType, properties, metadata, documentation)
    disNode = graphNode.findall("p:DeviceInstances", ns)
    assert (len(disNode) == 1)
    for diNode in disNode[0]:
        assert (diNode.tag == devITag) or (diNode.tag == extITag)
        if diNode.tag == devITag:
            di = load_device_instance(graph, diNode)
            graph.add_device_instance(di)
        elif diNode.tag == extITag:
            ei = load_external_instance(graph, diNode)
            graph.add_device_instance(ei)

    eisNode = graphNode.findall("p:EdgeInstances", ns)
    assert (len(eisNode) == 1)
    for eiNode in eisNode[0]:
        assert eiNode.tag == edgeITag
        ei = load_edge_instance(graph, eiNode)
        graph.add_edge_instance(ei)

    return graph
示例#3
0
def extractSendEvent(n, writer):
    eventId = get_attrib(n, "eventId")
    time = float(get_attrib(n, "time"))
    elapsed = float(get_attrib(n, "elapsed"))
    tags = _load_tags(n)
    dev = get_attrib(n, "dev")
    rts = int(get_attrib(n, "rts"), 0)
    seq = int(get_attrib(n, "seq"))

    L = []
    for l in n.findall("p:L", ns):
        L.append(l.text)

    S = n.find("p:S", ns)
    if S is not None and S.text is not None:
        try:
            S = json.loads("{" + S.text + "}")
        except:
            sys.stderr.write("p:S = '{}'".format("{" + S.text + "}"))
            raise

    pin = get_attrib(n, "pin")
    cancel = bool(get_attrib(n, "cancel"))
    fanout = int(get_attrib(n, "fanout"))

    M = n.find("p:M", ns)
    if M is not None:
        M = json.loads("{" + M.text + "}")

    writer.onSendEvent(
        SendEvent(eventId, time, elapsed, tags, dev, rts, seq, L, S, pin,
                  cancel, fanout, M))
示例#4
0
def load_external_type(graph, dtNode, sourceFile):
    id = get_attrib(dtNode, "id")
    state = None
    properties = load_struct_spec(dtNode, "p:Properties")
    shared_code = []
    metadata = None
    documentation = None
    dt = DeviceType(graph, id, properties, state, metadata, shared_code, True,
                    documentation)

    for p in dtNode.findall("p:InputPin", ns):
        name = get_attrib(p, "name")
        message_type_id = get_attrib(p, "messageTypeId")
        if message_type_id not in graph.message_types:
            raise XMLSyntaxError(
                "Unknown messageTypeId {}".format(message_type_id), p)
        message_type = graph.message_types[message_type_id]
        state = None  # pins of ExternalType cannot have any state, properties, or handlers
        properties = None
        handler = ''
        is_application = False  # Legacy: must be false, eventually will be removed
        sourceLine = 0
        pinMetadata = None

        dt.add_input(name, message_type, is_application, properties, state,
                     pinMetadata, handler, sourceFile, sourceLine)
        sys.stderr.write("      Added external input {}\n".format(name))

    for p in dtNode.findall("p:OutputPin", ns):
        name = get_attrib(p, "name")
        message_type_id = get_attrib(p, "messageTypeId")
        if message_type_id not in graph.message_types:
            raise XMLSyntaxError(
                "Unknown messageTypeId {}".format(message_type_id), p)
        message_type = graph.message_types[message_type_id]
        is_application = False  # Legacy: must be false, eventually will be removed
        handler = ''
        sourceLine = 0
        pinMetadata = None

        dt.add_output(name, message_type, is_application, pinMetadata, handler,
                      sourceFile, sourceLine)
        sys.stderr.write("      Added external output {}\n".format(name))

    dt.ready_to_send_handler = ''
    dt.ready_to_send_source_line = 0
    dt.ready_to_send_source_file = None

    return dt
示例#5
0
def load_external_instance(graph, eiNode):

    id = get_attrib(eiNode, "id")
    external_type_id = get_attrib(eiNode, "type")
    if external_type_id not in graph.graph_type.device_types:
        raise XMLSyntaxError(
            "Unknown external type id {}, known devices = [{}]".format(
                external_type_id,
                [d.di for d in graph.graph_type.deivce_types.keys()]), eiNode)
    external_type = graph.graph_type.device_types[external_type_id]

    properties = load_struct_instance(external_type.properties, eiNode, "P")
    metadata = None

    return DeviceInstance(graph, id, external_type, properties, metadata)
示例#6
0
def load_device_instance(graph, diNode):

    id = get_attrib(diNode, "id")
    device_type_id = get_attrib(diNode, "type")
    if device_type_id not in graph.graph_type.device_types:
        raise XMLSyntaxError(
            "Unknown device type id {}, known devices = [{}]".format(
                device_type_id,
                [d.id for d in graph.graph_type.device_types.keys()]), diNode)
    device_type = graph.graph_type.device_types[device_type_id]

    properties = load_struct_instance(device_type.properties, diNode, "P")
    state = load_struct_instance(device_type.state, diNode, "S")
    state = None
    metadata = None

    return DeviceInstance(graph, id, device_type, properties, state, metadata)
示例#7
0
def load_message_type(parent, mtElt):
    id = get_attrib(mtElt, "id")
    try:
        message = load_struct_spec(mtElt, "p:Message")
        return MessageType(
            parent,
            id,
            message,
        )
    except XMLSyntaxError:
        raise
    except Exception as e:
        raise XMLSyntaxError("Error while parsing message type {}".format(id),
                             mtElt, e)
示例#8
0
def extractRecvEvent(n, writer):
    eventId = get_attrib(n, "eventId")
    time = float(get_attrib(n, "time"))
    elapsed = float(get_attrib(n, "elapsed"))
    tags = _load_tags(n)
    dev = get_attrib(n, "dev")
    rts = int(get_attrib(n, "rts"), 0)
    seq = int(get_attrib(n, "seq"))

    L = []
    for l in n.findall("p:L", ns):
        L.append(l.text)

    S = n.find("p:S", ns)
    if S is not None and S.text is not None:
        S = json.loads("{" + S.text + "}")

    pin = get_attrib(n, "pin")
    sendEventId = get_attrib(n, "sendEventId")

    writer.onRecvEvent(
        RecvEvent(eventId, time, elapsed, tags, dev, rts, seq, L, S, pin,
                  sendEventId))
示例#9
0
def extractHardwareIdleEvent(n, writer):
    eventId = get_attrib(n, "eventId")
    time = float(get_attrib(n, "time"))
    elapsed = float(get_attrib(n, "elapsed"))
    tags = _load_tags(n)
    dev = get_attrib(n, "dev")
    rts = int(get_attrib(n, "rts"), 0)
    seq = int(get_attrib(n, "seq"))
    barrierId = get_attrib(n, "barrierId")

    L = []
    for l in n.findall("p:L", ns):
        L.append(l.text)

    S = n.find("p:S", ns)
    if S is not None and S.text is not None:
        #print(S.text)
        S = json.loads("{" + S.text + "}")

    e = HardwareIdleEvent(eventId, time, elapsed, tags, dev, rts, seq, L, S,
                          barrierId)
    writer.onHardwareIdleEvent(e)
示例#10
0
def load_graph_type(graphNode, sourcePath):
    deviceTypeTag = "{{{}}}DeviceType".format(ns["p"])
    externalTypeTag = "{{{}}}ExternalType".format(ns["p"])

    id = get_attrib(graphNode, "id")
    sys.stderr.write("  Loading graph type {}\n".format(id))

    properties = load_struct_spec(graphNode, "p:Properties")
    metadata = None
    documentation = None

    shared_code = []
    tt = get_child_text(graphNode, "p:SharedCode", ns)[0]
    if tt is not None:
        shared_code.append(tt)
    graphType = GraphType(id, properties, metadata, shared_code, documentation)

    for etNode in graphNode.findall("p:MessageTypes/p:*", ns):
        et = load_message_type(graphType, etNode)
        graphType.add_message_type(et)

    for dtNode in graphNode.findall("p:DeviceTypes/p:*", ns):

        if dtNode.tag == deviceTypeTag:
            dt = load_device_type(graphType, dtNode, sourcePath)
            graphType.add_device_type(dt)
            #sys.stderr.write("    Added device type {}\n".format(dt.id))
        elif dtNode.tag == externalTypeTag:
            et = load_external_type(graphType, dtNode, sourcePath)
            graphType.add_device_type(et)
            #sys.stderr.write("    Added external device type {}\n".format(et.id))
        else:
            raise RuntimeError(
                f"Unknown or unsupported element in DeviceTypes: {dtNode.tag}")

    return graphType
示例#11
0
def load_device_type(graph, dtNode, sourceFile):
    id = get_attrib(dtNode, "id")

    properties = load_struct_spec(dtNode, "p:Properties")
    state = load_struct_spec(dtNode, "p:State")

    shared_code = []
    tt = get_child_text(dtNode, "p:SharedCode", ns)[0]
    if tt is not None:
        shared_code.append(tt)
    metadata = None
    documentation = None
    dt = DeviceType(graph,
                    id,
                    properties,
                    state,
                    metadata,
                    shared_code,
                    isExternal=False,
                    documentation=documentation)

    for p in dtNode.findall("p:InputPin", ns):
        name = get_attrib(p, "name")
        message_type_id = get_attrib(p, "messageTypeId")
        if message_type_id not in graph.message_types:
            raise XMLSyntaxError(
                "Unknown messageTypeId {}".format(message_type_id), p)
        message_type = graph.message_types[message_type_id]
        # NOTE: application pin support needed for as long as 2to3 is relevant.
        is_application = get_attrib_optional_bool(
            p, "application")  # TODO: REMOVE APPLICATION PIN
        properties = load_struct_spec(p, "p:Properties")
        state = load_struct_spec(p, "p:State")
        pinMetadata = None
        documentation = None

        (handler, sourceLine) = get_child_text(p, "p:OnReceive", ns)
        dt.add_input(name, message_type, is_application, properties, state,
                     pinMetadata, handler, sourceFile, sourceLine,
                     documentation)
        #sys.stderr.write("      Added input {}\n".format(name))

    for p in dtNode.findall("p:OutputPin", ns):
        name = get_attrib(p, "name")
        message_type_id = get_attrib(p, "messageTypeId")
        if message_type_id not in graph.message_types:
            raise XMLSyntaxError(
                "Unknown messageTypeId {}".format(message_type_id), p)
        is_application = False
        is_indexed = get_attrib_optional_bool(p, "indexed")
        message_type = graph.message_types[message_type_id]
        pinMetadata = None
        (handler, sourceLine) = get_child_text(p, "p:OnSend", ns)
        documentation = None
        dt.add_output(name, message_type, is_application, pinMetadata, handler,
                      sourceFile, sourceLine, documentation, is_indexed)
        #sys.stderr.write("      Added input {}\n".format(name))

    (handler, sourceLine) = get_child_text(dtNode, "p:ReadyToSend", ns)
    dt.ready_to_send_handler = handler
    dt.ready_to_send_source_line = sourceLine
    dt.ready_to_send_source_file = sourceFile

    (handler, sourceLine) = get_child_text(dtNode, "p:OnInit", ns)
    dt.init_handler = handler
    dt.init_source_line = sourceLine
    dt.init_source_file = sourceFile

    (handler, sourceLine) = get_child_text(dtNode, "p:OnHardwareIdle", ns)
    dt.on_hardware_idle_handler = handler
    dt.on_hardware_idle_source_line = sourceLine
    dt.on_hardware_idle_source_file = sourceFile

    (handler, sourceLine) = get_child_text(dtNode, "p:OnDeviceIdle", ns)
    dt.on_device_idle_handler = handler
    dt.on_device_idle_source_line = sourceLine
    dt.on_device_idle_source_file = sourceFile

    return dt