Example #1
0
        public ScrutinizerForm(List <IInstruction> FetchShader, List <IInstruction> Shader, IScrutinizer backend)
        {
            InitializeComponent();
            m_Backend     = backend;
            m_FetchShader = FetchShader;
            m_Ops         = Shader;

            try
            {
                Wrapper w = new Wrapper();

                List <IInstruction> Ops = m_Backend.BuildProgram();

                m_Ops    = Ops;
                m_Blocks = Algorithms.BuildBasicBlocks(Ops);
                if (!Algorithms.IsCFGReducible(m_Blocks))
                {
                    MessageBox.Show("Non-reducible flow-graph detected.  Can't analyze this.");
                    return;
                }

                Algorithms.FindDominators(m_Blocks);

                m_Loops = Algorithms.FindLoops(m_Blocks);
                Algorithms.ClassifyBranches(m_Ops);

                Algorithms.AssignLabels(m_Ops);

                int Y = 0;
                if (m_FetchShader.Count > 0)
                {
                    Label l0 = new Label();
                    Label l1 = new Label();
                    l0.AutoSize = true;
                    l1.AutoSize = true;
                    l0.Text     = "*** INSTRUCTIONS BELOW ARE AN APPROXIMATION TO THE FETCH SHADER***";
                    l1.Text     = "******************************************************************";
                    l0.Left     = 128;
                    l1.Left     = 128;
                    panel1.Controls.Add(l0);
                    Y = l0.Height;

                    foreach (IInstruction op in m_FetchShader)
                    {
                        InstructionWidget widget = new InstructionWidget(op);
                        AddInstructionToPanel(widget, op);
                        widget.Top  = Y;
                        widget.Left = 0;
                        Y          += widget.Height;
                    }

                    l1.Top = Y;
                    panel1.Controls.Add(l1);
                    Y += l1.Height;
                }

                foreach (BasicBlock b in m_Blocks)
                {
                    foreach (IInstruction op in b.Instructions)
                    {
                        if (!String.IsNullOrEmpty(op.Label))
                        {
                            Label l = new Label();
                            l.Font     = new Font("Lucida Console", 8);
                            l.AutoSize = true;
                            l.Text     = op.Label;
                            l.Left     = 100;
                            l.Top      = Y;
                            panel1.Controls.Add(l);
                            Y += l.Height;
                        }

                        InstructionWidget widget = new InstructionWidget(op);
                        AddInstructionToPanel(widget, op);
                        widget.Top  = Y;
                        widget.Left = 0;
                        Y          += widget.Height;
                    }
                    Y += 15;
                }

                cfgWidget1.SetProgram(m_Loops, m_Blocks);
                parameterWidget1.BuildUI(m_Backend.SimulationParameters);

                MarkExecutedInstructions();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }