From 7672793542220f6839dd8a37cf87b505f36a9637 Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Mon, 7 Oct 2024 05:01:06 +0000 Subject: [PATCH] refactor(cfg): move block data types to separate file (#6319) Pure refactor. No logic has been changed. --- crates/oxc_cfg/src/block.rs | 62 ++++++++++++++++++++++++++++++++++++ crates/oxc_cfg/src/lib.rs | 63 ++----------------------------------- 2 files changed, 64 insertions(+), 61 deletions(-) create mode 100644 crates/oxc_cfg/src/block.rs diff --git a/crates/oxc_cfg/src/block.rs b/crates/oxc_cfg/src/block.rs new file mode 100644 index 0000000000000..2f2ae7137da49 --- /dev/null +++ b/crates/oxc_cfg/src/block.rs @@ -0,0 +1,62 @@ +use oxc_syntax::node::NodeId; +use petgraph::stable_graph::NodeIndex; + +pub type BasicBlockId = NodeIndex; + +#[derive(Debug)] +pub struct BasicBlock { + pub instructions: Vec, + pub unreachable: bool, +} + +impl BasicBlock { + pub(crate) fn new() -> Self { + BasicBlock { instructions: Vec::new(), unreachable: false } + } + + pub fn instructions(&self) -> &Vec { + &self.instructions + } +} + +#[derive(Debug, Clone)] +pub struct Instruction { + pub kind: InstructionKind, + pub node_id: Option, +} + +impl Instruction { + pub fn new(kind: InstructionKind, node_id: Option) -> Self { + Self { kind, node_id } + } +} + +#[derive(Debug, Clone)] +pub enum InstructionKind { + Unreachable, + Statement, + Return(ReturnInstructionKind), + Break(LabeledInstruction), + Continue(LabeledInstruction), + Throw, + Condition, + Iteration(IterationInstructionKind), +} + +#[derive(Debug, Clone)] +pub enum ReturnInstructionKind { + ImplicitUndefined, + NotImplicitUndefined, +} + +#[derive(Debug, Clone)] +pub enum LabeledInstruction { + Labeled, + Unlabeled, +} + +#[derive(Debug, Clone)] +pub enum IterationInstructionKind { + Of, + In, +} diff --git a/crates/oxc_cfg/src/lib.rs b/crates/oxc_cfg/src/lib.rs index 892366b1200c7..275b2cc2e41be 100644 --- a/crates/oxc_cfg/src/lib.rs +++ b/crates/oxc_cfg/src/lib.rs @@ -1,11 +1,10 @@ +mod block; mod builder; pub mod dot; pub mod visit; use itertools::Itertools; -use oxc_syntax::node::NodeId; use petgraph::{ - stable_graph::NodeIndex, visit::{Control, DfsEvent, EdgeRef}, Direction, Graph, }; @@ -19,69 +18,11 @@ pub mod graph { } } +pub use block::*; pub use builder::{ControlFlowGraphBuilder, CtxCursor, CtxFlags}; pub use dot::DisplayDot; use visit::set_depth_first_search; -pub type BasicBlockId = NodeIndex; - -#[derive(Debug)] -pub struct BasicBlock { - pub instructions: Vec, - pub unreachable: bool, -} - -impl BasicBlock { - fn new() -> Self { - BasicBlock { instructions: Vec::new(), unreachable: false } - } - - pub fn instructions(&self) -> &Vec { - &self.instructions - } -} - -#[derive(Debug, Clone)] -pub struct Instruction { - pub kind: InstructionKind, - pub node_id: Option, -} - -impl Instruction { - pub fn new(kind: InstructionKind, node_id: Option) -> Self { - Self { kind, node_id } - } -} - -#[derive(Debug, Clone)] -pub enum InstructionKind { - Unreachable, - Statement, - Return(ReturnInstructionKind), - Break(LabeledInstruction), - Continue(LabeledInstruction), - Throw, - Condition, - Iteration(IterationInstructionKind), -} -#[derive(Debug, Clone)] -pub enum ReturnInstructionKind { - ImplicitUndefined, - NotImplicitUndefined, -} - -#[derive(Debug, Clone)] -pub enum LabeledInstruction { - Labeled, - Unlabeled, -} - -#[derive(Debug, Clone)] -pub enum IterationInstructionKind { - Of, - In, -} - #[derive(Debug, Clone)] pub enum EdgeType { /// Conditional jumps