Skip to content

Commit a8cb2b4

Browse files
committed
Add more opcodes to terminator
1 parent 0348668 commit a8cb2b4

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

boa_engine/src/optimizer/control_flow_graph/basic_block.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ impl BasicBlock {
110110
Terminator::JumpConditional { no, yes, .. } => {
111111
vec![no.clone(), yes.clone()]
112112
}
113+
Terminator::TemplateLookup { no, yes, .. } => {
114+
vec![no.clone(), yes.clone()]
115+
}
113116
Terminator::Return { finally } => {
114117
let mut successors = Vec::new();
115118
if let Some(finally) = finally {
@@ -130,6 +133,10 @@ impl BasicBlock {
130133
nexts.push(no.clone());
131134
nexts.push(yes.clone());
132135
}
136+
Terminator::TemplateLookup { no, yes, .. } => {
137+
nexts.push(no.clone());
138+
nexts.push(yes.clone());
139+
}
133140
Terminator::Return { finally } => {
134141
if let Some(_finally) = finally {
135142
// FIXME: should we include this??

boa_engine/src/optimizer/control_flow_graph/mod.rs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ pub enum Terminator {
4141
yes: RcBasicBlock,
4242
},
4343

44+
/// TODO: doc
45+
TemplateLookup {
46+
/// TODO: doc
47+
no: RcBasicBlock,
48+
49+
/// TODO: doc
50+
yes: RcBasicBlock,
51+
52+
/// TODO: doc
53+
site: u64,
54+
},
55+
4456
/// TODO: doc
4557
Return {
4658
/// Finally block that the return should jump to, if exists.
@@ -152,6 +164,14 @@ impl Debug for ControlFlowGraph {
152164
let target = index_from_basic_block(yes);
153165
write!(f, "{} B{target}", opcode.as_str())?;
154166
}
167+
Terminator::TemplateLookup {
168+
no: _,
169+
yes,
170+
site: _,
171+
} => {
172+
let target = index_from_basic_block(yes);
173+
write!(f, "TemplateLookup B{target}")?;
174+
}
155175
Terminator::Return { finally } => {
156176
write!(f, "Return")?;
157177
if let Some(finally) = finally {
@@ -182,6 +202,12 @@ const fn is_jump_kind_opcode(opcode: Opcode) -> bool {
182202
| Opcode::JumpIfNullOrUndefined
183203
| Opcode::Case
184204
| Opcode::Default
205+
| Opcode::LogicalAnd
206+
| Opcode::LogicalOr
207+
| Opcode::Coalesce
208+
| Opcode::Break
209+
| Opcode::BreakLabel
210+
| Opcode::Continue
185211
)
186212
}
187213

@@ -214,6 +240,10 @@ impl ControlFlowGraph {
214240
let exit = result.read::<u32>(0);
215241
leaders.push(exit);
216242
}
243+
Opcode::TemplateLookup => {
244+
let exit = result.read::<u32>(0);
245+
leaders.push(exit);
246+
}
217247
opcode if is_jump_kind_opcode(opcode) => {
218248
let target = result.read::<u32>(0);
219249

@@ -300,6 +330,23 @@ impl ControlFlowGraph {
300330

301331
false
302332
}
333+
Opcode::TemplateLookup => {
334+
let address = result.read::<u32>(0);
335+
let site = result.read::<u64>(4);
336+
let yes = basic_block_from_bytecode_position(address);
337+
let no = basic_blocks[i + 1].clone();
338+
339+
yes.borrow_mut()
340+
.predecessors
341+
.push(basic_blocks[i].downgrade());
342+
no.borrow_mut()
343+
.predecessors
344+
.push(basic_blocks[i].downgrade());
345+
346+
terminator = Terminator::TemplateLookup { no, yes, site };
347+
348+
false
349+
}
303350
opcode if is_jump_kind_opcode(opcode) => {
304351
let address = result.read::<u32>(0);
305352
let yes = basic_block_from_bytecode_position(address);
@@ -308,7 +355,9 @@ impl ControlFlowGraph {
308355
yes.borrow_mut()
309356
.predecessors
310357
.push(basic_blocks[i].downgrade());
311-
yes.borrow_mut().predecessors.push(no.downgrade());
358+
no.borrow_mut()
359+
.predecessors
360+
.push(basic_blocks[i].downgrade());
312361

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

@@ -410,6 +459,15 @@ impl ControlFlowGraph {
410459
let target = index_from_basic_block(yes);
411460
labels.push((start as u32, target));
412461
}
462+
Terminator::TemplateLookup { yes, site, .. } => {
463+
results.extend_from_slice(&[Opcode::TemplateLookup as u8]);
464+
let start = results.len();
465+
results.extend_from_slice(&[0, 0, 0, 0]);
466+
results.extend_from_slice(&site.to_ne_bytes());
467+
468+
let target = index_from_basic_block(yes);
469+
labels.push((start as u32, target));
470+
}
413471
Terminator::Return { .. } => {
414472
results.push(Opcode::Return as u8);
415473
}

boa_engine/src/vm/opcode/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ generate_impl! {
11681168

11691169
/// Start of a finally block.
11701170
///
1171-
/// Operands:
1171+
/// Operands: finally_end_address: u32
11721172
///
11731173
/// Stack: **=>**
11741174
FinallyStart,

0 commit comments

Comments
 (0)