@@ -32,10 +32,12 @@ module State : sig
32
32
33
33
val get_next_instruction_id : t -> int
34
34
35
- val add_iend_with_poptrap : t -> Mach .instruction -> unit
35
+ val add_iend_with_poptrap : t -> Mach .instruction -> Label .t -> unit
36
36
37
37
val is_iend_with_poptrap : t -> Mach .instruction -> bool
38
38
39
+ val get_iend_with_poptrap : t -> Mach .instruction -> Label .t option
40
+
39
41
val add_exception_handler : t -> Label .t -> unit
40
42
41
43
val get_exception_handlers : t -> Label .t list
@@ -48,7 +50,7 @@ end = struct
48
50
layout : Cfg_with_layout .layout ;
49
51
catch_handlers : Label .t Numbers.Int.Tbl .t ;
50
52
mutable next_instruction_id : int ;
51
- mutable iends_with_poptrap : Mach .instruction list ;
53
+ mutable iends_with_poptrap : ( Mach .instruction * Label .t ) list ;
52
54
mutable exception_handlers : Label .t list
53
55
}
54
56
@@ -115,13 +117,17 @@ end = struct
115
117
| Itrywith _ | Iraise _ ->
116
118
false
117
119
118
- let add_iend_with_poptrap t iend =
120
+ let add_iend_with_poptrap t iend pop_action =
119
121
assert (is_iend iend);
120
- t.iends_with_poptrap < - iend :: t.iends_with_poptrap
122
+ t.iends_with_poptrap < - ( iend, pop_action) :: t.iends_with_poptrap
121
123
122
124
let is_iend_with_poptrap t iend =
123
125
assert (is_iend iend);
124
- List. memq iend t.iends_with_poptrap
126
+ List. mem_assq iend t.iends_with_poptrap
127
+
128
+ let get_iend_with_poptrap t iend =
129
+ assert (is_iend iend);
130
+ List. assq_opt iend t.iends_with_poptrap
125
131
126
132
let add_exception_handler t lbl =
127
133
t.exception_handlers < - lbl :: t.exception_handlers
@@ -558,9 +564,9 @@ let rec add_blocks :
558
564
else
559
565
terminate_block
560
566
~trap_actions:
561
- (if State. is_iend_with_poptrap state last
562
- then [Cmm. Pop Pop_generic ]
563
- else [] )
567
+ (match State. get_iend_with_poptrap state last with
568
+ | Some _lbl_handler -> [Cmm. Pop Pop_generic ]
569
+ | None -> [] )
564
570
(copy_instruction_no_reg state last ~desc: (Cfg. Always next))
565
571
| Ireturn trap_actions ->
566
572
terminate_block ~trap_actions
@@ -628,7 +634,7 @@ let rec add_blocks :
628
634
terminate_block ~trap_actions: []
629
635
(copy_instruction_no_reg state last ~desc: (Cfg. Always label_body));
630
636
let next, add_next_block = prepare_next_block () in
631
- State. add_iend_with_poptrap state (get_end body);
637
+ State. add_iend_with_poptrap state (get_end body) label_handler ;
632
638
State. add_exception_handler state label_handler;
633
639
add_blocks body state ~starts_with_pushtrap ~start: label_body ~next
634
640
~is_cold ;
0 commit comments