From ef56d39c8efa73addb55339c5d77c7070ce9eef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Fri, 17 May 2024 14:42:41 +0200 Subject: [PATCH] Source maps: emit annotations to indicate code with no debug location --- compiler/lib/wasm/wa_generate.ml | 9 ++------- compiler/lib/wasm/wa_wat_output.ml | 3 ++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/lib/wasm/wa_generate.ml b/compiler/lib/wasm/wa_generate.ml index 8eebc789..c860a822 100644 --- a/compiler/lib/wasm/wa_generate.ml +++ b/compiler/lib/wasm/wa_generate.ml @@ -635,13 +635,8 @@ module Generate (Target : Wa_target_sig.S) = struct | (Not | Lt | Le | Eq | Neq | Ult | Array_get | IsInt | Vectlength), _ -> assert false)) - and emit_location loc instrs = - match loc with - | No -> instrs - | Before _ | After _ -> with_location loc instrs - and translate_instr ctx stack_ctx context (i, loc) = - emit_location + with_location loc (match i with | Assign (x, y) -> @@ -877,7 +872,7 @@ module Generate (Target : Wa_target_sig.S) = struct let* () = Stack.perform_reloads stack_ctx (`Branch (fst block.branch)) in let* () = Stack.perform_spilling stack_ctx (`Block pc) in let branch, loc = block.branch in - emit_location + with_location loc (match branch with | Branch cont -> diff --git a/compiler/lib/wasm/wa_wat_output.ml b/compiler/lib/wasm/wa_wat_output.ml index 952213da..39667eae 100644 --- a/compiler/lib/wasm/wa_wat_output.ml +++ b/compiler/lib/wasm/wa_wat_output.ml @@ -574,7 +574,8 @@ let expression_or_instructions ctx st in_function = | Location (loc, i) -> ( let loc = Generate.source_location ctx.debug loc in match loc with - | Javascript.N | U | Pi Parse_info.{ src = None; _ } -> instruction i + | Javascript.N | U | Pi Parse_info.{ src = None; _ } -> + Comment "@" :: instruction i | Pi Parse_info.{ src = Some src; col; line; _ } -> let loc = Format.sprintf "%s:%d:%d" src line col in Comment ("@ " ^ loc) :: instruction i)