public void Warning(Absy subject, string msg, params object[] args)
 {
     Contract.Requires(args != null);
     Contract.Requires(msg != null);
     Contract.Requires(subject != null);
     Warning(subject.tok, msg, args);
 }
Ejemplo n.º 2
0
        public static HashSet <string> GetProceduresCalled(Absy node)
        {
            var fu = new ProcsCalledVisitor();

            fu.Visit(node);
            return(fu.procsCalled);
        }
Ejemplo n.º 3
0
        internal void Propagate(Absy node)
        {
            Block block = cmdBlocks[node];

            if (node is Cmd)
            {
                int  index = block.Cmds.IndexOf(node as Cmd);
                Absy cmd   = (index < block.Cmds.Count - 1) ? block.Cmds[index + 1] : cmd = block.TransferCmd;
                workList.Add(cmd);
                cmdBlocks[cmd] = block;
            }
            else if (node is GotoCmd)
            {
                foreach (var succ in (node as GotoCmd).labelTargets)
                {
                    Absy cmd;
                    if (succ.Cmds.Count > 0)
                    {
                        cmd = succ.Cmds[0];
                    }
                    else
                    {
                        cmd = succ.TransferCmd; // some blocks are just a goto
                    }
                    workList.Add(cmd);
                    cmdBlocks[cmd] = succ;
                }
            }
            else
            {
                Console.WriteLine("Error in WorkList: Propagating state for " + node);
                Debug.Assert(false);
            }
        }
Ejemplo n.º 4
0
 public void WriteLine(Absy node, int level, string text)
 {
     Contract.Requires(text != null);
     Contract.Requires(node != null);
     this.SetToken(node);
     this.WriteLine(level, text);
 }
Ejemplo n.º 5
0
            private void AddParCallCmdLabels(Dictionary <Tuple <Absy, Absy>, string> edgeLabels, ParCallCmd parCallCmd,
                                             Absy next)
            {
                CheckNonMoverCondition(parCallCmd);
                if (parCallCmd.CallCmds.Any(callCmd => CallCmdLabel(callCmd) == Y &&
                                            [email protected](
                                                callCmd.Proc)))
                {
                    if (parCallCmd.CallCmds.Any(callCmd => CallCmdLabel(callCmd) == A))
                    {
                        @base.checkingContext.Error(parCallCmd,
                                                    $"Parallel call contains both non-mover and yielding procedure at layer {currLayerNum}");
                    }
                    else
                    {
                        CheckYieldingProcCondition(parCallCmd);
                    }
                }

                edgeLabels[new Tuple <Absy, Absy>(parCallCmd, parCallCmd.CallCmds[0])] = P;
                for (int i = 0; i < parCallCmd.CallCmds.Count; i++)
                {
                    var callCmd = parCallCmd.CallCmds[i];
                    var edge    = new Tuple <Absy, Absy>(callCmd,
                                                         i + 1 < parCallCmd.CallCmds.Count ? parCallCmd.CallCmds[i + 1] : next);
                    var label = CallCmdLabel(callCmd);
                    edgeLabels[edge] = label;
                }
            }
Ejemplo n.º 6
0
        private void CheckAndAddLayers(Absy node, QKeyValue attributes, int enclosingProcLayerNum)
        {
            List <int> attrs = RemoveDuplicatesAndSort(FindLayers(attributes));

            if (attrs.Count == 0)
            {
                Error(node, "layer not present");
                return;
            }
            LayerRange upperBound = FindLayerRange();

            absyToLayerNums[node] = new HashSet <int>();
            foreach (int layerNum in attrs)
            {
                if (layerNum > enclosingProcLayerNum)
                {
                    Error(node, "The layer cannot be greater than the layer of enclosing procedure");
                }
                else if (upperBound.Contains(layerNum))
                {
                    absyToLayerNums[node].Add(layerNum);
                }
                else
                {
                    Error(node, string.Format("A variable being accessed in this specification is unavailable at layer {0}", layerNum));
                }
            }
        }
Ejemplo n.º 7
0
        public override Absy Visit(Absy node)
        {
            Contract.Requires(node != null);
            Contract.Ensures(Contract.Result <Absy>() != null);

            throw new System.NotImplementedException();
        }
