Ejemplo n.º 1
0
        private string Dump(ProcedureStructure str)
        {
            StringWriter sw = new StringWriter();

            str.Write(sw);
            return(sw.ToString());
        }
Ejemplo n.º 2
0
 private void FindPostDominators(ProcedureBuilder m)
 {
     ProcedureStructureBuilder graphs = new ProcedureStructureBuilder(m.Procedure);
     h = graphs.Build();
     sw = new StringWriter();
     graphs.AnalyzeGraph().Write(sw);
 }
Ejemplo n.º 3
0
        private void FindPostDominators(ProcedureBuilder m)
        {
            ProcedureStructureBuilder graphs = new ProcedureStructureBuilder(m.Procedure);

            h  = graphs.Build();
            sw = new StringWriter();
            graphs.AnalyzeGraph().Write(sw);
        }
Ejemplo n.º 4
0
 private void CompileTest(ProcedureBuilder mock)
 {
     proc = mock.Procedure;
     StructureAnalysis sa = new StructureAnalysis(mock.Procedure);
     sa.BuildProcedureStructure();
     sa.FindStructures();
     curProc = sa.ProcedureStructure;
 }
Ejemplo n.º 5
0
 protected virtual void RunTest(ProcedureBuilder pm)
 {
     ProcedureStructureBuilder g = new ProcedureStructureBuilder(pm.Procedure);
     g.BuildNodes();
     g.DefineEdges();
     proc = g.CreateProcedureStructure();
     g.SetTimeStamps();
 }
Ejemplo n.º 6
0
        protected virtual void RunTest(ProcedureBuilder pm)
        {
            ProcedureStructureBuilder g = new ProcedureStructureBuilder(pm.Procedure);

            g.BuildNodes();
            g.DefineEdges();
            proc = g.CreateProcedureStructure();
            g.SetTimeStamps();
        }
Ejemplo n.º 7
0
        private void CompileTest(ProcedureBuilder mock)
        {
            proc = mock.Procedure;
            StructureAnalysis sa = new StructureAnalysis(mock.Procedure);

            sa.BuildProcedureStructure();
            sa.FindStructures();
            curProc = sa.ProcedureStructure;
        }
Ejemplo n.º 8
0
        private void CompileTest(ProcedureBuilder pm)
        {
            ProcedureStructureBuilder         g     = new ProcedureStructureBuilder(pm.Procedure);
            Dictionary <Block, StructureNode> nodes = new Dictionary <Block, StructureNode>();

            g.BuildNodes();
            g.DefineEdges();
            proc = g.CreateProcedureStructure();
            g.SetTimeStamps();
        }
Ejemplo n.º 9
0
 public void GenerateCode(ProcedureStructure proc, List<AbsynStatement> stms)
 {
     nodesToRender.Enqueue(new NodeEmitter(proc.EntryNode, new AbsynStatementEmitter(stms)));
     while (nodesToRender.Count > 0)
     {
         NodeEmitter ne = nodesToRender.Dequeue();
         if (IsVisited(ne.Node))
             EmitGotoAndForceLabel(ne.Predecessor, ne.Node, ne.Emitter);
         GenerateCode(ne.Node, null, ne.Emitter);
     }
 }
Ejemplo n.º 10
0
        protected virtual void RunTest(Procedure proc)
        {
            ProcedureStructureBuilder graphs = new ProcedureStructureBuilder(proc);

            graphs.BuildNodes();
            graphs.DefineEdges();
            ph = graphs.CreateProcedureStructure();
            graphs.SetTimeStamps();

            IntervalBuilder ib = new IntervalBuilder();

            intervals = ib.BuildIntervals(new StructureGraphAdapter(ph.Nodes), ph.EntryNode);
        }
Ejemplo n.º 11
0
        private ProcedureStructure CompileTest(Procedure proc)
        {
            ProcedureStructureBuilder g = new ProcedureStructureBuilder(proc);

            g.BuildNodes();
            g.DefineEdges();
            ProcedureStructure ps = g.CreateProcedureStructure();

            g.SetTimeStamps();

            DerivedSequenceBuilder gr = new DerivedSequenceBuilder(ps);

            return(ps);
        }
