mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(cfg): add type alias for Graph (#6322)
Pure refactor. No logic changes
This commit is contained in:
parent
95ca01ccc1
commit
a1e0d30f20
2 changed files with 7 additions and 8 deletions
|
|
@ -16,7 +16,7 @@ struct ErrorHarness(ErrorEdgeKind, BasicBlockId);
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct ControlFlowGraphBuilder<'a> {
|
pub struct ControlFlowGraphBuilder<'a> {
|
||||||
pub graph: Graph<usize, EdgeType>,
|
pub graph: Graph,
|
||||||
pub basic_blocks: Vec<BasicBlock>,
|
pub basic_blocks: Vec<BasicBlock>,
|
||||||
pub current_node_ix: BasicBlockId,
|
pub current_node_ix: BasicBlockId,
|
||||||
ctx_stack: Vec<Ctx<'a>>,
|
ctx_stack: Vec<Ctx<'a>>,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ pub mod visit;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use petgraph::{
|
use petgraph::{
|
||||||
visit::{Control, DfsEvent, EdgeRef},
|
visit::{Control, DfsEvent, EdgeRef},
|
||||||
Direction, Graph,
|
Direction,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod graph {
|
pub mod graph {
|
||||||
|
|
@ -23,6 +23,8 @@ pub use builder::{ControlFlowGraphBuilder, CtxCursor, CtxFlags};
|
||||||
pub use dot::DisplayDot;
|
pub use dot::DisplayDot;
|
||||||
use visit::set_depth_first_search;
|
use visit::set_depth_first_search;
|
||||||
|
|
||||||
|
pub type Graph = petgraph::graph::DiGraph<usize, EdgeType>;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum EdgeType {
|
pub enum EdgeType {
|
||||||
/// Conditional jumps
|
/// Conditional jumps
|
||||||
|
|
@ -62,12 +64,12 @@ pub enum EvalConstConditionResult {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ControlFlowGraph {
|
pub struct ControlFlowGraph {
|
||||||
pub graph: Graph<usize, EdgeType>,
|
pub graph: Graph,
|
||||||
pub basic_blocks: Vec<BasicBlock>,
|
pub basic_blocks: Vec<BasicBlock>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ControlFlowGraph {
|
impl ControlFlowGraph {
|
||||||
pub fn graph(&self) -> &Graph<usize, EdgeType> {
|
pub fn graph(&self) -> &Graph {
|
||||||
&self.graph
|
&self.graph
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,10 +133,7 @@ impl ControlFlowGraph {
|
||||||
where
|
where
|
||||||
F: Fn(&Instruction) -> EvalConstConditionResult,
|
F: Fn(&Instruction) -> EvalConstConditionResult,
|
||||||
{
|
{
|
||||||
fn get_jump_target(
|
fn get_jump_target(graph: &Graph, node: BasicBlockId) -> Option<BasicBlockId> {
|
||||||
graph: &Graph<usize, EdgeType>,
|
|
||||||
node: BasicBlockId,
|
|
||||||
) -> Option<BasicBlockId> {
|
|
||||||
graph
|
graph
|
||||||
.edges_directed(node, Direction::Outgoing)
|
.edges_directed(node, Direction::Outgoing)
|
||||||
.find_or_first(|e| matches!(e.weight(), EdgeType::Jump))
|
.find_or_first(|e| matches!(e.weight(), EdgeType::Jump))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue