private void ReplacePreOrPostStateVars()
            {
                var sub = new Dictionary <Variable, Expr>();

                foreach (var v in trc.allInParams)
                {
                    sub[varCopies[v][0]] = Expr.Ident(v);
                }
                foreach (var v in trc.frame)
                {
                    sub[varCopies[v][0]] = ExprHelper.Old(Expr.Ident(v));
                }

                if (!trc.ignorePostState)
                {
                    foreach (var v in trc.PostStateVars)
                    {
                        var lastCopy = varCopies[v].Last();
                        if (sub.ContainsKey(lastCopy))
                        {
                            Debug.Assert(trc.frame.Contains(v) && lastCopy == varCopies[v][0]);
                            pathExprs.Add(Expr.Eq(Expr.Ident(v), sub[lastCopy]));
                        }
                        // In case of conflict we prefer "v" instead of "old(v)"
                        sub[lastCopy] = Expr.Ident(v);
                    }
                }

                pathExprs = SubstitutionHelper.Apply(sub, pathExprs).ToList();
            }
Esempio n. 2
0
 private static Expr OutPermsSubsetInPerms(LinearDomain domain, IEnumerable<Expr> ins, IEnumerable<Expr> outs)
 {
   Expr inMultiset = ExprHelper.Old(PermissionMultiset(domain, ins));
   Expr outMultiset = PermissionMultiset(domain, outs);
   Expr subsetExpr = ExprHelper.FunctionCall(domain.mapLe, outMultiset, inMultiset);
   return Expr.Eq(subsetExpr, ExprHelper.FunctionCall(domain.mapConstBool, Expr.True));
 }
Esempio n. 3
0
            private void ComputeWitnessedTransitionRelationExprs()
            {
                witnessedTransitionRelations = new List <Expr>();
                Dictionary <Variable, List <WitnessFunction> > varToWitnesses = FrameWithWitnesses.
                                                                                Where(x => NotEliminatedVars.Contains(frameIntermediateCopy[x])).
                                                                                ToDictionary(
                    x => frameIntermediateCopy[x],
                    x => transitionRelationComputer.globalVarToWitnesses[(GlobalVariable)x]);

                foreach (var witnessSet in varToWitnesses.Values.CartesianProduct())
                {
                    Dictionary <Variable, Expr> witnessSubst = new Dictionary <Variable, Expr>();
                    foreach (Tuple <Variable, WitnessFunction> pair in
                             Enumerable.Zip(varToWitnesses.Keys, witnessSet, Tuple.Create))
                    {
                        WitnessFunction witnessFunction = pair.Item2;
                        List <Expr>     args            = new List <Expr>();
                        foreach (var arg in witnessFunction.InputArgs)
                        {
                            Expr expr = null;
                            switch (arg.Kind)
                            {
                            case WitnessFunction.InputArgumentKind.FIRST_ARG:
                                // TODO: Add note on the reason of using second
                                expr = Expr.Ident(second.Params.
                                                  First(x => x.Name == second.Prefix + arg.Name));
                                break;

                            case WitnessFunction.InputArgumentKind.SECOND_ARG:
                                expr = Expr.Ident(first.Params.
                                                  First(x => x.Name == first.Prefix + arg.Name));
                                break;

                            case WitnessFunction.InputArgumentKind.PRE_STATE:
                                expr = ExprHelper.Old(Expr.Ident(
                                                          frame.First(x => x.Name == arg.Name)));
                                break;

                            case WitnessFunction.InputArgumentKind.POST_STATE:
                                expr = Expr.Ident(frame.First(x => x.Name == arg.Name));
                                break;

                            default:
                                Debug.Assert(false);
                                break;
                            }
                            args.Add(expr);
                        }
                        witnessSubst[pair.Item1] = ExprHelper.FunctionCall(
                            witnessFunction.function, args.ToArray()
                            );
                    }
                    var subst = Substituter.SubstitutionFromHashtable(witnessSubst);
                    witnessedTransitionRelations.Add(
                        Substituter.Apply(subst, TransitionRelationExpr));
                }
            }
Esempio n. 4
0
        private Dictionary <Implementation, List <Cmd> > CreatePreconditions(
            LinearPermissionInstrumentation linearPermissionInstrumentation)
        {
            var implToInitCmds = new Dictionary <Implementation, List <Cmd> >();

            foreach (var impl in absyMap.Keys.OfType <Implementation>())
            {
                var initCmds = new List <Cmd>();
                if (civlTypeChecker.GlobalVariables.Count() > 0)
                {
                    initCmds.Add(CmdHelper.HavocCmd(
                                     civlTypeChecker.GlobalVariables.Select(v => Expr.Ident(v)).ToList()));
                    linearPermissionInstrumentation.DisjointnessExprs(impl, true).ForEach(
                        expr => initCmds.Add(CmdHelper.AssumeCmd(expr)));

                    Substitution procToImplInParams = Substituter.SubstitutionFromHashtable(impl.Proc.InParams
                                                                                            .Zip(impl.InParams).ToDictionary(x => x.Item1, x => (Expr)Expr.Ident(x.Item2)));

                    impl.Proc.Requires.ForEach(req =>
                                               initCmds.Add(new AssumeCmd(req.tok, Substituter.Apply(procToImplInParams, req.Condition))));

                    foreach (var callCmd in GetYieldingProc(impl).yieldRequires)
                    {
                        var yieldInvariant = civlTypeChecker.procToYieldInvariant[callCmd.Proc];
                        if (layerNum == yieldInvariant.LayerNum)
                        {
                            Substitution callFormalsToActuals = Substituter.SubstitutionFromHashtable(callCmd.Proc.InParams
                                                                                                      .Zip(callCmd.Ins)
                                                                                                      .ToDictionary(x => x.Item1, x => (Expr)ExprHelper.Old(x.Item2)));
                            callCmd.Proc.Requires.ForEach(req => initCmds.Add(new AssumeCmd(req.tok,
                                                                                            Substituter.Apply(procToImplInParams,
                                                                                                              Substituter.Apply(callFormalsToActuals, req.Condition)))));
                        }
                    }
                }

                implToInitCmds[impl] = initCmds;
            }

            return(implToInitCmds);
        }