Exemplo n.º 1
0
        private Implementation processImplementation(Implementation node)
        {
            varsRead = new VarsUsed();

            // Gather the set of vars used
            foreach (var b in node.Blocks)
            {
                base.VisitBlock(b);
            }

            globalsRead.UnionWith(varsRead.globalsUsed);

            // Get rid of declarations (before variable slice adds new variables)
            var newvars = new List <Variable>();

            foreach (Variable v in node.LocVars)
            {
                if (varsRead.localsUsed.Contains(v.Name))
                {
                    newvars.Add(v);
                }
            }
            node.LocVars = newvars;

            // Do VariableSlicing
            VariableSlicing slice = new VariableSlicing(new VarSet(new HashSet <string>(varsRead.localsUsed), node.Name), ltinfo, node);

            for (int i = 0; i < node.Blocks.Count; i++)
            {
                node.Blocks[i] = slice.VisitBlock(node.Blocks[i]);
            }

            varsRead = null;
            return(node);
        }
Exemplo n.º 2
0
 public UnReadVarEliminator(bool onlyLocals)
 {
     this.onlyLocals = onlyLocals;
     varsRead        = null;
     globalsRead     = null;
     ltinfo          = new ModifyTrans();
     gtinfo          = new ModifyTrans();
     sliceGlobals    = null;
 }
Exemplo n.º 3
0
        public Program run(Program node)
        {
            globalsRead = new HashSet <string>();

            // Typecheck -- needed for variable abstraction
            if (node.Typecheck() != 0)
            {
                BoogieUtil.PrintProgram(node, "error.bpl");
                throw new InternalError("Type errors");
            }

            // Go through all procedures and implementations (slice locals)
            var TopLevelDeclarations = node.TopLevelDeclarations.ToList();

            for (int i = 0; i < TopLevelDeclarations.Count; i++)
            {
                if (TopLevelDeclarations[i] is Implementation)
                {
                    TopLevelDeclarations[i] = processImplementation(TopLevelDeclarations[i] as Implementation);
                }
                else if (TopLevelDeclarations[i] is Procedure)
                {
                    processProcedure(TopLevelDeclarations[i] as Procedure);
                }
            }
            node.TopLevelDeclarations = TopLevelDeclarations;

            if (onlyLocals)
            {
                return(node);
            }


            sliceGlobals = new VariableSlicing(VarSet.ToVarSet(globalsRead, node), gtinfo);
            node         = sliceGlobals.VisitProgram(node);
            BoogieUtil.DoModSetAnalysis(node);

            return(node);
        }
Exemplo n.º 4
0
 public VariableSlicePass(VarSet v)
 {
     tinfo    = new ModifyTrans();
     vslice   = new VariableSlicing(v, tinfo);
     passName = "Variable Slicing";
 }