oxc_cfg/
block.rs

1use oxc_syntax::node::NodeId;
2
3#[derive(Debug, Clone)]
4pub struct BasicBlock {
5    pub instructions: Vec<Instruction>,
6    unreachable: bool,
7}
8
9impl BasicBlock {
10    pub(crate) fn new() -> Self {
11        BasicBlock { instructions: Vec::new(), unreachable: false }
12    }
13
14    pub fn instructions(&self) -> &Vec<Instruction> {
15        &self.instructions
16    }
17
18    #[inline]
19    pub fn is_unreachable(&self) -> bool {
20        self.unreachable
21    }
22
23    #[inline]
24    pub fn mark_as_unreachable(&mut self) {
25        self.unreachable = true;
26    }
27
28    #[inline]
29    pub fn mark_as_reachable(&mut self) {
30        self.unreachable = false;
31    }
32}
33
34#[derive(Debug, Clone)]
35pub struct Instruction {
36    pub kind: InstructionKind,
37    pub node_id: Option<NodeId>,
38}
39
40impl Instruction {
41    pub fn new(kind: InstructionKind, node_id: Option<NodeId>) -> Self {
42        Self { kind, node_id }
43    }
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub enum InstructionKind {
48    Unreachable,
49    Statement,
50    ImplicitReturn,
51    Return(ReturnInstructionKind),
52    Break(LabeledInstruction),
53    Continue(LabeledInstruction),
54    Throw,
55    Condition,
56    Iteration(IterationInstructionKind),
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq)]
60pub enum ReturnInstructionKind {
61    ImplicitUndefined,
62    NotImplicitUndefined,
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub enum LabeledInstruction {
67    Labeled,
68    Unlabeled,
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72pub enum IterationInstructionKind {
73    Of,
74    In,
75}