@@ -447,19 +447,23 @@ let expression_or_instructions ctx st in_function =
447447 @ [ List (Atom " else" :: expression iff) ])
448448 ]
449449 | Try (ty , body , catches ) ->
450- [ List
451- (Atom " try"
452- :: (block_type st ty
453- @ List (Atom " do" :: instructions body)
454- :: List. map
455- ~f: (fun (tag , i , ty ) ->
456- List
457- (Atom " catch"
458- :: index st.tag_names tag
459- :: (instruction (Wasm_ast. Event Code_generation. hidden_location)
460- @ instruction (Wasm_ast. Br (i + 1 , Some (Pop ty))))))
461- catches))
462- ]
450+ if Config.Flag. trap_on_exception ()
451+ then [ List (Atom " block" :: (block_type st ty @ instructions body)) ]
452+ else
453+ [ List
454+ (Atom " try"
455+ :: (block_type st ty
456+ @ List (Atom " do" :: instructions body)
457+ :: List. map
458+ ~f: (fun (tag , i , ty ) ->
459+ List
460+ (Atom " catch"
461+ :: index st.tag_names tag
462+ :: (instruction
463+ (Wasm_ast. Event Code_generation. hidden_location)
464+ @ instruction (Wasm_ast. Br (i + 1 , Some (Pop ty))))))
465+ catches))
466+ ]
463467 | ExternConvertAny e' -> [ List (Atom " extern.convert_any" :: expression e') ]
464468 and instruction i =
465469 match i with
@@ -503,8 +507,14 @@ let expression_or_instructions ctx st in_function =
503507 | None -> []
504508 | Some e -> expression e))
505509 ]
506- | Throw (tag , e ) -> [ List (Atom " throw" :: index st.tag_names tag :: expression e) ]
507- | Rethrow i -> [ List [ Atom " rethrow" ; Atom (string_of_int i) ] ]
510+ | Throw (tag , e ) ->
511+ if Config.Flag. trap_on_exception ()
512+ then [ List [ Atom " unreachable" ] ]
513+ else [ List (Atom " throw" :: index st.tag_names tag :: expression e) ]
514+ | Rethrow i ->
515+ if Config.Flag. trap_on_exception ()
516+ then [ List [ Atom " unreachable" ] ]
517+ else [ List [ Atom " rethrow" ; Atom (string_of_int i) ] ]
508518 | CallInstr (f , l ) ->
509519 [ List
510520 (Atom " call"
0 commit comments