Пример #1
0
    def parse_pass_group_dict(cls, pass_group_dict, pass_options,
                              external_programs, remove_pass, clang_delta_std,
                              clang_delta_preserve_routine, not_c, renaming):
        pass_group = {}
        removed_passes = set(remove_pass.split(',')) if remove_pass else set()

        def parse_options(options):
            valid_options = set()

            for opt in options:
                try:
                    valid_options.add(AbstractPass.Option(opt))
                except ValueError:
                    raise PassOptionError(opt)

            return valid_options

        def include_pass(pass_dict, options):
            return ((('include' not in pass_dict)
                     or bool(parse_options(pass_dict['include']) & options))
                    and
                    (('exclude' not in pass_dict) or
                     not bool(parse_options(pass_dict['exclude']) & options)))

        for category in ['first', 'main', 'last']:
            if category not in pass_group_dict:
                raise CViseError('Missing category {}'.format(category))

            pass_group[category] = []

            for pass_dict in pass_group_dict[category]:
                if not include_pass(pass_dict, pass_options):
                    continue

                if 'pass' not in pass_dict:
                    raise CViseError(
                        'Invalid pass in category {}'.format(category))

                try:
                    pass_class = cls.pass_name_mapping[pass_dict['pass']]
                except KeyError:
                    raise CViseError('Unkown pass {}'.format(
                        pass_dict['pass']))

                pass_instance = pass_class(pass_dict.get('arg'),
                                           external_programs)
                if str(pass_instance) in removed_passes:
                    continue

                if not_c and 'c' in pass_dict and pass_dict['c']:
                    continue
                elif not renaming and 'renaming' in pass_dict and pass_dict[
                        'renaming']:
                    continue

                pass_instance.user_clang_delta_std = clang_delta_std
                pass_instance.clang_delta_preserve_routine = clang_delta_preserve_routine
                pass_group[category].append(pass_instance)

        return pass_group
Пример #2
0
    def load_pass_group_file(cls, path):
        with open(path) as pass_group_file:
            try:
                pass_group_dict = json.load(pass_group_file)
            except json.JSONDecodeError:
                raise CViseError('Not valid JSON.')

        return pass_group_dict
Пример #3
0
def get_share_dir():
    script_path = os.path.dirname(os.path.realpath(__file__))

    # Test all known locations for the cvise directory
    share_dirs = [
        os.path.join(script_path, "..", "share", "cvise"),
        os.path.join(script_path, "cvise")
    ]

    for d in share_dirs:
        if os.path.isdir(d):
            return d

    raise CViseError("Cannot find cvise module directory!")
Пример #4
0
def get_share_dir():

    # Test all known locations for the cvise directory
    share_dirs = [
            os.path.join("@CMAKE_INSTALL_FULL_DATADIR@", "@cvise_PACKAGE@"),
            destdir + os.path.join("@CMAKE_INSTALL_FULL_DATADIR@", "@cvise_PACKAGE@"),
            os.path.join(script_path, "cvise")
            ]

    for d in share_dirs:
        if os.path.isdir(d):
            return d

    raise CViseError("Cannot find cvise module directory!")
Пример #5
0
def get_libexec_dir():
    script_path = os.path.dirname(os.path.realpath(__file__))

    # Test all known locations for the cvise directory
    libexec_dirs = [
            os.path.join(script_path, "..", "libexec"),
            #FIXME: The programs are in sub directories
            os.path.join(script_path)
            ]

    for d in libexec_dirs:
        if os.path.isdir(d):
            return d

    raise CViseError("Cannot find libexec directory!")