Struct StructureAnalysis

Source
pub struct StructureAnalysis { /* private fields */ }
Expand description

This module is responsible for control flow analysis.

Implementations§

Source§

impl StructureAnalysis

Source

pub fn new(debug_mode: bool, structure_max_iterations: usize) -> Self

Creates a new StructureAnalysis instance.

Source

pub fn add_region(&mut self, region_type: RegionType) -> RegionId

Adds a new region to the control flow graph.

Source

pub fn connect_regions( &mut self, from: RegionId, to: RegionId, edge_type: ControlFlowEdgeType, ) -> Result<(), StructureAnalysisError>

Connect two regions in the control flow graph.

Source

pub fn get_region( &self, region_id: RegionId, ) -> Result<&Region, StructureAnalysisError>

Gets a region by its ID.

Source

pub fn get_region_mut( &mut self, region_id: RegionId, ) -> Result<&mut Region, StructureAnalysisError>

Gets a mutable region by its ID.

Source

pub fn get_entry_region(&self) -> RegionId

Gets the entry region id

Source

pub fn get_node_index( &self, region_id: RegionId, ) -> Result<NodeIndex, StructureAnalysisError>

Gets the node index of a region.

Source

pub fn get_region_type( &self, region_id: RegionId, ) -> Result<RegionType, StructureAnalysisError>

Gets the region type of a region ID.

Source

pub fn get_branch_opcode( &self, region_id: RegionId, ) -> Result<Option<Opcode>, StructureAnalysisError>

Gets the opcode of a region ID.

Source

pub fn get_region_id( &self, node_index: NodeIndex, ) -> Result<RegionId, StructureAnalysisError>

Gets the region ID of a node index.

Source

pub fn execute(&mut self) -> Result<(), StructureAnalysisError>

Executes the control flow analysis.

Source

pub fn push_to_region<T>(&mut self, region_id: RegionId, node: T)
where T: Into<AstKind>,

Push a node to a region.

Source

pub fn push_unresolved_to_region(&mut self, region_id: RegionId, node: AstKind)

Push an unresolved node to a region.

Source

pub fn get_single_successor( &self, region_id: RegionId, ) -> Result<Option<RegionId>, StructureAnalysisError>

Get the single successor of a region, if there is only one.

§Arguments
  • region_id: The region ID to get the successor of.
§Returns
  • An Option containing the successor node index and region ID if there is only one successor.
Source

pub fn get_single_predecessor( &self, region_id: RegionId, ) -> Result<Option<RegionId>, StructureAnalysisError>

Gets the single predecessor of a region, if there is only one.

§Arguments
  • region_id: The region ID to get the predecessor of.
§Returns
  • An Option containing the predecessor node index and region ID if there is only one predecessor.
Source

pub fn is_cyclic( &self, region_id: RegionId, ) -> Result<bool, StructureAnalysisError>

If a region is cyclic

§Arguments
  • region_id: The region ID to check.
§Returns
  • true if the region is cyclic, false otherwise.
  • Err(StructureAnalysisError) if an error occurred.
Source

pub fn is_back_edge( &self, region: RegionId, successor: RegionId, ) -> Result<bool, StructureAnalysisError>

If a node is a back edge. Basically calls dominates_strictly with the arguments reversed.

§Arguments
  • region: The region ID of the source region.
  • successor: The region ID of the destination region.
§Returns
  • true if the edge is a back edge, false otherwise.
  • Err(StructureAnalysisError) if an error occurred.
Source

pub fn dominates_strictly( &self, dominator: RegionId, dominatee: RegionId, ) -> Result<bool, StructureAnalysisError>

If a node dominates another node.

§Arguments
  • dominator: The region ID of the dominator.
  • dominatee: The region ID of the dominatee.
§Returns
  • true if the dominator dominates the dominatee, false otherwise.
  • Err(StructureAnalysisError) if an error occurred.
Source

pub fn get_single_linear_successor( &self, region_id: RegionId, ) -> Result<Option<RegionId>, StructureAnalysisError>

Get the single linear successor of a region, if the region type is linear.

§Arguments
  • region_id: The region ID to get the successor of.
§Returns
  • An Option containing the successor node index and region ID if there is only one linear successor.
Source

pub fn has_single_predecessor( &self, id: RegionId, ) -> Result<bool, StructureAnalysisError>

Check if a node has a single predecessor.

§Arguments
  • node_index: The node index to check.
§Returns
  • true if the node has a single predecessor, false otherwise.
Source

pub fn remove_edge( &mut self, from_region_id: RegionId, to_region_id: RegionId, ) -> Result<(), StructureAnalysisError>

Remove an edge between two regions.

§Arguments
  • from_region_id: The region ID of the source region.
  • to_region_id: The region ID of the destination region.
§Returns
  • Ok(()) if the operation was successful.
  • Err(StructureAnalysisError) if an error occurred.
Source

pub fn get_successors( &self, region_id: RegionId, ) -> Result<Vec<(RegionId, ControlFlowEdgeType)>, StructureAnalysisError>

Gets the successors of a region as a vector of region IDs.

§Arguments
  • region_id: The region ID to get the successors of.
§Returns
  • A vector of region IDs representing the successors of the region.
Source

pub fn get_predecessors( &self, region_id: RegionId, ) -> Result<Vec<RegionId>, StructureAnalysisError>

Gets the predecessors of a region as a vector of region IDs.

§Arguments
  • region_id: The region ID to get the predecessors of.
§Returns
  • A vector of region IDs representing the predecessors of the region.
Source

pub fn remove_node( &mut self, region_id: RegionId, ) -> Result<(), StructureAnalysisError>

Removes a node from the region graph.

§Arguments
  • region_id: The region ID of the region to remove.
Source

pub fn get_snapshots(&self) -> Result<&Vec<String>, StructureAnalysisError>

Gets the debug snapshots, where each snapshot is a Graphviz representation of the CFG.

Source

pub fn before_reduce(&mut self, region_id: RegionId)

This function should always be called before reducing a region.

Source

pub fn after_reduce(&mut self, region_id: RegionId)

This function should always be called after reducing a region.

Source

pub fn capture_snapshot(&mut self, region_to_highlight: Option<RegionId>)

Capture a snapshot of the CFG.

Source

pub fn capture_region_snapshot(&mut self, region_to_highlight: RegionId)

Capture a snapshot of the CFG.

§Arguments
  • region_to_highlight: The region to highlight in the snapshot (e.g. region being manipulated)

Trait Implementations§

Source§

impl Default for StructureAnalysis

Source§

fn default() -> StructureAnalysis

Returns the “default value” for a type. Read more
Source§

impl DotRenderableGraph for StructureAnalysis

Source§

fn render_dot(&self, config: CfgDotConfig) -> String

Convert the Graph to dot format.

§Returns
  • A String containing the dot representation of the graph.
Source§

impl NodeResolver for StructureAnalysis

Source§

type NodeData = Region

The renderable node type associated with the resolver.
Source§

fn resolve(&self, node_index: NodeIndex) -> Option<&Self::NodeData>

Resolves a NodeIndex to its associated metadata.
Source§

fn resolve_edge_color(&self, n1: NodeIndex, n2: NodeIndex) -> String

Resolves the color of the edge between two nodes.
Source§

fn resolve_border_color(&self, index: NodeIndex) -> Option<String>

Resolves the color of the node’s border, if any.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.