Ejemplo n.º 8
0
 /// <summary>
 ///     Returns all variables which are occur within an old expression in <paramref name="node" />
 ///     and which satisfy <paramref name="pred" />
 /// </summary>
 public ISet <Variable> FindOldVariables(Absy node, Predicate <Variable> pred)
 {
     _freeOldVars = new GSet <Variable>();
     _pred        = pred;
     Visit(node);
     return(new HashSet <Variable>(_freeOldVars));
 }
Ejemplo n.º 9
0
 public void Write(Absy node, string text, params string[] args)
 {
     Contract.Requires(text != null);
     Contract.Requires(node != null);
     this.SetToken(node);
     this.Write(text, args);
 }
Ejemplo n.º 10
0
        public static HashSet <Variable> GetVariables(Absy node)
        {
            var vu = new VarsUsed();

            vu.Visit(node);
            return(vu.Vars);
        }
Ejemplo n.º 11
0
        public static HashSet <string> GetFunctionsUsed(Absy node)
        {
            var fu = new FunctionsUsed();

            fu.Visit(node);
            return(fu.funcsUsed);
        }
Ejemplo n.º 12
0
        public static HashSet <string> GetVarsUsed(Absy node)
        {
            var vu = new VarsUsed();

            vu.Visit(node);
            return(vu.varsUsed);
        }
Ejemplo n.º 13
0
        public static void Collect(Absy node, out List <DeclWithFormals> dependencies)
        {
            var dc = new DependencyCollector();

            dc.Visit(node);
            dependencies = dc.dependencies.ToList();
        }
Ejemplo n.º 14
0
 public override Absy Visit(Absy node)
 {
     //Contract.Requires(node != null);
     Contract.Ensures(Contract.Result <Absy>() != null);
     node = base.Visit(node);
     return(node);
 }
        public Dictionary <string, Expr> PermissionExprs(Absy absy)
        {
            var linearTypeChecker = civlTypeChecker.linearTypeChecker;
            var domainNameToScope = new Dictionary <string, HashSet <Variable> >();

            foreach (var domainName in linearTypeChecker.linearDomains.Keys)
            {
                domainNameToScope[domainName] = new HashSet <Variable>();
            }

            var availableVars = AvailableLinearLocalVars(absy).Union(LinearGlobalVars());

            foreach (var v in availableVars)
            {
                var domainName = linearTypeChecker.FindDomainName(v);
                domainNameToScope[domainName].Add(MapVariable(v));
            }

            var domainNameToExpr = new Dictionary <string, Expr>();

            foreach (var domainName in domainNameToScope.Keys)
            {
                var permissionExprs =
                    linearTypeChecker.PermissionExprForEachVariable(domainName, domainNameToScope[domainName]);
                domainNameToExpr[domainName] = linearTypeChecker.UnionExprForPermissions(domainName, permissionExprs);
            }

            return(domainNameToExpr);
        }
