Exemple #1
0
    def use_model(self, name):
        model_unit = self.lal_ctx.get_from_provider(name, "specification")
        with log_stdout('error'):
            for diag in model_unit.diagnostics:
                print('   {}'.format(diag))
                return

        model_ofs = model_unit.root.findall(
            lambda x: (x.is_a(lal.AspectAssoc)
                       and x.f_id.text.lower() == "model_of")
        )

        type_models = {
            aspect.parent.parent.parent: aspect.f_expr.p_referenced_decl
            for aspect in model_ofs
            if aspect.parent.parent.parent.is_a(lal.TypeDecl, lal.SubtypeDecl)
        }

        fun_models = {
            aspect.parent.parent.parent: aspect.f_expr.p_referenced_decl
            for aspect in model_ofs
            if aspect.parent.parent.parent.is_a(lal.SubpDecl)
        }

        if len(type_models) + len(fun_models) != len(model_ofs):
            with log_stdout('info'):
                print("warning: detected usage of Model_Of in an unknown "
                      "context.")

        for tdecl, ref in type_models.iteritems():
            if ref is None:
                with log_stdout('info'):
                    print("warning: Model_Of used on '{}' refers to an unknown"
                          " type.".format(tdecl.f_name.text))
            else:
                self.type_models[ref] = tdecl

        for fdecl, ref in fun_models.iteritems():
            if ref is None:
                with log_stdout('info'):
                    print(
                        "warning: Model_Of used on '{}' refers to an unknown "
                        "procedure/function.".format(
                            fdecl.f_subp_spec.f_subp_name.text
                        )
                    )
            else:
                self.fun_models[ref] = fdecl
Exemple #2
0
 def run(self, **kwargs):
     ctx = kwargs['ctx']
     res = None
     self._keepalive()
     try:
         progs = [
             prog
             for key, ir in kwargs.iteritems()
             if key.startswith('ir')
             if ir is not None
             for prog in ir
         ]
         modeler = irtools.Models(
             self.get_typer_for(ctx, self.model_config.typer),
             self.get_type_interpreter_for(
                 self.model_config.type_interpreter
             ),
             *self.get_call_strategies_for(
                 self.model_config.call_strategy,
                 progs,
                 lambda p: models[p],
                 lambda: merge_pred_builder
             )
         )
         models = modeler.of(*progs)
         merge_pred_builder = self.get_merge_pred_builder_for(
             self.model_config.merge_predicate_builder
         )
         res = (models, merge_pred_builder)
     except Exception as e:
         with log_stdout('info'):
             print('error: could not create model: {}.'.format(e))
             traceback.print_exc(file=sys.stdout)
     return {'model': res}
Exemple #3
0
    def _extract_from_unit(self, unit):
        if unit.root is None:
            with log_stdout('error'):
                print('Could not parse {}:'.format(unit.filename))
                for diag in unit.diagnostics:
                    print('   {}'.format(diag))
                    return

        unit.populate_lexical_env()

        subpdata = analysis.traverse_unit(unit.root)
        self.subpdata.update(subpdata)

        progs = []
        for subp, subpuserdata in subpdata.iteritems():
            if subp.is_a(lal.BaseSubpBody):
                start_t = time.clock()
                progs.append(
                    gen_ir(self, subp, self._internal_typer, subpuserdata)
                )
                end_t = time.clock()
                log(
                    'timings',
                    " - Transformation of subprocedure {} took {}s".format(
                        subp.f_subp_spec.f_subp_name.text,
                        end_t - start_t
                    )
                )

        converter = ConvertUniversalTypes(self.evaluator, self._internal_typer)

        for prog in progs:
            prog.visit(converter)

        return progs
Exemple #4
0
    def run(self, ctx):
        try:
            unit = ctx.get_from_file(self.filename)
            if unit.root is not None:
                return {'res': unit}

            log('error', '\n'.join(str(diag) for diag in unit.diagnostics))
        except Exception as e:
            with log_stdout('info'):
                print('error: libadalang failed to analyze {}: {}.'.format(
                    self.filename, e))
                traceback.print_exc(file=sys.stdout)
        return {'res': None}
Exemple #5
0
    def run(self, ctx, unit):
        irtree = None
        if unit is not None:
            log('info', 'Transforming {}'.format(self.filename))
            try:
                start_t = time.clock()
                irtree = ctx.extract_programs_from_unit(unit)
                end_t = time.clock()

                log(
                    'timings', "Transformation of {} took {}s.".format(
                        self.filename, end_t - start_t))
            except Exception as e:
                with log_stdout('info'):
                    print(
                        'error: could not generate IR for file {}: {}.'.format(
                            self.filename, e))
                    traceback.print_exc(file=sys.stdout)
        return {'res': irtree}
Exemple #6
0
def do_partition(args, provider_config, checkers, partition):
    """
    Runs the checkers on a single partition of the whole set of files.
    Returns a list of diagnostics.

    :param argparse.Namespace args: The command-line arguments.
    :param ProviderConfig provider_config: The provider configuration.
    :param list[(Checker, list[str])] checkers: The list of checkers to run
        together with their specific arguments.
    :param (int, list[str]) partition: The index of that partition and the list
        of files that make up that partition.
    :rtype: list[(DiagnosticPosition, str, MessageKind, str)]
    """
    set_logger(args)
    keepalive(2)

    diags = []
    index, files = partition

    logger.log('debug',
               "started partition {} with files {}".format(index, files))

    try:
        reqs = get_requirements(provider_config, checkers, files)
        schedule = get_schedules(reqs)[0]

        if args.export_schedule is not None:
            export_schedule(schedule, "{}{}".format(args.export_schedule,
                                                    index))

        for checker_result in schedule.run(on_subgoal_achieved).values():
            for program_result in checker_result:
                for diag in program_result.diagnostics:
                    report = program_result.diag_report(diag)
                    if report is not None:
                        diags.append(report)
    except Exception:
        with logger.log_stdout('internal-error'):
            traceback.print_exc(file=sys.stdout)
    finally:
        logger.log('debug', "completed partition {}".format(index))
        return diags
Exemple #7
0
    def run(self, ir, model_and_merge_pred):
        res = []
        if ir is not None and model_and_merge_pred is not None:
            log('info', 'Analyzing file {}'.format(self.analysis_file))

            model, merge_pred_builder = model_and_merge_pred

            start_t = time.clock()

            for prog in ir:
                self._keepalive(prog)
                fun = prog.data.fun_id
                subp_start_t = time.clock()

                try:
                    res.append(abstract_analysis.compute_semantics(
                        prog, model[prog], merge_pred_builder
                    ))
                except Exception as e:
                    with log_stdout('info'):
                        print('error: analysis of subprocedure {}({}) failed: '
                              '{}.'.format(fun.f_subp_spec.f_subp_name.text,
                                           fun.sloc_range, e))
                        traceback.print_exc(file=sys.stdout)

                subp_end_t = time.clock()

                log(
                    'timings',
                    " - Analysis of subprocedure {} took {}s.".format(
                        fun.f_subp_spec.f_subp_name.text,
                        subp_end_t - subp_start_t
                    )
                )

            end_t = time.clock()
            log('timings', "Analysis of {} took {}s.".format(
                self.analysis_file, end_t - start_t
            ))

        return {'res': res}