mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(cfg): move block data types to separate file (#6319)
Pure refactor. No logic has been changed.
This commit is contained in:
parent
14275b138e
commit
7672793542
2 changed files with 64 additions and 61 deletions
62
crates/oxc_cfg/src/block.rs
Normal file
62
crates/oxc_cfg/src/block.rs
Normal file
|
|
@ -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,
|
||||
}
|
||||
|
|
@ -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<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
|
||||
|
|
|
|||
Loading…
Reference in a new issue