public void sizeFourInfiniteLoop() { LoopFinder myLoopFinder = new LoopFinder(new List <int>() { 0, 2, 7, 0 }); Tuple <int, int> stepsToInfinite = myLoopFinder.FindInfinite(); Assert.AreEqual(4, stepsToInfinite.Item2); }
public void fiveStepsToInfinite() { LoopFinder myLoopFinder = new LoopFinder(new List <int>() { 0, 2, 7, 0 }); Tuple <int, int> stepsToInfinite = myLoopFinder.FindInfinite(); Assert.AreEqual(5, stepsToInfinite.Item1); }
public void singleIteration() { LoopFinder myLoopFinder = new LoopFinder(new List <int>() { 0, 2, 7, 0 }); List <int> firstLoopResult = myLoopFinder.NextPass(); Assert.AreEqual(new List <int>() { 2, 4, 1, 2 }, firstLoopResult); }
public void LoopFinder_WhileGoto_TagNodes() { RunTest(new MockWhileGoto()); StringWriter sw = new StringWriter(); proc.Write(sw); Console.WriteLine(sw.ToString()); Assert.AreEqual("LoopHead", proc.Ordering[6].Block.Name); Interval i = proc.DerivedGraphs[0].Intervals[1]; Assert.AreEqual("LoopHead", i.Header.Name); LoopFinder lf = new LoopFinder(proc.Ordering[6], proc.Ordering[2], proc.Ordering); var loopNodes = lf.FindNodesInLoop(i.FindIntervalNodes(0)); Assert.AreEqual(3, loopNodes.Count); }
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); }
private void Start() { Node exit = new Node(new Vector2(-1, -1)); vtg = new VoronoiToGraph(); //genera un immagine su cui lloyd e voronoi lavoreranno Rect bounds = new Rect(0, 0, maxCanvas, maxCanvas); //punti randomici NON QUELLI DA UTILIZZARE List <Vector2> points = CreateRandomPoint(polygonNumber); //genero voronoi e modifico tramite lloyd Voronoi voronoi = new Voronoi(points, bounds, 4); puntiLloyd = voronoi.SitesIndexedByLocation; archiDelGrafo = voronoi.Edges; vtg.GeneraGrafo(archiDelGrafo, maxCanvas); Graph grafoFinale = vtg.GetGraph(); //vtg.MergeNodes(); foreach (Node a in grafoFinale.nodes) { Debug.Log(a.position + "questo e un nodo del grafo dove x =" + a.position.x + " y =" + a.position.y); } Debug.Log(grafoFinale.nodes.Count); DisplayVoronoiDiagram(points, archiDelGrafo);//grafo voronoi poligoni = new LoopFinder(); poligoni.PolyTransform(poligono, exit); Node next = vtg.GetStartingPoint(); do { next = poligoni.FindLoops(next); } while (next != exit); foreach (Arc a in grafoFinale.arcs) { Debug.Log(a.value + "dell'arco che va da " + a.a.position + " a " + a.b.position); } //DisplayVoronoiDiagram(points, vtg.poligoni.arcs);//mio grafo //DisplayVoronoiDiagram(points, archiDelGrafo);//grafo voronoi //tBase.text = archiDelGrafo.ToString()+ ""; }
static void Main() { string line; System.IO.StreamReader file = new System.IO.StreamReader(@"../../challenge_one.txt"); if ((line = file.ReadLine()) != null) { List <int> banks = Regex.Split(line, @"\s+").Select(int.Parse).ToList(); LoopFinder myLoopFinder = new LoopFinder(banks); Tuple <int, int> stepsToInfinite = myLoopFinder.FindInfinite(); Console.WriteLine("Challenge One"); Console.WriteLine(stepsToInfinite.Item1); Console.WriteLine("Challenge Two"); Console.WriteLine(stepsToInfinite.Item2); } file.Close(); }
public void LoopFinder_WhileGoto_TagNodes() { RunTest(new MockWhileGoto()); StringWriter sw = new StringWriter(); proc.Write(sw); Console.WriteLine(sw.ToString()); Assert.AreEqual("LoopHead", proc.Ordering[6].Block.Name); Interval i = proc.DerivedGraphs[0].Intervals[1]; Assert.AreEqual("LoopHead", i.Header.Name); LoopFinder lf = new LoopFinder(proc.Ordering[6], proc.Ordering[2], proc.Ordering); var loopNodes = lf.FindNodesInLoop(i.FindIntervalNodes(0)); Assert.AreEqual(3, loopNodes.Count); }
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); }
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); }