Ejemplo n.º 12
0
        public void LoopFinder_Reg00013()
        {
            Program prog = RewriteProgramMsdos("Fragments/regressions/r00013.asm", Address.SegPtr(0x800, 0));
            ProcedureStructureBuilder psb = new ProcedureStructureBuilder(prog.Procedures.Values[0]);
            proc = psb.Build();
            psb.AnalyzeGraph();

            proc.Dump();
            var lf = new LoopFinder(proc.Ordering[23], proc.Ordering[0], proc.Ordering);
            var intervalNodes = proc.Nodes[23].Interval.FindIntervalNodes(0);
            var loopNodes = lf.FindNodesInLoop(intervalNodes);
            proc.Dump();
            Loop loop = lf.DetermineLoopType(loopNodes);
            Assert.IsTrue(loop is TestlessLoop);
        }
Ejemplo n.º 13
0
        public void FindSelfLoopInInterval()
        {
            ProcedureStructure proc = CompileTest(delegate(ProcedureBuilder m)
            {
                m.Label("lupe");
                m.BranchIf(m.LocalBool("f"), "lupe");
                m.Return();
            });

            SccLoopFinder finder    = CreateSccLoopFinder(proc, proc.DerivedGraphs[0].Intervals[1], 0);
            var           loopNodes = finder.FindLoop();

            Assert.AreEqual(1, loopNodes.Count);
            var aNodes = new List <StructureNode>(loopNodes);

            Assert.AreEqual("lupe", aNodes[0].Block.Name);
        }
Ejemplo n.º 14
0
        public void LoopFinder_Reg00013()
        {
            Program prog = RewriteProgramMsdos("Fragments/regressions/r00013.asm", Address.SegPtr(0x800, 0));
            ProcedureStructureBuilder psb = new ProcedureStructureBuilder(prog.Procedures.Values[0]);

            proc = psb.Build();
            psb.AnalyzeGraph();

            proc.Dump();
            var lf            = new LoopFinder(proc.Ordering[23], proc.Ordering[0], proc.Ordering);
            var intervalNodes = proc.Nodes[23].Interval.FindIntervalNodes(0);
            var loopNodes     = lf.FindNodesInLoop(intervalNodes);

            proc.Dump();
            Loop loop = lf.DetermineLoopType(loopNodes);

            Assert.IsTrue(loop is TestlessLoop);
        }
Ejemplo n.º 15
0
        public void Reg00013()
        {
            ProcedureStructure proc = CompileTest("Fragments/regressions/r00013.asm");

            proc.DumpDerivedSequence(Console.Out);
            for (int j = 0; j < proc.DerivedGraphs.Count; ++j)
            {
                for (int i = 0; i < proc.DerivedGraphs[j].Intervals.Count; ++i)
                {
                    Interval      interval  = proc.DerivedGraphs[j].Intervals[i];
                    SccLoopFinder finder    = CreateSccLoopFinder(proc, interval, j);
                    var           loopNodes = finder.FindLoop();
                    var           items     = new List <StructureNode>(loopNodes);
                    items.Sort(delegate(StructureNode a, StructureNode b) { return(string.Compare(a.Name, b.Name)); });
                    foreach (StructureNode sn in items)
                    {
                        Console.Out.Write(sn.Name + " ");
                    }
                    Console.Out.WriteLine();
                }
            }
        }
Ejemplo n.º 16
0
        public void FindMultiNodeLoop()
        {
            ProcedureStructure proc = CompileTest(delegate(ProcedureBuilder m)
            {
                m.Label("lupe");
                m.BranchIf(m.LocalBool("a"), "branch_true");

                m.SideEffect(m.Fn("foo"));
                m.Jump("join");
                m.Label("branch_true");
                m.SideEffect(m.Fn("bar"));
                m.Label("join");
                m.BranchIf(m.LocalBool("b"), "lupe");
                m.Return();
            });

            SccLoopFinder finder    = CreateSccLoopFinder(proc, proc.DerivedGraphs[0].Intervals[1], 0);
            var           loopNodes = finder.FindLoop();

            Assert.AreEqual(4, loopNodes.Count);
            Assert.IsTrue(loopNodes.Contains(proc.Nodes[2]));
        }
Ejemplo n.º 17
0
 protected StructureNode GetNode(ProcedureStructure proc, string nodeName)
 {
     return(proc.Nodes.Find(node => node.Name == nodeName));
 }
Ejemplo n.º 18
0
 private void RunTest(ProcedureBuilder m)
 {
     var psb = new ProcedureStructureBuilder(m.Procedure);
     proc = psb.Build();
 }
Ejemplo n.º 19
0
        private SccLoopFinder CreateSccLoopFinder(ProcedureStructure proc, Interval intNode, int graphLevel)
        {
            var nodesInInterval = intNode.FindIntervalNodes(graphLevel);

            return(new SccLoopFinder(intNode, nodesInInterval));
        }
