Exemple #1
0
        public ILGraphViewer(ILGraph graph)
        {
            InitializeComponent();

            this.Graph = graph;

            // Defaults
            this.BackColor = Color.White;

            // Create the vertex settings
            Dictionary <Instruction, VertexSettings>         vertices = new Dictionary <Instruction, VertexSettings>();
            Dictionary <Instruction, HashSet <Instruction> > targets  = graph.Targets;
            float x = this.Padding;
            float y = this.Padding;

            foreach (Instruction instruction in graph.Code)
            {
                if (!vertices.ContainsKey(instruction))
                {
                    vertices[instruction] = new VertexSettings(instruction, x, y)
                    {
                        Targets = targets[instruction].Select(i => {
                            if (!vertices.ContainsKey(i))
                            {
                                vertices[i] = new VertexSettings(i, 0, 0);
                            }
                            return(vertices[i]);
                        })
                    };
                }

                vertices[instruction].Center = new PointF(x, y);
                x += this.Spacing;
            }
            this.vertices = new SortedSet <VertexSettings>(vertices.Values, new VertexComparer());

            this.Size = GetPreferredSize(this.Size);

            this.Image = new Bitmap(this.Width, this.Height);

            this.Paint     += (sender, e) => Redraw();
            this.MouseMove += (sender, e) => {
                VertexSettings prevHovered = this.Hovered;
                this.Hovered = this.vertices.Where(vertex => vertex.GetBounds().Contains(this.ClientMousePosition)).LastOrDefault();
                if (prevHovered != this.Hovered)
                {
                    Redraw();
                }
            };
            this.Click += (sender, e) => Select(this.ClientMousePosition);
        }
Exemple #2
0
        public IEnumerable <Instruction> GetFluff(Matcher.MatcherData data)
        {
            ILGraph graph = data.Graph;

            HashSet <Instruction> fluff = new HashSet <Instruction>();

            foreach (Instruction stloc in data.Code)
            {
                int?loc = stloc.GetStLoc();
                if (loc == null)
                {
                    continue;
                }

                // Check that it gets immediately loaded again
                // TODO: Might want to search for the ldloc instead of assuming it's the next instruction.
                //       Basically, if no instructions between stloc and ldloc use the stack, then use that ldloc.
                Instruction ldloc = stloc.Next;
                if (ldloc?.GetLdLoc() != loc)
                {
                    continue;
                }

                // Search graph to see if this location is stored over before it's used
                HashSet <Instruction> visited = new HashSet <Instruction>();
                Dictionary <Instruction, HashSet <Instruction> > targets = graph.Targets;
                HashSet <Instruction> searching = new HashSet <Instruction>(targets[ldloc]);
                bool isFluff = true;
                while (searching.Any())
                {
                    HashSet <Instruction> nextSearch = new HashSet <Instruction>();
                    if (searching.Any(i => i.GetLdLoc() == loc))
                    {
                        isFluff = false;
                        break;
                    }
                    else
                    {
                        foreach (Instruction i in searching.Where(i => i.GetStLoc() != loc))
                        {
                            foreach (Instruction target in targets[i])
                            {
                                if (visited.Contains(target))
                                {
                                    continue;
                                }
                                nextSearch.Add(target);
                                visited.Add(target);
                            }
                        }
                    }
                    searching = nextSearch;
                }

                if (isFluff)
                {
                    fluff.Add(stloc);
                    fluff.Add(ldloc);
                }
            }

            return(fluff);
        }
Exemple #3
0
 /// <summary>
 /// arguments for GraphCollectionChanged events
 /// </summary>
 /// <param name="graph">the graph who was changed, for ILPlot: the scene graph</param>
 /// <param name="reason">reason</param>
 /// <param name="configurator"> instance of IILPanelConfigurator or null</param>
 public ILGraphCollectionChangedEventArgs(ILGraph graph, GraphCollectionChangeReason reason, IILPanelConfigurator configurator)
 {
     this.Graph        = graph;
     this.Reason       = reason;
     this.Configurator = configurator;
 }