예제 #1
0
파일: Program.cs 프로젝트: zvonimir/corral
        static void AddTemplates(IEnumerable <string> templates, string infile, string outfile)
        {
            var program = BoogieUtil.ParseProgram(infile);
            var tproc   = program.TopLevelDeclarations.OfType <Procedure>()
                          .Where(p => QKeyValue.FindBoolAttribute(p.Attributes, "template"))
                          .FirstOrDefault();
            var globals = new HashSet <string>(program.TopLevelDeclarations.OfType <Variable>().Select(v => v.Name));

            Debug.Assert(tproc != null);

            if (!Driver.OnlyDuality)
            {
                tproc.Ensures.RemoveAll(ens => !ens.Free);
            }

            foreach (var t in templates)
            {
                var aexpr = ToAnnotatedExpr(t);

                // Make sure all globals are present in the file
                var gv = new GatherVariables();
                gv.VisitExpr(aexpr.Item2);
                var vars = new HashSet <string>(gv.variables);
                vars.RemoveWhere(v => v.StartsWith("v_fin_int") || v.StartsWith("v_fout_int") || v.StartsWith("v_loop_int"));
                if (!vars.IsSubsetOf(globals))
                {
                    continue;
                }

                // special support
                if (QKeyValue.FindBoolAttribute(aexpr.Item1, "irql") &&
                    (aexpr.Item2.ToString() == "v_fin_int == v_fout_int" || aexpr.Item2.ToString() == "v_fout_int == v_fin_int"))
                {
                    AddIrql(tproc, program);
                    continue;
                }

                var annotationStr = "";
                if (aexpr.Item1 != null)
                {
                    var sw = new StringWriter();
                    aexpr.Item1.Emit(new TokenTextWriter(sw));
                    sw.Close();
                    annotationStr = sw.ToString();
                }

                var newt = MakeUniqueTemplateVariables.Rewrite(aexpr.Item2);
                var tstr = newt.ToString();
                tproc.Ensures.Add(ToEnsures(annotationStr + " " + FindAnnotations(tstr), tstr));
            }

            program.TopLevelDeclarations.AddRange(MakeUniqueTemplateVariables.template_var_in.Values);
            program.TopLevelDeclarations.AddRange(MakeUniqueTemplateVariables.template_var_out.Values);
            program.TopLevelDeclarations.AddRange(MakeUniqueTemplateVariables.template_var_loop.Values);

            BoogieUtil.PrintProgram(program, outfile);
        }
예제 #2
0
파일: Program.cs 프로젝트: zvonimir/corral
        public static Expr Rewrite(Expr expr)
        {
            var mu = new MakeUniqueTemplateVariables();

            return(mu.VisitExpr(expr));
        }