@@ -444,19 +444,23 @@ let expression_or_instructions ctx st in_function =
444444 @ [ List (Atom " else" :: expression iff) ])
445445 ]
446446 | Try (ty , body , catches ) ->
447- [ List
448- (Atom " try"
449- :: (block_type st ty
450- @ List (Atom " do" :: instructions body)
451- :: List. map
452- ~f: (fun (tag , i , ty ) ->
453- List
454- (Atom " catch"
455- :: index st.tag_names tag
456- :: (instruction (Wasm_ast. Event Code_generation. hidden_location)
457- @ instruction (Wasm_ast. Br (i + 1 , Some (Pop ty))))))
458- catches))
459- ]
447+ if Config.Flag. trap_on_exception ()
448+ then [ List (Atom " block" :: (block_type st ty @ instructions body)) ]
449+ else
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
460+ (Wasm_ast. Event Code_generation. hidden_location)
461+ @ instruction (Wasm_ast. Br (i + 1 , Some (Pop ty))))))
462+ catches))
463+ ]
460464 and instruction i =
461465 match i with
462466 | Drop e -> [ List (Atom " drop" :: expression e) ]
@@ -499,8 +503,14 @@ let expression_or_instructions ctx st in_function =
499503 | None -> []
500504 | Some e -> expression e))
501505 ]
502- | Throw (tag , e ) -> [ List (Atom " throw" :: index st.tag_names tag :: expression e) ]
503- | Rethrow i -> [ List [ Atom " rethrow" ; Atom (string_of_int i) ] ]
506+ | Throw (tag , e ) ->
507+ if Config.Flag. trap_on_exception ()
508+ then [ List [ Atom " unreachable" ] ]
509+ else [ List (Atom " throw" :: index st.tag_names tag :: expression e) ]
510+ | Rethrow i ->
511+ if Config.Flag. trap_on_exception ()
512+ then [ List [ Atom " unreachable" ] ]
513+ else [ List [ Atom " rethrow" ; Atom (string_of_int i) ] ]
504514 | CallInstr (f , l ) ->
505515 [ List
506516 (Atom " call"
0 commit comments