Skip to content

Commit

Permalink
refactor(cfg): move block data types to separate file (#6319)
Browse files Browse the repository at this point in the history
Pure refactor. No logic has been changed.
  • Loading branch information
DonIsaac committed Oct 7, 2024
1 parent 14275b1 commit 7672793
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 61 deletions.
62 changes: 62 additions & 0 deletions crates/oxc_cfg/src/block.rs
Original file line number Diff line number Diff line change
@@ -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<Instruction>,
pub unreachable: bool,
}

impl BasicBlock {
pub(crate) fn new() -> Self {
BasicBlock { instructions: Vec::new(), unreachable: false }
}

pub fn instructions(&self) -> &Vec<Instruction> {
&self.instructions
}
}

#[derive(Debug, Clone)]
pub struct Instruction {
pub kind: InstructionKind,
pub node_id: Option<NodeId>,
}

impl Instruction {
pub fn new(kind: InstructionKind, node_id: Option<NodeId>) -> 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,
}
63 changes: 2 additions & 61 deletions crates/oxc_cfg/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand All @@ -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<Instruction>,
pub unreachable: bool,
}

impl BasicBlock {
fn new() -> Self {
BasicBlock { instructions: Vec::new(), unreachable: false }
}

pub fn instructions(&self) -> &Vec<Instruction> {
&self.instructions
}
}

#[derive(Debug, Clone)]
pub struct Instruction {
pub kind: InstructionKind,
pub node_id: Option<NodeId>,
}

impl Instruction {
pub fn new(kind: InstructionKind, node_id: Option<NodeId>) -> 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
Expand Down

0 comments on commit 7672793

Please sign in to comment.