Пример #1
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
Пример #2
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