コード例 #1
0
        public override CBAProgram runCBAPass(CBAProgram p)
        {
            // Eliminate dead variables
            UnusedVarEliminator.Eliminate(p as Program);

            // Add the inlining bound
            addInlineAttribute(p);

            // Inline
            doInlining(p);

            // Remove the inlined procedures & implementations
            removeInlinedProcs(p);

            // Remove annotations that won't parse because of dropped variables
            RemoveVarsFromAttributes.Prune(p);

            return(p);
        }
コード例 #2
0
ファイル: VariableSlice.cs プロジェクト: smackers/corral
        // Remove declarations of globals that are not tracked
        public override Program VisitProgram(Program node)
        {
            /*
             * Log.Write(Log.Debug, "Tracking variables: ");
             * foreach (var s in trackedVars)
             * {
             *  Log.Write(Log.Debug, s + " ");
             * }
             * Log.Write(Log.Debug, "\n");
             */

            HashSet <string> declaredGlobals = new HashSet <string>();

            // Partition the list into global declarations and others
            var globals = node.TopLevelDeclarations.OfType <GlobalVariable>().ToList();
            var rest    = node.TopLevelDeclarations.Where(decl => !(decl is GlobalVariable)).ToList();

            // Gather all declared global variables
            foreach (Declaration d in globals)
            {
                var g = d as GlobalVariable;
                if (g == null)
                {
                    continue;
                }

                // Store declared global
                declaredGlobals.Add(g.Name);
            }

            if (trackedVars.Contains(new VarSet(declaredGlobals, BoogieUtil.GetAllProcNames(node))))
            {
                return(node);
            }

            // Make sure all the vars to track are declared
            Debug.Assert(declaredGlobals.Contains(trackedVars.Variables));

            // Visit declaration other than global variable declarations
            for (int i = 0, n = rest.Count; i < n; i++)
            {
                rest[i] = this.VisitDeclaration(rest[i]);
            }

            // Remove globals that are not tracked
            node.TopLevelDeclarations = globals.Where(x => isTrackedVariable(x as GlobalVariable));

            node.AddTopLevelDeclarations(rest);

            foreach (var proc in slicedEnsures)
            {
                if (visitedImplementations.Contains(proc))
                {
                    Log.WriteLine(Log.Warning, "Slicing away (non-free) ensures condition");
                }
            }

            if (slicedRequires.Any())
            {
                Log.WriteLine(Log.Warning, "Slicing away (non-free) requires condition");
            }

            // Remove annotations that won't parse because of dropped variables
            RemoveVarsFromAttributes.Prune(node);

            return(node);
        }
コード例 #3
0
ファイル: CBAPasses.cs プロジェクト: smackers/corral
        public override CBAProgram runCBAPass(CBAProgram p)
        {
            if (unrollNum >= 0)
            {
                return(base.runCBAPass(p));
            }

            foreach (var impl in BoogieUtil.GetImplementations(p))
            {
                impl.PruneUnreachableBlocks();
            }

            // save RB
            var rb = CommandLineOptions.Clo.RecursionBound;

            if (BoogieVerify.irreducibleLoopUnroll >= 0)
            {
                CommandLineOptions.Clo.RecursionBound = BoogieVerify.irreducibleLoopUnroll;
            }

            var procsWithIrreducibleLoops = new HashSet <string>();
            var passInfo = p.ExtractLoops(out procsWithIrreducibleLoops);

            // restore RB
            CommandLineOptions.Clo.RecursionBound = rb;

            // no loops found, then this transformation is identity
            if (passInfo.Count == 0 && procsWithIrreducibleLoops.Count == 0)
            {
                return(null);
            }

            if (addUniqueCallLabels)
            {
                // annotate calls with a unique number
                var addIds = new AddUniqueCallIds();

                // Loop unrolling is done for procs with irreducible loops.
                // This simply copies Cmd objects. Duplicate them to remove
                // aliasing
                foreach (var impl in p.TopLevelDeclarations
                         .OfType <Implementation>()
                         .Where(impl => procsWithIrreducibleLoops.Contains(impl.Name)))
                {
                    var dup = new FixedDuplicator(true);
                    foreach (var blk in impl.Blocks)
                    {
                        blk.Cmds = dup.VisitCmdSeq(blk.Cmds);
                    }
                }

                // Add labels again to all procedures
                foreach (var impl in p.TopLevelDeclarations
                         .OfType <Implementation>())
                {
                    addIds.VisitImplementation(impl);
                }
            }

            info = new Dictionary <string, Dictionary <string, string> >();
            passInfo.Iter(kvp =>
            {
                info.Add(kvp.Key, new Dictionary <string, string>());
                kvp.Value.Iter(sb => info[kvp.Key].Add(sb.Key, sb.Value.Label));
            });

            // Construct the set of procs in the original program
            // and the loop procedures
            allProcs  = new HashSet <string>();
            loopProcs = new HashSet <string>();
            foreach (var decl in p.TopLevelDeclarations)
            {
                var impl = decl as Implementation;
                if (impl == null)
                {
                    continue;
                }
                allProcs.Add(impl.Name);
                if (impl.Proc is LoopProcedure)
                {
                    loopProcs.Add(impl.Name);
                    impl.Proc.AddAttribute("LoopProcedure");
                }
            }

            //foreach (var impl in BoogieUtil.GetImplementations(p))
            //{
            //removeAssumeFalseBlocks(impl);
            //}


            // Optimization: if no loop is found, then no need to print
            // out a new program
            if (loopProcs.Count == 0)
            {
                return(null);
            }

            // Remove vars from attributes that are not in scope anymore
            RemoveVarsFromAttributes.Prune(p);

            return(p);
        }