private void TransformImpl(Implementation originalImpl, Implementation impl)
        {
            // initialize globalSnapshotInstrumentation
            globalSnapshotInstrumentation = new GlobalSnapshotInstrumentation(civlTypeChecker);

            // initialize refinementInstrumentation
            YieldingProc yieldingProc = civlTypeChecker.procToYieldingProc[originalImpl.Proc];

            if (yieldingProc.upperLayer == this.layerNum)
            {
                if (yieldingProc is ActionProc)
                {
                    refinementInstrumentation = new ActionRefinementInstrumentation(
                        civlTypeChecker,
                        impl,
                        originalImpl,
                        globalSnapshotInstrumentation.OldGlobalMap);
                }
                else
                {
                    refinementInstrumentation = new SkipRefinementInstrumentation(
                        civlTypeChecker,
                        yieldingProc,
                        globalSnapshotInstrumentation.OldGlobalMap);
                }
            }
            else
            {
                refinementInstrumentation = new RefinementInstrumentation();
            }

            var allYieldPredicates = CollectYields(impl);

            // initialize noninterferenceInstrumentation
            if (CommandLineOptions.Clo.TrustNonInterference)
            {
                noninterferenceInstrumentation = new NoneNoninterferenceInstrumentation();
            }
            else
            {
                noninterferenceCheckerDecls.AddRange(
                    NoninterferenceChecker.CreateNoninterferenceCheckers(civlTypeChecker, linearTypeChecker, layerNum, absyMap, impl, allYieldPredicates));
                noninterferenceInstrumentation = new SomeNoninterferenceInstrumentation(
                    civlTypeChecker,
                    linearTypeChecker,
                    linearPermissionInstrumentation,
                    globalSnapshotInstrumentation.OldGlobalMap,
                    wrapperNoninterferenceCheckerProc);
            }

            DesugarConcurrency(impl, allYieldPredicates);

            impl.LocVars.AddRange(globalSnapshotInstrumentation.NewLocalVars);
            impl.LocVars.AddRange(refinementInstrumentation.NewLocalVars);
            impl.LocVars.AddRange(noninterferenceInstrumentation.NewLocalVars);
        }
        private YieldingProcInstrumentation(
            CivlTypeChecker civlTypeChecker,
            LinearTypeChecker linearTypeChecker,
            LinearPermissionInstrumentation linearPermissionInstrumentation,
            int layerNum,
            Dictionary <Absy, Absy> absyMap,
            Dictionary <CallCmd, Block> refinementBlocks)
        {
            this.civlTypeChecker   = civlTypeChecker;
            this.linearTypeChecker = linearTypeChecker;
            this.layerNum          = layerNum;
            this.absyMap           = absyMap;
            this.linearPermissionInstrumentation = linearPermissionInstrumentation;
            this.refinementBlocks       = refinementBlocks;
            parallelCallAggregators     = new Dictionary <string, Procedure>();
            noninterferenceCheckerDecls = new List <Declaration>();

            List <Variable> inputs = new List <Variable>();

            foreach (string domainName in linearTypeChecker.linearDomains.Keys)
            {
                inputs.Add(linearTypeChecker.LinearDomainInFormal(domainName));
            }

            foreach (Variable g in civlTypeChecker.GlobalVariables)
            {
                inputs.Add(OldGlobalFormal(g));
            }

            wrapperNoninterferenceCheckerProc = new Procedure(Token.NoToken,
                                                              $"Wrapper_NoninterferenceChecker_{layerNum}", new List <TypeVariable>(),
                                                              inputs, new List <Variable>(), new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>());
            CivlUtil.AddInlineAttribute(wrapperNoninterferenceCheckerProc);

            // initialize globalSnapshotInstrumentation
            globalSnapshotInstrumentation = new GlobalSnapshotInstrumentation(civlTypeChecker);

            // initialize noninterferenceInstrumentation
            if (CommandLineOptions.Clo.TrustNoninterference)
            {
                noninterferenceInstrumentation = new NoneNoninterferenceInstrumentation();
            }
            else
            {
                noninterferenceInstrumentation = new SomeNoninterferenceInstrumentation(
                    civlTypeChecker,
                    linearTypeChecker,
                    linearPermissionInstrumentation,
                    globalSnapshotInstrumentation.OldGlobalMap,
                    wrapperNoninterferenceCheckerProc);
            }
        }
        private void TransformImpl(Implementation impl)
        {
            HashSet <Block> yieldingLoopHeaders;
            Graph <Block>   graph = ComputeYieldingLoopHeaders(impl, out yieldingLoopHeaders);

            // initialize globalSnapshotInstrumentation
            globalSnapshotInstrumentation = new GlobalSnapshotInstrumentation(civlTypeChecker);

            // initialize refinementInstrumentation
            Procedure    originalProc = implMap[impl].Proc;
            YieldingProc yieldingProc = civlTypeChecker.procToYieldingProc[originalProc];

            if (yieldingProc.upperLayer == this.layerNum)
            {
                refinementInstrumentation = new SomeRefinementInstrumentation(
                    civlTypeChecker,
                    impl,
                    originalProc,
                    globalSnapshotInstrumentation.OldGlobalMap,
                    yieldingLoopHeaders);
            }
            else
            {
                refinementInstrumentation = new NoneRefinementInstrumentation();
            }

            // initialize noninterferenceInstrumentation
            if (CommandLineOptions.Clo.TrustNonInterference)
            {
                noninterferenceInstrumentation = new NoneNoninterferenceInstrumentation();
            }
            else
            {
                noninterferenceInstrumentation = new SomeNoninterferenceInstrumentation(civlTypeChecker,
                                                                                        linearTypeChecker,
                                                                                        layerNum, absyMap, globalSnapshotInstrumentation.OldGlobalMap, yieldProc);
            }

            DesugarConcurrency(impl, graph, yieldingLoopHeaders);

            impl.LocVars.AddRange(globalSnapshotInstrumentation.NewLocalVars);
            impl.LocVars.AddRange(refinementInstrumentation.NewLocalVars);
            impl.LocVars.AddRange(noninterferenceInstrumentation.NewLocalVars);
        }
