public void BuildProcedureStructure() { var cfgs = new ProcedureStructureBuilder(proc); ProcedureStructure = cfgs.Build(); cfgs.AnalyzeGraph(); }
public ProcedureStructure Build() { BuildNodes(); DefineEdges(); curProc = CreateProcedureStructure(); SetTimeStamps(); BuildDerivedSequences(curProc); return(curProc); }
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); } }
public ProcedureStructure CreateProcedureStructure() { List <StructureNode> nodes = new List <StructureNode>(); foreach (StructureNode node in blockNodes.Values) { nodes.Add(node); } var newProc = new ProcedureStructure(proc.Name, nodes); newProc.EntryNode = blockNodes[proc.EntryBlock]; newProc.ExitNode = blockNodes[proc.ExitBlock]; this.curProc = newProc; return(newProc); }
public DerivedSequenceBuilder(ProcedureStructure proc) { this.graphs = proc.DerivedGraphs; this.ib = new IntervalBuilder(); var gr = BuildDerivedGraph(proc.Nodes, proc.EntryNode); graphs.Add(gr); while (gr.Graph.Nodes.Count > 1) { DerivedGraph newGr = BuildNextOrderGraph(gr); if (newGr.Graph.Nodes.Count == gr.Graph.Nodes.Count) { return; } graphs.Add(newGr); gr = newGr; } }
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); } } } }
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); }
// Build the sequence of derived graphs for each procedure public void BuildDerivedSequences(ProcedureStructure curProc) { DerivedSequenceBuilder d = new DerivedSequenceBuilder(curProc); }
public UnstructuredConditionalAnalysis(ProcedureStructure curProc) { this.curProc = curProc; }