@@ -18,6 +18,7 @@ use self::{
18
18
ControlFrameBase ,
19
19
ControlFrameKind ,
20
20
ElseControlFrame ,
21
+ ElseReachability ,
21
22
IfControlFrame ,
22
23
IfReachability ,
23
24
LocalIdx ,
@@ -482,6 +483,34 @@ impl FuncTranslator {
482
483
Ok ( ( ) )
483
484
}
484
485
486
+ /// Translates the end of a Wasm `else` control frame.
487
+ fn translate_end_else ( & mut self , frame : ElseControlFrame ) -> Result < ( ) , Error > {
488
+ debug_assert ! ( !self . stack. is_control_empty( ) ) ;
489
+ let reachability = frame. reachability ( ) ;
490
+ if matches ! (
491
+ reachability,
492
+ ElseReachability :: OnlyThen | ElseReachability :: OnlyElse
493
+ ) {
494
+ return self . translate_end_if_or_else_only ( frame, reachability) ;
495
+ }
496
+ let end_of_then_reachable = frame. is_end_of_then_reachable ( ) ;
497
+ let end_of_else_reachable = self . reachable ;
498
+ let reachable = match ( end_of_then_reachable, end_of_else_reachable) {
499
+ ( false , false ) => frame. is_branched_to ( ) ,
500
+ _ => true ,
501
+ } ;
502
+ if end_of_else_reachable {
503
+ let len_values = frame. len_branch_params ( & self . engine ) ;
504
+ let consume_fuel_instr: Option < Instr > = frame. consume_fuel_instr ( ) ;
505
+ self . copy_branch_params ( usize:: from ( len_values) , consume_fuel_instr) ?;
506
+ }
507
+ self . labels
508
+ . pin_label ( frame. label ( ) , self . instrs . next_instr ( ) )
509
+ . unwrap ( ) ;
510
+ self . reachable = reachable;
511
+ Ok ( ( ) )
512
+ }
513
+
485
514
/// Translates the end of a Wasm `else` control frame where only one branch is known to be reachable.
486
515
fn translate_end_if_or_else_only (
487
516
& mut self ,
@@ -505,12 +534,6 @@ impl FuncTranslator {
505
534
Ok ( ( ) )
506
535
}
507
536
508
- /// Translates the end of a Wasm `else` control frame.
509
- fn translate_end_else ( & mut self , _frame : ElseControlFrame ) -> Result < ( ) , Error > {
510
- debug_assert ! ( !self . stack. is_control_empty( ) ) ;
511
- todo ! ( )
512
- }
513
-
514
537
/// Translates the end of an unreachable Wasm control frame.
515
538
fn translate_end_unreachable ( & mut self , _frame : ControlFrameKind ) -> Result < ( ) , Error > {
516
539
debug_assert ! ( !self . stack. is_control_empty( ) ) ;
0 commit comments