Example #1
0
def _parse_definition_tuple(definition_tuple):
    """Return the target definitions corresponding to the *definition_tuple*.

    Return the target definitions corresponding to the *definition_tuple*.
    Check the *definition_tuple* format, and for each element (architecture,
    microarchitecture and environment) looks for the if there is a definition
    present in the current defined definition paths. It returns a tuple with
    the three corresponding definitions.

    :param definition_tuple: Target definition string
    :type definition_tuple: :class:`~.str`
    :return: Tuple of target definitions
    :rtype: :func:`tuple` of :class:`~.Definition`
    :raise microprobe.exceptions.MicroprobeTargetDefinitionError: if something
        if the *definition_tuple* format is wrong or if the definition
        specified is not found
    """

    try:
        isa_def, architecture_def, env_def = definition_tuple.split("-")
    except ValueError:
        raise MicroprobeTargetDefinitionError(
            "Invalid format of '%s' target tuple" % definition_tuple)

    definitions = find_isa_definitions()
    if isa_def not in [definition.name for definition in definitions]:
        raise MicroprobeTargetDefinitionError("ISA '%s' not available" %
                                              isa_def)
    else:
        isa_def = [
            definition for definition in definitions
            if definition.name == isa_def
        ][-1]

    definitions = find_microarchitecture_definitions()
    if architecture_def not in [definition.name for definition in definitions]:
        raise MicroprobeTargetDefinitionError(
            "Microarchitecture '%s' not available" % architecture_def)
    else:
        architecture_def = [
            definition for definition in definitions
            if definition.name == architecture_def
        ][-1]

    definitions = find_env_definitions()
    if env_def not in [definition.name for definition in definitions]:
        raise MicroprobeTargetDefinitionError(
            "Environment '%s' not available. " % env_def)
    else:
        env_def = [
            definition for definition in definitions
            if definition.name == env_def
        ][-1]

    return (isa_def, architecture_def, env_def)
Example #2
0
    def property_isa_map(self, prop_name):
        """Generate property to isa map.

        Return a dictionary mapping values of the property *prop_name* to
        the list of :class:`~.InstructionType` that have that property value.

        :param prop_name: Property name
        :type prop_name: :class:`~.str`
        :return: Dictionary mapping value properties to instruction types
        :rtype: :class:`~.dict` mapping property values to :class:`~.list` of
                :class:`~.InstructionType`
        :raise microprobe.exceptions.MicroprobeTargetDefinitionError: if the
            property is not found
        """
        prop_map = {}

        for instr in self.isa.instructions.values():

            try:
                value = getattr(instr, prop_name)
            except AttributeError:
                raise MicroprobeTargetDefinitionError(
                    "Property '%s' for instruction not found" % prop_name)

            if not isinstance(value, list):
                values = [value]
            else:
                values = value

            for value in values:

                if value not in prop_map:
                    prop_map[value] = []

                prop_map[value].append(instr)

        for key in prop_map:
            prop_map[key] = set(prop_map[key])

        return prop_map
Example #3
0
def import_isa_definition(path):
    """Imports a ISA definition given a path

    :param path:

    """

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

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

    isadef = _read_yaml_definition([], path)

    regts, force = import_definition(
        isadef, os.path.join(path, "isa.yaml"), "Register_type",
        register_type_mod, None
    )
    regts = dict2OrderedDict(regts)

    regs, force = import_definition(
        isadef,
        os.path.join(
            path, "isa.yaml"
        ),
        "Register",
        register_mod,
        regts,
        force=force
    )
    regs = dict2OrderedDict(regs)

    ops, force = import_operand_definition(
        isadef,
        os.path.join(
            path, "isa.yaml"
        ),
        "Operand",
        operand_mod,
        regs,
        force=force
    )
    ops = dict2OrderedDict(ops)

    ifields, force = import_definition(
        isadef,
        os.path.join(
            path, "isa.yaml"
        ),
        "Instruction_field",
        ifield_mod,
        ops,
        force=force
    )
    ifields = dict2OrderedDict(ifields)

    iformats, force = import_definition(
        isadef,
        os.path.join(
            path, "isa.yaml"
        ),
        "Instruction_format",
        iformat_mod,
        ifields,
        force=force
    )

    iformats = dict2OrderedDict(iformats)

    ins, force = import_definition(
        isadef,
        os.path.join(
            path, "isa.yaml"
        ),
        "Instruction",
        instruction_mod, (iformats, ops),
        force=force
    )
    ins = dict2OrderedDict(ins)

    comp_clss = import_cls_definition(
        isadef, os.path.join(path, "isa.yaml"), "Comparator", comparator_mod
    )

    gen_clss = import_cls_definition(
        isadef, os.path.join(path, "isa.yaml"), "Generator", generator_mod
    )

    isa_cls = get_object_from_module(
        isadef["ISA"]["Class"], isadef["ISA"]["Module"]
    )

    try:
        isa = isa_cls(
            isadef["Name"], isadef["Description"], path, ins,
            regs, comp_clss, gen_clss
        )
    except TypeError as exc:
        LOG.critical("Unable to import ISA definition.")
        LOG.critical("Check if you definition is complete.")
        LOG.critical("Error reported: %s", exc)
        raise MicroprobeTargetDefinitionError(exc)

    LOG.info("ISA '%s' imported", isa)

    if not LOG.isEnabledFor(DEBUG):
        return isa

    # Check definition. Ensure that all the components defined are referenced.
    for unused_regt in [
        regt
        for regt in regts.values()
        if regt not in [reg.type for reg in isa.registers.values()]
    ]:
        LOG.warning("Unused register type definition: %s", unused_regt)

    for unused_reg in [
        reg for reg in regs.values() if reg not in list(isa.registers.values())
    ]:
        LOG.warning("Unused register definition: %s", unused_reg)

    used_operands = []
    for ins in isa.instructions.values():
        for oper in ins.operands.values():
            used_operands.append(oper[0].name)
        for operand in [operand.type for operand in ins.implicit_operands]:
            used_operands.append(operand.name)
        for field in ins.format.fields:
            used_operands.append(field.default_operand.name)

    for unused_op in [
        operand for operand in ops.values()
        if operand.name not in used_operands
    ]:
        LOG.warning("Unused operand definition: %s", unused_op)

    used_fields = []
    for ins in isa.instructions.values():
        used_fields += [field.name for field in ins.format.fields]

    for unused_field in [
        field for field in ifields.values() if field.name not in used_fields
    ]:
        LOG.warning("Unused field definition: %s", unused_field)

    used_formats = []
    for ins in isa.instructions.values():
        used_formats.append(ins.format.name)

    for unused_format in [
        iformat
        for iformat in iformats.values() if iformat.name not in used_formats
    ]:
        LOG.warning("Unused format definition: %s", unused_format)

    return isa