Ejemplo n.º 20
0
 public void BuildProcedureStructure()
 {
     var cfgs = new ProcedureStructureBuilder(proc);
     ProcedureStructure = cfgs.Build();
     cfgs.AnalyzeGraph();
 }
Ejemplo n.º 21
0
        private void StructureLoops(ProcedureStructure curProc)
        {
            for (int gLevel = 0; gLevel < curProc.DerivedGraphs.Count; ++gLevel)
            {
                var curGraph = curProc.DerivedGraphs[gLevel];
                foreach (Interval curInt in curGraph.Intervals)
                {
                    var headNode = IntervalHeaderNode(curInt);
                    var intNodes = curInt.FindIntervalNodes(gLevel);
                    var latch = FindGreatestEnclosingBackEdgeInInterval(headNode, intNodes);

                    // If a latch was found and it doesn't belong to another loop, 
                    // tag the loop nodes and classify it.
                    if (latch != null && latch.Loop == null)
                    {
                        CreateLoop(curProc, headNode, intNodes, latch);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        private void CompileTest(ProcedureBuilder pm)
        {
            ProcedureStructureBuilder g = new ProcedureStructureBuilder(pm.Procedure);
            Dictionary<Block, StructureNode> nodes = new Dictionary<Block, StructureNode>();
            g.BuildNodes();
            g.DefineEdges();
            proc = g.CreateProcedureStructure();
            g.SetTimeStamps();

        }
 public UnstructuredConditionalAnalysis(ProcedureStructure curProc)
 {
     this.curProc = curProc;
 }
Ejemplo n.º 24
0
        protected virtual void RunTest(Procedure proc)
        {
            ProcedureStructureBuilder graphs = new ProcedureStructureBuilder(proc);
            graphs.BuildNodes();
            graphs.DefineEdges();
            ph = graphs.CreateProcedureStructure();
            graphs.SetTimeStamps();

            IntervalBuilder ib = new IntervalBuilder();
            intervals = ib.BuildIntervals(new StructureGraphAdapter(ph.Nodes), ph.EntryNode);
        }
Ejemplo n.º 25
0
        private void RunTest(ProcedureBuilder m)
        {
            var psb = new ProcedureStructureBuilder(m.Procedure);

            proc = psb.Build();
        }
Ejemplo n.º 26
0
 protected StructureNode GetNode(ProcedureStructure proc, string nodeName)
 {
     return proc.Nodes.Find(node => node.Name == nodeName);
 }
Ejemplo n.º 27
0
        private void CreateLoop(ProcedureStructure curProc, StructureNode headNode, HashSet<StructureNode> intervalNodes, StructureNode latch)
        {
            Debug.WriteLine(string.Format("Creating loop {0}-{1}", headNode.Name, latch.Name));

            // if the head node has already been determined as a loop header then the nodes
            // within this loop have to be untagged and the latch reset to its original type
            if (headNode.Loop != null && headNode.Loop.Latch != null)
            {
                StructureNode oldLatch = headNode.Loop.Latch;

                // reset the latch node's structured class. Only need to do this for a 2 way latch
//                if (oldLatch.BlockType == bbType.cBranch)
//                    oldLatch.SetStructType(structType.Cond);

                // untag the nodes
                for (int i = headNode.Order - 1; i >= oldLatch.Order; i--)
                    if (curProc.Ordering[i].Loop.Header == headNode)
                        curProc.Ordering[i].Loop = null;
            }


            // the latching node will already have been structured as a conditional header. If it is not
            // also the loop header (i.e. the loop is over more than one block) then reset
            // it to be a sequential node otherwise it will be correctly set as a loop header only later
//            if (latch != headNode)
//                latch.SetStructType(structType.Seq);


            var lf = new LoopFinder(headNode, latch, curProc.Ordering);
            var loopNodes = lf.FindNodesInLoop(intervalNodes);
            var loop = lf.DetermineLoopType(loopNodes);
        }
Ejemplo n.º 28
0
 private string Dump(ProcedureStructure str)
 {
     StringWriter sw = new StringWriter();
     str.Write(sw);
     return sw.ToString();
 }
Ejemplo n.º 29
0
 private SccLoopFinder CreateSccLoopFinder(ProcedureStructure proc, Interval intNode, int graphLevel)
 {
     var nodesInInterval = intNode.FindIntervalNodes(graphLevel);
     return new SccLoopFinder(intNode, nodesInInterval);
 }