private void FindPostDominators(ProcedureBuilder m)
 {
     ProcedureStructureBuilder graphs = new ProcedureStructureBuilder(m.Procedure);
     h = graphs.Build();
     sw = new StringWriter();
     graphs.AnalyzeGraph().Write(sw);
 }
Example #2
0
 protected virtual void RunTest(ProcedureBuilder pm)
 {
     ProcedureStructureBuilder g = new ProcedureStructureBuilder(pm.Procedure);
     g.BuildNodes();
     g.DefineEdges();
     proc = g.CreateProcedureStructure();
     g.SetTimeStamps();
 }
 private void CompileTest(ProcedureBuilder mock)
 {
     proc = mock.Procedure;
     StructureAnalysis sa = new StructureAnalysis(mock.Procedure);
     sa.BuildProcedureStructure();
     sa.FindStructures();
     curProc = sa.ProcedureStructure;
 }
Example #4
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);
     }
 }
Example #5
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);
        }
Example #6
0
 private void RunTest(ProcedureBuilder m)
 {
     var psb = new ProcedureStructureBuilder(m.Procedure);
     proc = psb.Build();
 }
        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;
 }
Example #9
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);
        }
Example #10
0
 protected StructureNode GetNode(ProcedureStructure proc, string nodeName)
 {
     return proc.Nodes.Find(node => node.Name == nodeName);
 }
Example #11
0
 private SccLoopFinder CreateSccLoopFinder(ProcedureStructure proc, Interval intNode, int graphLevel)
 {
     var nodesInInterval = intNode.FindIntervalNodes(graphLevel);
     return new SccLoopFinder(intNode, nodesInInterval);
 }
Example #12
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);
        }
Example #13
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);
                    }
                }
            }
        }
Example #14
0
 public void BuildProcedureStructure()
 {
     var cfgs = new ProcedureStructureBuilder(proc);
     ProcedureStructure = cfgs.Build();
     cfgs.AnalyzeGraph();
 }
Example #15
0
 private string Dump(ProcedureStructure str)
 {
     StringWriter sw = new StringWriter();
     str.Write(sw);
     return sw.ToString();
 }