-
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cfg): move block data types to separate file (#6319)
Pure refactor. No logic has been changed.
- Loading branch information
Showing
2 changed files
with
64 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters