Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cfg): move block data types to separate file #6319

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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