Ejemplo n.º 16
0
        // returns whether a propagation occured
        internal bool Assign(Absy node, AbsState state)
        {
            Block block = cmdBlocks[node];

            var callNode = (node as CallCmd);

            if (callNode != null) // maintain procCallers
            {
                var callee = callNode.Proc;
                if (!procCallers.ContainsKey(callee))
                {
                    procCallers[callee] = new HashSet <CallCmd>();
                }
                procCallers[callee].Add(callNode);
            }

            // if the new state for the node is different, add all succesors to the worklist
            if (!stateSpace.ContainsKey(node))
            {
                stateSpace[node] = state;
            }
            else if (!stateSpace[node].JoinWith(state))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 17
0
            public static void ReportBplError(Absy node, string message, bool error, bool showBplLocation)
            {
                Contract.Requires(message != null);
                Contract.Requires(node != null);
                IToken tok = node.tok;
                string s;

                if (tok != null && showBplLocation)
                {
                    s = string.Format("{0}({1},{2}): {3}", tok.filename, tok.line, tok.col, message);
                }
                else
                {
                    s = message;
                }

                if (error)
                {
                    ErrorWriteLine(s);
                }
                else
                {
                    Console.WriteLine(s);
                }
            }
Ejemplo n.º 18
0
 public void add(Absy node)
 {
     //if (node is TypedIdent) return;
     //if (node is Microsoft.Boogie.Type) return;
     m[node.UniqueId] = node;
     nodes.Add(node.UniqueId);
 }
Ejemplo n.º 19
0
 public void WriteLine(Absy node, int level, string text, params object[] args)
 {
     Contract.Requires(text != null);
     Contract.Requires(node != null);
     this.SetToken(node);
     this.WriteLine(level, text, args);
 }
Ejemplo n.º 20
0
        private void CheckAndAddLayers(Absy node, QKeyValue attributes, int enclosingProcLayerNum)
        {
            List <int> attrs = RemoveDuplicatesAndSort(FindLayers(attributes));

            if (attrs.Count == 0)
            {
                Error(node, "layer not present");
                return;
            }
            absyToLayerNums[node] = new HashSet <int>();
            foreach (int layerNum in attrs)
            {
                if (layerNum == leastUnimplementedLayerNum || !AllCreatedLayerNums.Contains(layerNum))
                {
                    Error(node, "Illegal layer number");
                }
                else if (layerNum > enclosingProcLayerNum)
                {
                    Error(node, "The layer cannot be greater than the layer of enclosing procedure");
                }
                else if (maxLayerNum < layerNum && layerNum <= minLayerNum)
                {
                    absyToLayerNums[node].Add(layerNum);
                }
                else
                {
                    Error(node, string.Format("A variable being accessed in this specification is unavailable at layer {0}", layerNum));
                }
            }
        }
        private void DiscoverVariableAssignments(Variable variable)
        {
            Absy assignment = null;

            foreach (Block block in cfg.Nodes)
            {
                foreach (Cmd cmd in block.Cmds)
                {
                    if (cmd is AssignCmd)
                    {
                        AssignCmd assignCmd = cmd as AssignCmd;
                        var       lhss      = assignCmd.Lhss.OfType <SimpleAssignLhs>();
                        foreach (var LhsRhs in lhss.Zip(assignCmd.Rhss))
                        {
                            if (LhsRhs.Item1.DeepAssignedVariable.Name == variable.Name)
                            {
                                assignment = LhsRhs.Item2;
                                if (variable.Name == this.initialVariable.Name)
                                {
                                    unexpandedExpr = LhsRhs.Item2;
                                }
                                goto AnalyseAssignment;
                            }
                        }
                    }
                    else if (cmd is CallCmd)
                    {
                        CallCmd call = cmd as CallCmd;
                        foreach (IdentifierExpr outParam in call.Outs)
                        {
                            if (outParam.Name == variable.Name)
                            {
                                assignment = cmd;
                                goto AnalyseAssignment;
                            }
                        }
                    }
                }
            }

            // Label used to allow exit from multiple levels in the previous loop nest
AnalyseAssignment:
            if (assignment != null)
            {
                var visitor = new VariablesOccurringInExpressionVisitor();
                visitor.Visit(assignment);
                foreach (Variable discovered in visitor.GetVariables())
                {
                    if (TEMP_VARIABLE.IsMatch(discovered.Name) && discovered.Name != variable.Name)
                    {
                        DiscoverVariableAssignments(discovered);
                    }
                    else if (GPU_VARIABLE.IsMatch(discovered.Name))
                    {
                        GPUVariables.Add(discovered);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        private IEnumerable <VariableDescriptor> GetReferencedVariables(Absy node, string proc)
        {
            var VarCollector = new VariableCollector();

            VarCollector.Visit(node);
            return(VarCollector.usedVars.Where(Item => VariableRelevantToAnalysis(Item, proc)).
                   Select(Item => MakeDescriptor(proc, Item)));
        }
Ejemplo n.º 23
0
        private static void ReportBarrierDivergence(Absy node)
        {
            Console.Error.WriteLine();
            var sli = new SourceLocationInfo(GetAttributes(node), GetSourceFileName(), node.tok);

            ErrorWriteLine(sli.Top() + ":", "barrier may be reached by non-uniform control flow", ErrorMsgType.Error);
            sli.PrintStackTrace();
        }
Ejemplo n.º 24
0
        private static void ReportEnsuresFailure(Absy node)
        {
            Console.Error.WriteLine();
            var sli = new SourceLocationInfo(GetAttributes(node), GetSourceFileName(), node.tok);

            ErrorWriteLine(sli.Top() + ":", "postcondition might not hold on all return paths", ErrorMsgType.Error);
            sli.PrintStackTrace();
        }
Ejemplo n.º 25
0
 // this is a simple transformer for a command that has no effect on the state
 internal Absy SimpleTransform(Absy node)
 {
     if (Assign(node, GatherPredecessorsState(node, cmdBlocks[node])))
     {
         Propagate(node);
     }
     return(node);
 }
Ejemplo n.º 26
0
        public Term TranslateSingle(Absy cmd)
        {
            if (cmd is HavocCmd)
            {
                throw new ArgumentException("Can only input commands that are desugared to single commands");
            }

            return(basicCmdVisitor.Translate(cmd));
        }
Ejemplo n.º 27
0
 protected override bool TranslatePrecondition(Absy node)
 {
     return(node is GlobalVariable ||
            node is Constant ||
            node is LocalVariable ||
            node is Formal ||
            node is Function ||
            node is Type);
 }
Ejemplo n.º 28
0
            private void ComputeGraph()
            {
                // Internal representation
                // At the end of the method, we translate to List<Tuple<Absy, int, Absy>>
                Dictionary <Tuple <Absy, Absy>, string> edgeLabels = new Dictionary <Tuple <Absy, Absy>, string>();

                foreach (Block block in impl.Blocks)
                {
                    // Block entry edge
                    Absy blockEntry = block.Cmds.Count == 0 ? (Absy)block.TransferCmd : (Absy)block.Cmds[0];
                    edgeLabels[new Tuple <Absy, Absy>(block, blockEntry)] =
                        @base.civlTypeChecker.IsYieldingLoopHeader(block, currLayerNum) ? Y : P;

                    // Block exit edges
                    if (block.TransferCmd is GotoCmd gotoCmd)
                    {
                        foreach (Block successor in gotoCmd.labelTargets)
                        {
                            edgeLabels[new Tuple <Absy, Absy>(block.TransferCmd, successor)] = P;
                        }
                    }
                    else if (block.TransferCmd is ReturnCmd)
                    {
                        finalStates.Add(block.TransferCmd);
                    }

                    // Block internal edges
                    for (int i = 0; i < block.Cmds.Count; i++)
                    {
                        Cmd  cmd  = block.Cmds[i];
                        Absy next = (i + 1 == block.Cmds.Count) ? (Absy)block.TransferCmd : block.Cmds[i + 1];
                        Tuple <Absy, Absy> edge = new Tuple <Absy, Absy>(cmd, next);
                        if (cmd is CallCmd callCmd)
                        {
                            edgeLabels[edge] = CallCmdLabel(callCmd);
                        }
                        else if (cmd is ParCallCmd parCallCmd)
                        {
                            AddParCallCmdLabels(edgeLabels, parCallCmd, next);
                        }
                        else if (cmd is YieldCmd)
                        {
                            edgeLabels[edge] = Y;
                        }
                        else
                        {
                            edgeLabels[edge] = P;
                        }
                    }
                }

                foreach (Tuple <Absy, Absy> e in edgeLabels.Keys)
                {
                    implEdges.Add(new Tuple <Absy, string, Absy>(e.Item1, edgeLabels[e], e.Item2));
                }
            }
Ejemplo n.º 29
0
 public T Translate(Absy node)
 {
     if (!StateIsFresh())
     {
         throw new ProofGenUnexpectedStateException(GetType());
     }
     Contract.Assert(TranslatePrecondition(node));
     Visit(node);
     return(Results.Pop());
 }
Ejemplo n.º 30
0
        private int GetLineNumber(Absy node)
        {
            int line = node.tok.line;

            #if DEBUG
            string filename = Path.GetFileName(node.tok.filename);
            Debug.Assert(filename == Path.GetFileName(PathToProgram), "Mismatched tokens. Expected " + Path.GetFileName(PathToProgram) + ", got " + filename);
            #endif
            return(line);
        }