Skip to content

Commit

Permalink
Update xmldocs, add convenience Add method
Browse files Browse the repository at this point in the history
  • Loading branch information
Washi1337 committed Jul 30, 2024
1 parent 25eb02b commit 06bdf2b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Core/Echo.ControlFlow/Blocks/BasicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public IList<TInstruction> Instructions
/// <inheritdoc />
public BasicBlock<TInstruction> GetLastBlock() => this;

/// <summary>
/// Synchronizes the basic block's offset with the offset of the first instruction.
/// </summary>
/// <param name="architecture">The architecture description of the instructions.</param>
public void UpdateOffset(IArchitecture<TInstruction> architecture)
{
Offset = Header is not null
Expand Down
23 changes: 23 additions & 0 deletions src/Core/Echo.ControlFlow/Collections/NodeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Echo.ControlFlow.Blocks;

namespace Echo.ControlFlow.Collections
{
Expand All @@ -28,6 +29,18 @@ internal NodeCollection(ControlFlowGraph<TInstruction> owner)
/// <inheritdoc />
public bool IsReadOnly => false;

/// <summary>
/// Wraps a basic block into a node and adds it to the graph.
/// </summary>
/// <param name="item">The block.</param>
/// <returns>The created node.</returns>
public ControlFlowNode<TInstruction> Add(BasicBlock<TInstruction> item)
{
var node = new ControlFlowNode<TInstruction>(item);
Add(node);
return node;
}

/// <inheritdoc />
public void Add(ControlFlowNode<TInstruction> item)
{
Expand Down Expand Up @@ -135,11 +148,21 @@ public void UpdateOffsets()
node.UpdateOffset();
}

/// <summary>
/// Constructs a mapping from basic block header offsets to their respective nodes.
/// </summary>
/// <returns>The mapping</returns>
/// <exception cref="ArgumentException">The control flow graph contains nodes with duplicated offsets.</exception>
public IDictionary<long, ControlFlowNode<TInstruction>> CreateOffsetMap()
{
return _nodes.ToDictionary(x => x.Offset, x => x);
}

/// <summary>
/// Finds a node by its basic block header offset.
/// </summary>
/// <param name="offset">The offset.</param>
/// <returns>The node, or <c>null</c> if no node was found with the provided offset.</returns>
public ControlFlowNode<TInstruction>? GetByOffset(long offset) => _nodes.FirstOrDefault(x => x.Contents.Offset == offset);

/// <inheritdoc />
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Echo.ControlFlow/ControlFlowEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public ControlFlowNode<TInstruction> Target
get;
}

/// <summary>
/// Gets or sets user data that is added to the edge.
/// </summary>
public object? UserData
{
get;
set;
}

INode IEdge.Origin => Origin;

INode IEdge.Target => Target;
Expand Down
15 changes: 15 additions & 0 deletions src/Core/Echo.ControlFlow/ControlFlowNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public IControlFlowRegion<TInstruction>? ParentRegion
internal set;
}

/// <summary>
/// Gets the offset of the basic block the node is representing.
/// </summary>
public long Offset => Contents.Offset;

/// <inheritdoc />
Expand All @@ -122,6 +125,15 @@ public BasicBlock<TInstruction> Contents
get;
}

/// <summary>
/// Gets or sets user data that is added to the node.
/// </summary>
public object? UserData
{
get;
set;
}

/// <summary>
/// Gets or sets the neighbour to which the control is transferred to after execution of this block and no
/// other condition is met.
Expand Down Expand Up @@ -245,6 +257,9 @@ public ControlFlowEdge<TInstruction> ConnectWith(ControlFlowNode<TInstruction> n
return edge;
}

/// <summary>
/// Synchronizes the basic block's offset with the offset of the first instruction.
/// </summary>
public void UpdateOffset()
{
if (ParentGraph is not null)
Expand Down

0 comments on commit 06bdf2b

Please sign in to comment.