@@ -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 }
0 commit comments