Skip to content

Commit f572038

Browse files
committed
Merge Terminator Jump types
1 parent 1b91bc3 commit f572038

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

boa_engine/src/optimizer/control_flow_graph.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,14 @@ pub enum Terminator {
445445
/// TODO: doc
446446
None,
447447
/// TODO: doc
448-
JumpUnconditional(u32),
449-
/// TODO: doc
450-
JumpConditional(Opcode, u32),
448+
Jump(Opcode, u32),
451449
}
452450

453451
impl Debug for Terminator {
454452
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
455453
match self {
456454
Terminator::None => write!(f, "None"),
457-
Terminator::JumpUnconditional(target) => write!(f, "Jump B{target}"),
458-
Terminator::JumpConditional(opcode, target) => {
455+
Terminator::Jump(opcode, target) => {
459456
write!(f, "{} B{target}", opcode.as_str())
460457
}
461458
}
@@ -467,6 +464,21 @@ impl Terminator {
467464
pub fn is_none(&self) -> bool {
468465
matches!(self, Terminator::None)
469466
}
467+
468+
/// Check if [`Terminator::Jump`].
469+
pub fn is_jump(&self) -> bool {
470+
matches!(self, Terminator::Jump(_, _))
471+
}
472+
473+
/// Check if unconditional [`Terminator::Jump`].
474+
pub fn is_unconditional_jump(&self) -> bool {
475+
matches!(self, Terminator::Jump(Opcode::Jump, _))
476+
}
477+
478+
/// Check if conditional [`Terminator::Jump`].
479+
pub fn is_conditional_jump(&self) -> bool {
480+
matches!(self, Terminator::Jump(opcode, _) if *opcode != Opcode::Jump)
481+
}
470482
}
471483

472484
/// TODO: doc
@@ -633,15 +645,15 @@ impl ControlFlowGraph {
633645
basic_block.terminator = if result.opcode == Opcode::Jump {
634646
references[*index as usize].push(i as u32);
635647

636-
Terminator::JumpUnconditional(*index)
648+
Terminator::Jump(Opcode::Jump, *index)
637649
} else {
638650
references[*index as usize].push(i as u32);
639651

640652
if i + 1 != references.len() {
641653
references[*index as usize].push(i as u32 + 1);
642654
}
643655

644-
Terminator::JumpConditional(result.opcode, *index)
656+
Terminator::Jump(result.opcode, *index)
645657
};
646658

647659
basic_block.bytecode.truncate(len - 5);
@@ -712,13 +724,7 @@ impl ControlFlowGraph {
712724
results.extend(basic_block.bytecode);
713725
match basic_block.terminator {
714726
Terminator::None => {}
715-
Terminator::JumpUnconditional(target) => {
716-
results.extend_from_slice(&[Opcode::Jump as u8]);
717-
let start = results.len();
718-
results.extend_from_slice(&[0, 0, 0, 0]);
719-
labels.push((start as u32, target));
720-
}
721-
Terminator::JumpConditional(opcode, target) => {
727+
Terminator::Jump(opcode, target) => {
722728
results.extend_from_slice(&[opcode as u8]);
723729
let start = results.len();
724730
results.extend_from_slice(&[0, 0, 0, 0]);

0 commit comments

Comments
 (0)