brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 9ddb6a2 Raw
64 lines · python
1# DExTer : Debugging Experience Tester2# ~~~~~~   ~         ~~         ~   ~~3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7"""View tool."""8 9import os10 11import pickle12from dex.heuristic import Heuristic13from dex.heuristic.Heuristic import add_heuristic_tool_arguments14from dex.tools import ToolBase15from dex.utils.Exceptions import Error, HeuristicException16from dex.utils.ReturnCode import ReturnCode17 18 19class Tool(ToolBase):20    """Given a dextIR file, display the information in a human-readable form."""21 22    @property23    def name(self):24        return "DExTer view"25 26    def add_tool_arguments(self, parser, defaults):27        add_heuristic_tool_arguments(parser)28        parser.add_argument(29            "input_path",30            metavar="dextIR-file",31            type=str,32            default=None,33            help="dexter dextIR file to view",34        )35        parser.description = Tool.__doc__36 37    def handle_options(self, defaults):38        options = self.context.options39 40        options.input_path = os.path.abspath(options.input_path)41        if not os.path.isfile(options.input_path):42            raise Error(43                '<d>could not find dextIR file</> <r>"{}"</>'.format(options.input_path)44            )45 46    def go(self) -> ReturnCode:47        options = self.context.options48 49        with open(options.input_path, "rb") as fp:50            steps = pickle.load(fp)51 52        try:53            heuristic = Heuristic(self.context, steps)54        except HeuristicException as e:55            raise Error("could not apply heuristic: {}".format(e))56 57        self.context.o.auto(58            "{}\n\n{}\n\n{}\n\n".format(59                heuristic.summary_string, steps, heuristic.verbose_output60            )61        )62 63        return ReturnCode.OK64