Example #4
0
        private void TransformImpl(Implementation impl, List <Cmd> preconditions)
        {
            // initialize globalSnapshotInstrumentation
            globalSnapshotInstrumentation = new GlobalSnapshotInstrumentation(civlTypeChecker);

            // initialize refinementInstrumentation
            var yieldingProc = GetYieldingProc(impl);

            if (yieldingProc.upperLayer == this.layerNum)
            {
                refinementInstrumentation = new ActionRefinementInstrumentation(
                    civlTypeChecker,
                    impl,
                    (Implementation)absyMap[impl],
                    globalSnapshotInstrumentation.OldGlobalMap);
            }
            else
            {
                refinementInstrumentation = new RefinementInstrumentation();
            }

            // initialize noninterferenceInstrumentation
            if (CommandLineOptions.Clo.TrustNoninterference)
            {
                noninterferenceInstrumentation = new NoneNoninterferenceInstrumentation();
            }
            else
            {
                noninterferenceInstrumentation = new SomeNoninterferenceInstrumentation(
                    civlTypeChecker,
                    linearTypeChecker,
                    linearPermissionInstrumentation,
                    globalSnapshotInstrumentation.OldGlobalMap,
                    wrapperNoninterferenceCheckerProc);
            }

            DesugarConcurrency(impl, preconditions);

            impl.LocVars.AddRange(globalSnapshotInstrumentation.NewLocalVars);
            impl.LocVars.AddRange(refinementInstrumentation.NewLocalVars);
            impl.LocVars.AddRange(noninterferenceInstrumentation.NewLocalVars);
        }