Exemplo n.º 1
0
                    m = re.search(
                        branch_syntax + r'\s*' +
                        imm.syntax_name.replace('#', r'\#'), template.syntax,
                        re.X)
                    # The '#' (used in imm. op. names) is escaped, as it is interpreted as
                    # a comment in verbose regex (re.X), and verbose regex is used because
                    # the branch syntax is written with spaces (verbose style) to improve
                    # its readability.

                    if m:
                        template.branch.target = imm
                        return

                raise UnexpectedException()
                # The target immediate operand should have been found.

        return


if __name__ == "__main__":

    print("Starting decodification...")

    deco = HexagonInstructionDecoder()

    common.pickle_dump(common.INST_TEMPL_PATH, deco.inst_template_list)

    print("Decoding done.")

    # TODO: move this to a general main, to call the importer together with the decoder.
Exemplo n.º 2
0
            if branch_syntax in [TemplateBranch.jump_imm_syntax, TemplateBranch.call_imm_syntax]:
                # Branch type: jump/call immediate.

                for imm in template.imm_ops: # type: ImmediateTemplate
                    m = re.search(branch_syntax + r'\s*' + imm.syntax_name.replace('#', r'\#'), template.syntax, re.X)
                    # The '#' (used in imm. op. names) is escaped, as it is interpreted as
                    # a comment in verbose regex (re.X), and verbose regex is used because
                    # the branch syntax is written with spaces (verbose style) to improve
                    # its readability.

                    if m:
                        template.branch.target = imm
                        return

                raise UnexpectedException()
                # The target immediate operand should have been found.

        return
    
if __name__ == "__main__":
    
    print("Starting decodification...")

    deco = HexagonInstructionDecoder()
    
    common.pickle_dump(common.INST_TEMPL_PATH, deco.inst_template_list)
    
    print("Decoding done.")

    # TODO: move this to a general main, to call the importer together with the decoder.
Exemplo n.º 3
0
                inst_def.behavior = behavior
                break

    print('Match behavior: {0:.2f}%'.format(
        match_behaviors / len(mp.syntax_behavior_text) * 100))

    # TODO: Add corrected_behaviors.py to the repo.
    #     # Apply corrected behaviors specified in the behaviors script:
    #     sys.path.append('../inst_sources/')
    #     from behaviors_annex import corrected_behaviors
    #     # TODO: figure out how to include this script, or make it into a pickle binary file and just load it
    #     for sb in corrected_behaviors:
    #         syntax = sb[0]
    #         behavior = sb[1]
    #         syntax = syntax.lower().replace(' ', '')
    #         found_syntax = False
    # #         pv('syntax')
    #         for inst_def in mp.instructions:
    #             syntax_to_match = inst_def.syntax.lower().replace(' ', '')
    # #             pv('syntax_to_match')
    #             if syntax_to_match == syntax:
    #                 inst_def.behavior = behavior
    #                 found_syntax = True
    #                 break
    #
    #         if found_syntax == False:
    #             # All of these corrected behaviors should match
    #             raise UnexpectedException()

    pickle_dump(INST_DEF_PATH, mp.instructions)
Exemplo n.º 4
0
                inst_def.behavior = behavior
                break
    
    print('Match behavior: {0:.2f}%'.format(match_behaviors / len(mp.syntax_behavior_text) * 100))

    # TODO: Add corrected_behaviors.py to the repo.
#     # Apply corrected behaviors specified in the behaviors script:
#     sys.path.append('../inst_sources/')
#     from behaviors_annex import corrected_behaviors
#     # TODO: figure out how to include this script, or make it into a pickle binary file and just load it
#     for sb in corrected_behaviors:
#         syntax = sb[0]
#         behavior = sb[1]
#         syntax = syntax.lower().replace(' ', '')
#         found_syntax = False
# #         pv('syntax')
#         for inst_def in mp.instructions:
#             syntax_to_match = inst_def.syntax.lower().replace(' ', '')
# #             pv('syntax_to_match')
#             if syntax_to_match == syntax:
#                 inst_def.behavior = behavior
#                 found_syntax = True
#                 break
#
#         if found_syntax == False:
#             # All of these corrected behaviors should match
#             raise UnexpectedException()
    

    pickle_dump(INST_DEF_PATH, mp.instructions)