示例#1
0
        private void ExtractOldVariablesForBodylessMethod(Program prog, ArmadaSymbolTable symbols, Method meth, ArmadaSingleMethodSymbolTable smst)
        {
            if (meth.Ens == null)
            {
                return;
            }
            if (!meth.Ens.Any())
            {
                return;
            }

            var s   = AH.MakeNameSegment("s", "Armada_TotalState");
            var tid = AH.MakeNameSegment("tid", "Armada_ThreadHandle");
            var failureCollector = new SimpleFailureReporter(prog);
            var ensContext       = new BodylessMethodSnapshotResolutionContext(s, tid, meth.Name, symbols, failureCollector);

            foreach (var ens in meth.Ens)
            {
                var ensResolvedJustToGetOldValues = ensContext.ResolveAsRValue(ens.E);
            }
            int whichOldValue = 0;

            foreach (var oldValue in ensContext.OldValues)
            {
                var varName = $"Armada_Old{whichOldValue}";
                var v       = new MethodStackFrameUnaddressableLocalArmadaVariable(varName, oldValue.Type, oldValue, ArmadaVarType.ExternOld, meth.Name);
                ++whichOldValue;
                smst.AddVariable(prog, v);
            }
        }
示例#2
0
        protected string GetStepCaseForUpdateToUpdateNextRoutine_LH(NextRoutine nextRoutine)
        {
            var hNextRoutine = nextRoutineMap[nextRoutine];
            var lowStmt      = (UpdateStmt)nextRoutine.armadaStatement.Stmt;
            var lowExprs     = lowStmt.Lhss;

            var hStmt  = (UpdateStmt)hNextRoutine.armadaStatement.Stmt;
            var hExprs = hStmt.Lhss;

            var pi  = GetMatchingLowLevelLhssForHighLevelLhss(lowExprs, hExprs);
            var bvs = nextRoutine.HasFormals ? $"params: L.Armada_StepParams_{nextRoutine.NameSuffix}" : "";
            var ps  = new List <string>();

            for (int i = 0; i < hExprs.Count; i++)
            {
                var failureReporter = new SimpleFailureReporter(pgp.prog);
                var context         = new NormalResolutionContext("L", nextRoutine.method.Name, pgp.symbolsLow, failureReporter);
                // Add the pi[i]'th rhs from the low-level update statement
                var    rhs = lowStmt.Rhss.ElementAt(pi[i]);
                string newRhs;
                if (rhs is ExprRhs)
                {
                    var erhs         = (ExprRhs)rhs;
                    var newRhsRValue = context.ResolveAsRValue(erhs.Expr);
                    newRhs = newRhsRValue.Val;
                }
                else // rhs must be HavocRhs here
                {
                    newRhs = $"params.nondet{i}";
                }
                if (hStmt.Rhss.ElementAt(i) is HavocRhs) // If the high level is a havoc-rhs, then it needs to be given the values
                {
                    ps.Add(newRhs);
                }
            }

            string hname    = hNextRoutine.NameSuffix;
            var    caseBody = hNextRoutine.HasFormals ? $"H.Armada_Step_{hname}(H.Armada_StepParams_{hname}({AH.CombineStringsWithCommas(ps)}))"
                                               : $"H.Armada_Step_{hname}";

            return($"case Armada_Step_{nextRoutine.NameSuffix}({bvs}) => {caseBody}\n");
        }
示例#3
0
        protected string GetStepCaseForUpdateToSomehowNextRoutine_LH(NextRoutine nextRoutine)
        {
            var hNextRoutine = nextRoutineMap[nextRoutine];
            var lowStmt      = (UpdateStmt)nextRoutine.armadaStatement.Stmt;
            var lowExprs     = lowStmt.Lhss;

            var hStmt  = (SomehowStmt)hNextRoutine.armadaStatement.Stmt;
            var hExprs = hStmt.Mod.Expressions;

            var pi  = GetMatchingLowLevelLhssForHighLevelLhss(lowExprs, hExprs);
            var bvs = nextRoutine.HasFormals ? $"params: L.Armada_StepParams_{nextRoutine.NameSuffix}" : "";
            var ps  = nextRoutine.Formals.Select(f => $"params{f.LocalVarName}").ToList();

            for (int i = 0; i < hExprs.Count; i++)
            {
                var failureReporter = new SimpleFailureReporter(pgp.prog);
                var context         = new NormalResolutionContext("L", nextRoutine.method.Name, pgp.symbolsLow, failureReporter);
                // Add the pi[i]'th rhs from the low-level update statement
                var rhs = lowStmt.Rhss.ElementAt(pi[i]);
                if (rhs is ExprRhs)
                {
                    var erhs         = (ExprRhs)rhs;
                    var newRhsRValue = context.ResolveAsRValue(erhs.Expr);
                    ps.Add(newRhsRValue.Val);
                }
                else
                {
                    AH.PrintError(pgp.prog, "Havoc RHS not yet supported");
                    return(null);
                }
            }

            string hname    = hNextRoutine.NameSuffix;
            var    caseBody = hNextRoutine.HasFormals ? $"H.Armada_Step_{hname}(H.Armada_StepParams_{hname}({AH.CombineStringsWithCommas(ps)}))"
                                               : $"H.Armada_Step_{hname}";

            return($"case Armada_Step_{nextRoutine.NameSuffix}({bvs}) => {caseBody}\n");
        }