Ejemplo n.º 1
0
 private void ExtractGVNodes(InstNode root, Dictionary <InstNode, GraphVizNode> nodeDict)
 {
     GraphTraversal.PerformTraversal <InstNode>(root, (node, fringeAdder) =>
     {
         if (!nodeDict.ContainsKey(node))
         {
             var ms = new MemoryStream();
             var sw = new StreamWriter(ms);
             PrettyPrinter.PrettyPrint(node.Content, sw);
             sw.Flush();
             ms.Seek(0, SeekOrigin.Begin);
             var data = new StreamReader(ms).ReadToEnd();
             nodeDict.Add(node, new GraphVizNode()
             {
                 Id = IdC++, Label = data
             });
             if (node.Left != null)
             {
                 fringeAdder(node.Left);
             }
             if (node.Right != null)
             {
                 fringeAdder(node.Right);
             }
         }
     });
 }
Ejemplo n.º 2
0
        public uint CalculateWCET2(InstNode root)
        {
            var visitedNodes = new Dictionary <InstNode, Func <uint> >();
            var cache        = new Dictionary <InstNode, uint>();

            GraphTraversal.PerformTraversal <InstNode>(root, (node, fringeAdder) =>
            {
                if (visitedNodes.ContainsKey(node))
                {
                    return;
                }
                var cycles     = (uint)(node.Content.Count * 0);
                cycles        += node.StaticCost;
                Func <uint> lc = () => 0u;
                Func <uint> rc = () => 0u;
                if (node.Left != null)
                {
                    fringeAdder(node.Left);
                    lc = () =>
                    {
                        uint c;
                        if (cache.TryGetValue(node.Left, out c))
                        {
                            return(c);
                        }
                        c = visitedNodes[node.Left]();
                        cache.Add(node.Left, c);
                        return(c);
                    };
                }
                if (node.Right != null)
                {
                    fringeAdder(node.Right);
                    rc = () =>
                    {
                        uint c;
                        if (cache.TryGetValue(node.Right, out c))
                        {
                            return(c);
                        }
                        c = visitedNodes[node.Right]();
                        cache.Add(node.Right, c);
                        return(c);
                    };
                }
                visitedNodes.Add(node, () => cycles + Math.Max(lc(), rc()));
            }, true);
            return(visitedNodes[root]());
        }
Ejemplo n.º 3
0
        private ISet <Tuple <InstNode, InstNode> > FindCycles2(InstNode root)
        {
            var visitedNodes = new HashSet <InstNode>();
            var cycles       = new HashSet <Tuple <InstNode, InstNode> >();

            GraphTraversal.PerformTraversal <InstNode>(root, (node, fringeAdder) =>
            {
                if (visitedNodes.Contains(node))
                {
                    return;
                }
                visitedNodes.Add(node);
                if (node.Left != null)
                {
                    if (visitedNodes.Contains(node.Left))
                    {
                        cycles.Add(new Tuple <InstNode, InstNode>(node, node.Left));
                    }
                }
                if (node.Right != null)
                {
                    if (visitedNodes.Contains(node.Right))
                    {
                        cycles.Add(new Tuple <InstNode, InstNode>(node, node.Right));
                    }
                }
                if (node.Left != null)
                {
                    if (!visitedNodes.Contains(node.Left))
                    {
                        fringeAdder(node.Left);
                    }
                }
                if (node.Right != null)
                {
                    if (!visitedNodes.Contains(node.Right))
                    {
                        fringeAdder(node.Right);
                    }
                }
            });
            return(cycles);
        }
Ejemplo n.º 4
0
        private void GenerateGraphLinks(Node <IList <IInstruction> > root, Dictionary <InstNode, GraphVizNode> graphVizNodes, StringBuilder builder)
        {
            var visitedNodes = new HashSet <InstNode>();

            GraphTraversal.PerformTraversal <InstNode>(root, (node, fringeAdder) =>
            {
                if (visitedNodes.Contains(node))
                {
                    return;
                }
                visitedNodes.Add(node);
                if (node.Left != null)
                {
                    builder.AppendLine(String.Format("node{0}->node{1}", graphVizNodes[node].Id, graphVizNodes[node.Left].Id));
                    fringeAdder(node.Left);
                }
                if (node.Right != null)
                {
                    builder.AppendLine(String.Format("node{0}->node{1}", graphVizNodes[node].Id, graphVizNodes[node.Right].Id));
                    fringeAdder(node.Right);
                }
            });
        }