Ejemplo n.º 1
0
def import_definition(cls, filenames, dummy):
    """

    :param cls:
    :type cls:
    :param filenames:
    :type filenames:
    :param dummy:
    :type dummy:
    """

    LOG.info("Start importing element type definitions")

    element_types = {}

    for filename in filenames:
        element_type_data = read_yaml(filename, SCHEMA)

        if element_type_data is None:
            continue

        for elem in element_type_data:
            name = elem["Name"]
            descr = elem.get("Description", "No description")

            element_type = cls(name, descr)
            element_types[name] = element_type

            LOG.debug(element_type)

    for filename in filenames:
        import_properties(filename, element_types)

    LOG.info("End importing element type definitions")
    return element_types
Ejemplo n.º 2
0
    def add_properties_to_isa(self, instructions):
        """

        :param instructions:

        """
        for cfile in self._instruction_property_defs:
            import_properties(cfile, instructions)
Ejemplo n.º 3
0
def import_microarchitecture_definition(path):
    """Imports a Microarchitecture definition given a path

    :param path:

    """

    LOG.info("Start microarchitecture import")
    LOG.debug("Importing definition from '%s'", path)

    if not os.path.isabs(path):
        path = os.path.abspath(path)

    uarchdef = _read_yaml_definition([], path)

    element_types, force = import_definition(
        uarchdef, os.path.join(path, "microarchitecture.yaml"), "Element_type",
        getattr(microprobe.target.uarch, 'element_type'), None)

    element, force = import_definition(uarchdef,
                                       os.path.join(path,
                                                    "microarchitecture.yaml"),
                                       "Element",
                                       getattr(microprobe.target.uarch,
                                               'element'),
                                       element_types,
                                       force=force)

    uarch_cls = get_object_from_module(uarchdef["Microarchitecture"]["Class"],
                                       uarchdef["Microarchitecture"]["Module"])

    uarch = uarch_cls(uarchdef["Name"], uarchdef["Description"], element,
                      uarchdef["Instruction_properties"]["Path"])

    import_properties(os.path.join(path, "microarchitecture.yaml"),
                      {uarchdef["Name"]: uarch})

    LOG.info("Microarchitecture '%s' imported", uarch)
    return uarch
Ejemplo n.º 4
0
def import_definition(cls, filenames, element_types):
    """ """
    LOG.debug("Start importing microarchitecture elements")

    elements = RejectingDict()
    elements_subelements = RejectingDict()

    for filename in filenames:
        element_data = read_yaml(filename, SCHEMA)

        if element_data is None:
            continue

        for elem in element_data:
            name = elem["Name"]
            parent = elem.get("Parent", None)
            subelements = elem.get("Subelements", [])
            repeat = elem.get("Repeat", None)
            rfrom = 0
            rto = 0
            replace = "0"

            try:
                elem_type = element_types[elem["Type"]]
            except KeyError:
                raise MicroprobeArchitectureDefinitionError(
                    "Unknown "
                    "microarchitecture element type in "
                    "microarchitecture element definition "
                    " '%s' found in '%s'" % (name, filename))
            descr = elem.get("Description", elem_type.description)

            if repeat:
                rfrom = repeat["From"]
                replace = "%s" % rfrom
                rto = repeat["To"]

            for index in range(rfrom, rto + 1):
                cname = name.replace(replace, "%d" % index)
                cdescr = descr.replace(replace, "%d" % index)
                element = cls(cname, cdescr, elem_type)

                try:
                    elements[cname] = element
                    elements_subelements[cname] = subelements
                except ValueError:
                    raise MicroprobeArchitectureDefinitionError(
                        "Duplicated microarchitecture element "
                        "definition '%s' found in '%s'" % (name, filename))

            LOG.debug(element)

    for filename in filenames:
        import_properties(filename, elements)

    for elem, subelements in elements_subelements.items():
        try:
            subelements_instances = [elements[item] for item in subelements]
        except KeyError as exc:
            raise MicroprobeArchitectureDefinitionError(
                "Undefined sub-element '%s' in element "
                "definition '%s'. Check following "
                "files: %s" % (exc, elem, filenames))

        elements[elem].set_subelements(subelements_instances)

    element_list = list(elements.values())
    fixing_hierarchy = True

    LOG.info("Start building element hierarchy...")
    fix_pass = 0
    while fixing_hierarchy:
        fix_pass += 1
        LOG.debug("Start building element hierarchy... pass %d", fix_pass)
        fixing_hierarchy = False
        for element in element_list:
            parents = [
                item for item in element_list if element in item.subelements
            ]

            if len(parents) > 1:
                # needs duplication

                LOG.debug("Element %s has %d parents", element, len(parents))

                for parent in sorted(parents):
                    LOG.debug("Duplicating for parent: %s", parent)
                    # Create a new copy
                    new_element = cls(element.name, element.description,
                                      element.type)
                    new_element.set_subelements(element.subelements)
                    element_list.append(new_element)

                    # Update parent to point to the new copy
                    new_subelements = parent.subelements
                    new_subelements.remove(element)
                    new_subelements.append(new_element)
                    parent.set_subelements(new_subelements)
                    fixing_hierarchy = True

                element_list.remove(element)

    LOG.info("Finish building element hierarchy")

    # Check correctness of the structure and set parents
    LOG.info("Checking element hierarchy...")
    top_element = None
    for element in element_list:
        parents = [
            item for item in element_list if element in item.subelements
        ]

        if len(parents) > 1:
            raise MicroprobeArchitectureDefinitionError(
                "Wrong hierarchy of microarchitecture "
                "elements. The definition of element"
                " '%s' has multiple parents: '%s'." %
                (element, [str(elem) for elem in parents]))
        elif len(parents) == 0:
            if top_element is not None:
                raise MicroprobeArchitectureDefinitionError(
                    "Wrong hierarchy of microarchitecture "
                    "elements. There are at least two top "
                    "elements: '%s' and '%s'. Define a single "
                    "parent element for all the hierarchy." %
                    (element, top_element))
            top_element = element
        else:
            element.set_parent_element(parents[0])

    if top_element is None:
        raise MicroprobeArchitectureDefinitionError(
            "Wrong hierarchy of microarchitecture "
            "elements. There is not a top element."
            " Define a single parent element for all "
            "the hierarchy.")

    LOG.info("Element hierarchy correct")

    elem_dict = dict([(element.full_name, element)
                      for element in element_list])

    for filename in filenames:
        import_properties(filename, elem_dict)

    LOG.info("End importing elements")
    return elem_dict