Skip to content

Commit

Permalink
Add more opcodes to terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jun 18, 2023
1 parent 0348668 commit a8cb2b4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
7 changes: 7 additions & 0 deletions boa_engine/src/optimizer/control_flow_graph/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ impl BasicBlock {
Terminator::JumpConditional { no, yes, .. } => {
vec![no.clone(), yes.clone()]
}
Terminator::TemplateLookup { no, yes, .. } => {
vec![no.clone(), yes.clone()]
}
Terminator::Return { finally } => {
let mut successors = Vec::new();
if let Some(finally) = finally {
Expand All @@ -130,6 +133,10 @@ impl BasicBlock {
nexts.push(no.clone());
nexts.push(yes.clone());
}
Terminator::TemplateLookup { no, yes, .. } => {
nexts.push(no.clone());
nexts.push(yes.clone());
}
Terminator::Return { finally } => {
if let Some(_finally) = finally {
// FIXME: should we include this??
Expand Down
60 changes: 59 additions & 1 deletion boa_engine/src/optimizer/control_flow_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ pub enum Terminator {
yes: RcBasicBlock,
},

/// TODO: doc
TemplateLookup {
/// TODO: doc
no: RcBasicBlock,

/// TODO: doc
yes: RcBasicBlock,

/// TODO: doc
site: u64,
},

/// TODO: doc
Return {
/// Finally block that the return should jump to, if exists.
Expand Down Expand Up @@ -152,6 +164,14 @@ impl Debug for ControlFlowGraph {
let target = index_from_basic_block(yes);
write!(f, "{} B{target}", opcode.as_str())?;
}
Terminator::TemplateLookup {
no: _,
yes,
site: _,
} => {
let target = index_from_basic_block(yes);
write!(f, "TemplateLookup B{target}")?;
}
Terminator::Return { finally } => {
write!(f, "Return")?;
if let Some(finally) = finally {
Expand Down Expand Up @@ -182,6 +202,12 @@ const fn is_jump_kind_opcode(opcode: Opcode) -> bool {
| Opcode::JumpIfNullOrUndefined
| Opcode::Case
| Opcode::Default
| Opcode::LogicalAnd
| Opcode::LogicalOr
| Opcode::Coalesce
| Opcode::Break
| Opcode::BreakLabel
| Opcode::Continue
)
}

Expand Down Expand Up @@ -214,6 +240,10 @@ impl ControlFlowGraph {
let exit = result.read::<u32>(0);
leaders.push(exit);
}
Opcode::TemplateLookup => {
let exit = result.read::<u32>(0);
leaders.push(exit);
}
opcode if is_jump_kind_opcode(opcode) => {
let target = result.read::<u32>(0);

Expand Down Expand Up @@ -300,6 +330,23 @@ impl ControlFlowGraph {

false
}
Opcode::TemplateLookup => {
let address = result.read::<u32>(0);
let site = result.read::<u64>(4);
let yes = basic_block_from_bytecode_position(address);
let no = basic_blocks[i + 1].clone();

yes.borrow_mut()
.predecessors
.push(basic_blocks[i].downgrade());
no.borrow_mut()
.predecessors
.push(basic_blocks[i].downgrade());

terminator = Terminator::TemplateLookup { no, yes, site };

false
}
opcode if is_jump_kind_opcode(opcode) => {
let address = result.read::<u32>(0);
let yes = basic_block_from_bytecode_position(address);
Expand All @@ -308,7 +355,9 @@ impl ControlFlowGraph {
yes.borrow_mut()
.predecessors
.push(basic_blocks[i].downgrade());
yes.borrow_mut().predecessors.push(no.downgrade());
no.borrow_mut()
.predecessors
.push(basic_blocks[i].downgrade());

terminator = Terminator::JumpConditional { opcode, no, yes };

Expand Down Expand Up @@ -410,6 +459,15 @@ impl ControlFlowGraph {
let target = index_from_basic_block(yes);
labels.push((start as u32, target));
}
Terminator::TemplateLookup { yes, site, .. } => {
results.extend_from_slice(&[Opcode::TemplateLookup as u8]);
let start = results.len();
results.extend_from_slice(&[0, 0, 0, 0]);
results.extend_from_slice(&site.to_ne_bytes());

let target = index_from_basic_block(yes);
labels.push((start as u32, target));
}
Terminator::Return { .. } => {
results.push(Opcode::Return as u8);
}
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ generate_impl! {

/// Start of a finally block.
///
/// Operands:
/// Operands: finally_end_address: u32
///
/// Stack: **=>**
FinallyStart,
Expand Down

0 comments on commit a8cb2b4

Please sign in to comment.