Skip to content

Commit

Permalink
Simplify adjust_trap_depth "by the magic of recursion"
Browse files Browse the repository at this point in the history
  • Loading branch information
gretay-js committed Jun 24, 2019
1 parent 87aadc8 commit 26a4a21
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions asmcomp/linearize.ml
Expand Up @@ -128,16 +128,15 @@ let check_label n = match n.desc with
of differences in exception trap depths.
The argument delta is the number of trap frames (not bytes). *)

let adjust_trap_depth delta_traps next =
let rec adjust_trap_depth delta_traps next =
(* Simplify by merging and eliminating Ladjust_trap_depth instructions
whenever possible. *)
let delta_traps, next =
match next.desc with
| Ladjust_trap_depth { delta_traps = k } -> delta_traps + k, next.next
| _ -> delta_traps, next
in
if delta_traps = 0 then next
else cons_instr (Ladjust_trap_depth { delta_traps }) next
match next.desc with
| Ladjust_trap_depth { delta_traps = k } ->
adjust_trap_depth (delta_traps + k) next.next
| _ ->
if delta_traps = 0 then next
else cons_instr (Ladjust_trap_depth { delta_traps }) next

(* Discard all instructions up to the next label.
This function is to be called before adding a non-terminating
Expand Down

0 comments on commit 26a4a21

Please sign in to comment.