Esempio n. 1
0
        public override Expression GetStoreBufferLocation()
        {
            if (!AH.IsPrimitiveType(type))
            {
                return(null);
            }

            var fields = new List <Expression>();
            var v      = GetStoreBufferLocationInfo(ref fields);

            if (v == null)
            {
                return(null);
            }

            var fields_seq = new SeqDisplayExpr(Token.NoToken, fields);

            return(AH.MakeApply2("Armada_StoreBufferLocation_Unaddressable", v, fields_seq, "Armada_StoreBufferLocation"));
        }
Esempio n. 2
0
        protected override void GenerateConvertTraceEntry_LH()
        {
            var cases = new List <MatchCaseExpr>();

            foreach (var nextRoutine in pgp.symbolsLow.NextRoutines)
            {
                cases.Add(GetTraceEntryCaseForNextRoutine_LH(nextRoutine));
            }

            ExpressionBuilder bodyBuilder = new ExpressionBuilder(pgp.prog);

            var ls    = AH.MakeNameSegment("ls", "L.Armada_TraceEntry");
            var entry = AH.MakeNameSegment("entry", "L.Armada_TraceEntry");
            var tid   = AH.MakeExprDotName(entry, "tid", "L.Armada_ThreadHandle");

            var locv    = AH.MakeApply2("L.Armada_GetThreadLocalView", ls, tid, "L.Armada_SharedMemory");
            var threads = AH.MakeExprDotName(ls, "threads", "map<Armada_ThreadHandle, Armada_Thread>");
            var t       = AH.MakeSeqSelectExpr(threads, tid, "L.Armada_Thread");

            // var t = AH.ParseExpression(pgp.prog, "", "ls.threads[tid]");

            locv = bodyBuilder.AddVariableDeclaration("locv", locv);
            t    = bodyBuilder.AddVariableDeclaration("t", t);

            var source = AH.MakeNameSegment("entry", "L.Armada_TraceEntry");
            var body   = AH.MakeMatchExpr(source, cases, "H.Armada_TraceEntry");

            bodyBuilder.SetBody(body);

            var formals = new List <Formal> {
                AH.MakeFormal("ls", "LState"), AH.MakeFormal("entry", "L.Armada_TraceEntry")
            };
            var validTraceEntryPredicate = AH.MakeApply2("L.Armada_ValidStep", ls, entry, new BoolType());

            var fn = AH.MakeFunctionWithReq("ConvertTraceEntry_LH", formals, validTraceEntryPredicate, bodyBuilder.Extract());

            pgp.AddDefaultClassDecl(fn, "convert");
        }
Esempio n. 3
0
        public NextRoutine(Program i_prog, ArmadaSymbolTable i_symbols, NextType i_nextType, MethodInfo methodInfo,
                           ArmadaStatement i_armadaStatement, Statement i_stmt, ArmadaPC i_pc, ArmadaPC i_endPC)
        {
            prog                  = i_prog;
            symbols               = i_symbols;
            nextType              = i_nextType;
            validStepBuilder      = new PredicateBuilder(i_prog);
            crashAvoidanceBuilder = new PredicateBuilder(i_prog);
            getNextStateBuilder   = new ExpressionBuilder(i_prog);
            method                = methodInfo != null ? methodInfo.method : null;
            armadaStatement       = i_armadaStatement;
            stmt                  = i_stmt;
            pc      = i_pc;
            endPC   = i_endPC;
            formals = new List <NextFormal>();
            valid   = true;

            s    = ReserveVariableName("s", "Armada_TotalState");
            tid  = ReserveVariableName("tid", "Armada_ThreadHandle");
            locv = null;

            // s.stop_reason.Armada_NotStopped?
            var stop_reason = AH.MakeExprDotName(s, "stop_reason", "Armada_StopReason");
            var not_stopped = AH.MakeExprDotName(stop_reason, "Armada_NotStopped?", new BoolType());

            AddConjunct(not_stopped);

            // tid in s.threads
            var threads        = AH.MakeExprDotName(s, "threads", AH.MakeThreadsType());
            var tid_in_threads = AH.MakeInExpr(tid, threads);

            AddConjunct(tid_in_threads);

            // var t := s.threads[tid];
            t = AddVariableDeclaration("t", AH.MakeSeqSelectExpr(threads, tid, "Armada_Thread"));

            // var locv := Armada_GetThreadLocalView(s, tid);
            locv = AH.MakeApply2("Armada_GetThreadLocalView", s, tid, "Armada_SharedMemory");
            locv = AddVariableDeclaration("locv", locv);

            if (pc != null)
            {
                var current_pc = AH.MakeExprDotName(t, "pc", "Armada_PC");
                var pc_correct = AH.MakeEqExpr(current_pc, AH.MakeNameSegment(pc.ToString(), "Armada_PC"));
                AddConjunct(pc_correct);

                // t.top.Armada_StackFrame_{methodName}?
                var top = AH.MakeExprDotName(t, "top", "Armada_StackFrame");
                var top_frame_correct = AH.MakeExprDotName(top, $"Armada_StackFrame_{pc.methodName}?", new BoolType());
                AddConjunct(top_frame_correct);

                if (methodInfo != null)
                {
                    var constraints = methodInfo.GetEnablingConstraintCollector(pc);
                    if (constraints != null && !constraints.Empty)
                    {
                        var enabling_condition = AH.MakeApply2($"Armada_EnablingConditions_{pc}", s, tid, new BoolType());
                        AddConjunct(enabling_condition);
                    }
                }
            }
        }