Пример #1
0
        protected MatchCaseExpr GetTraceEntryCaseForUpdateToUpdateNextRoutine_LH(NextRoutine nextRoutine)
        {
            var highNextRoutine = nextRoutineMap[nextRoutine];
            var lowStmt         = (UpdateStmt)nextRoutine.armadaStatement.Stmt;
            var lowExprs        = lowStmt.Lhss;

            var highStmt  = (UpdateStmt)highNextRoutine.armadaStatement.Stmt;
            var highExprs = highStmt.Lhss;

            var pi = GetMatchingLowLevelLhssForHighLevelLhss(lowExprs, highExprs);

            var bvs = new List <BoundVar> {
                AH.MakeBoundVar("tid", "Armada_ThreadHandle")
            };

            bvs.AddRange(nextRoutine.Formals.Select(f => AH.MakeBoundVar(f.LocalVarName, AddModuleNameToArmadaType(f.VarType, "L"))));

            var ps = new List <Expression> {
                AH.MakeNameSegment("tid", "Armada_ThreadHandle")
            };

            // ps.AddRange(nextRoutine.Formals.Select(f => AH.MakeNameSegment(f.LocalVarName, f.VarType))); // Use the tid (and any other) parameters from the bound vars in the case statement

            for (int i = 0; i < highExprs.Count; i++)
            {
                var context = new NormalResolutionContext(nextRoutine, pgp.symbolsLow);
                // Add the pi[i]'th rhs from the low-level update statement
                var        rhs = lowStmt.Rhss.ElementAt(pi[i]);
                Expression 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 = AH.MakeNameSegment($"nondet{i}", lowExprs[pi[i]].Type);
                }
                if (highStmt.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 nextRoutineName = nextRoutine.NameSuffix;
            string hname           = nextRoutineMap[nextRoutine].NameSuffix;
            var    case_body       = AH.MakeApplyN($"H.Armada_TraceEntry_{hname}", ps, "H.Armada_TraceEntry");
            var    case0           = AH.MakeMatchCaseExpr($"Armada_TraceEntry_{nextRoutineName}", bvs, case_body);

            return(case0);
        }
Пример #2
0
        protected MatchCaseExpr GetTraceEntryCaseForUpdateToSomehowNextRoutine_LH(NextRoutine nextRoutine)
        {
            var highNextRoutine = nextRoutineMap[nextRoutine];
            var lowStmt         = (UpdateStmt)nextRoutine.armadaStatement.Stmt;
            var lowExprs        = lowStmt.Lhss;

            var highStmt  = (SomehowStmt)highNextRoutine.armadaStatement.Stmt;
            var highExprs = highStmt.Mod.Expressions;

            var pi = GetMatchingLowLevelLhssForHighLevelLhss(lowExprs, highExprs);

            var bvs = new List <BoundVar> {
                AH.MakeBoundVar("tid", "Armada_ThreadHandle")
            };

            bvs.AddRange(nextRoutine.Formals.Select(f => AH.MakeBoundVar(f.LocalVarName, AddModuleNameToArmadaType(f.VarType, "L"))));

            var ps = new List <Expression> {
                AH.MakeNameSegment("tid", "Armada_ThreadHandle")
            };

            ps.AddRange(nextRoutine.Formals.Select(f => AH.MakeNameSegment(f.LocalVarName, f.VarType))); // Use the tid (and any other) parameters from the bound vars in the case statement

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

                ps.Add(newRhs);
            }

            string nextRoutineName = nextRoutine.NameSuffix;
            string hname           = nextRoutineMap[nextRoutine].NameSuffix;
            var    case_body       = AH.MakeApplyN($"H.Armada_TraceEntry_{hname}", ps, "H.Armada_TraceEntry");
            var    case0           = AH.MakeMatchCaseExpr($"Armada_TraceEntry_{nextRoutineName}", bvs, case_body);

            return(case0);
        }
Пример #3
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");
        }
Пример #4
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");
        }