From 99943610cbef38f25c7589329b5ef5b5532e5cc9 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Wed, 11 Sep 2024 07:46:17 +0300 Subject: [PATCH] * WebAssembly: generate the final bashB opcode of a function via the end_function instruction, instead of adding it magically in the object writer. This makes the WebAssembly debug line info more accurate, covering the end_function instruction as well. --- compiler/ogwasm.pas | 3 +-- compiler/wasm32/aasmcpu.pas | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas index 23c5595854..8301097ba7 100644 --- a/compiler/ogwasm.pas +++ b/compiler/ogwasm.pas @@ -1322,14 +1322,13 @@ implementation encoded_locals:=tdynamicarray.Create(64); WriteFunctionLocals(encoded_locals,ObjSymExtraData); - codelen:=encoded_locals.size+codeexprlen+1; + codelen:=encoded_locals.size+codeexprlen; WriteUleb(dest,codelen); encoded_locals.seek(0); CopyDynamicArray(encoded_locals,dest,encoded_locals.size); ObjSection.FileSectionOfs:=dest.size-objsym.offset; ObjSection.EncodedLocalsSize:=encoded_locals.size; CopyDynamicArray(ObjSection.Data,dest,codeexprlen); - WriteByte(dest,$0B); encoded_locals.Free; end; diff --git a/compiler/wasm32/aasmcpu.pas b/compiler/wasm32/aasmcpu.pas index 871090c73d..93f2c9c8bc 100644 --- a/compiler/wasm32/aasmcpu.pas +++ b/compiler/wasm32/aasmcpu.pas @@ -2236,6 +2236,7 @@ uses a_end_if, a_end_loop, a_end_try, + a_end_function, a_catch_all, a_ref_is_null: result:=1; @@ -2350,8 +2351,6 @@ uses internalerror(2021092011); end; end; - a_end_function: - result:=0; a_block, a_loop, a_if, @@ -2993,7 +2992,8 @@ uses a_end_block, a_end_if, a_end_loop, - a_end_try: + a_end_try, + a_end_function: WriteByte($0B); a_catch_all: WriteByte($19); @@ -3132,8 +3132,6 @@ uses internalerror(2021092011); end; end; - a_end_function: - ; a_block, a_loop, a_if,