using Dna.Extensions; using Rivers; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Dna.ControlFlow { public class ControlFlowGraph : Graph { public ulong StartAddress { get; } public ControlFlowGraph(ulong startAddress) { Name = startAddress.ToString("X"); StartAddress = startAddress; } /// /// Creates a new basic block and adds it to the control flow graph. /// /// /// public BasicBlock CreateBlock(ulong address) { var block = new BasicBlock(address); block.Address = address; block.UserData.Add(block.Address.ToString("X"), block); Nodes.Add(block); return block; } public IEnumerable> GetBlocks() { return Nodes.Select(x => x.GetBlock()); } public IEnumerable GetInstructions() { return Nodes.SelectMany(x => x.GetBlock().Instructions); } public bool WhileEachBlockInReversePostOrder(BasicBlock block, Func, bool> func) { return false; } public override string ToString() { return GraphFormatter.FormatGraph(this); } } }