Пример #1
0
        public Procedure getContextSwitchProcedure(int K)
        {
            Debug.Assert(K >= 1);

            if (csProcBound == K)
            {
                return(csProc);
            }

            csProcBound = K;

            // Procedure for context switching

            //procedure contextSwitch();
            //modifies k;
            //modifies raiseException;
            //ensures(old(k) <= k);
            //ensures(k < K);
            //ensures(inAtomicBlock => (old(k) == k && (raiseException == false)))
            //ensures(!assertsPassed && !inAtomicBlock => raiseException)

            List <IdentifierExpr> mods = new List <IdentifierExpr>();

            mods.Add(new IdentifierExpr(Token.NoToken, vark));

            if (InstrumentationConfig.addRaiseException && ContextSwitchRaisesException)
            {
                mods.Add(new IdentifierExpr(Token.NoToken, raiseException));
            }

            // ensures(k < K)
            Ensures e1 = new Ensures(false, BoogieAstFactory.MkAssumeVarLtConst(vark, K).Expr);

            // ensures(old(k) <= k)
            Ensures e2 = new Ensures(false, BoogieAstFactory.MkAssumeOldVarLeVar(vark, vark).Expr);

            Ensures e3;

            if (InstrumentationConfig.addRaiseException && ContextSwitchRaisesException)
            {
                //ensures(inAtomicBlock => (old(k) == k && (raiseException == false)))
                e3 = new Ensures(false, BoogieAstFactory.MkAssumeInAtomic(inAtomicBlock, vark, raiseException).Expr);
            }
            else
            {
                //ensures(inAtomicBlock => (old(k) == k))
                e3 = new Ensures(false, Expr.Imp(Expr.Ident(inAtomicBlock), Expr.Eq(new OldExpr(Token.NoToken, Expr.Ident(vark)), Expr.Ident(vark))));
            }

            List <Ensures> ensures = new List <Ensures>();

            ensures.Add(e1);
            ensures.Add(e2);
            ensures.Add(e3);

            csProc = new Procedure(Token.NoToken, csProcName, new List <TypeVariable>(), new List <Variable>(), new List <Variable>(),
                                   new List <Requires>(), mods, ensures);

            return(csProc);
        }