From c5339548fe7c5d0dac6879de57b9c6ad98d64255 Mon Sep 17 00:00:00 2001 From: python273 Date: Tue, 8 Oct 2024 21:39:44 +0400 Subject: [PATCH] wasm-decompile: add function index comments --- src/decompiler.cc | 4 ++-- test/decompile/basic.txt | 12 ++++++------ test/decompile/code-metadata.txt | 2 +- test/decompile/loadstore.txt | 2 +- test/decompile/names.txt | 8 ++++---- test/decompile/precedence.txt | 2 +- test/decompile/stack-flush.txt | 6 +++--- test/regress/regress-1922.txt | 2 +- test/regress/regress-1924.txt | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/decompiler.cc b/src/decompiler.cc index 257de8362b..cdb0a78385 100644 --- a/src/decompiler.cc +++ b/src/decompiler.cc @@ -826,9 +826,9 @@ struct Decompiler { } } if (is_import) { - s += ";"; + s += cat("; // func", std::to_string(func_index)); } else { - s += " {\n"; + s += cat(" { // func", std::to_string(func_index), "\n"); auto val = DecompileExpr(ast.exp_stack[0], nullptr); IndentValue(val, indent_amount, {}); for (auto& stat : val.v) { diff --git a/test/decompile/basic.txt b/test/decompile/basic.txt index b8cdaead7a..6564de8937 100644 --- a/test/decompile/basic.txt +++ b/test/decompile/basic.txt @@ -149,9 +149,9 @@ data d_abcdefghijklmnoqrstuvwxyzabc(offset: 100) = data d_c(offset: 200) = "hi"; data d_d(offset: 300) = "Hello, World!\0a\00"; -import function ns_fi(); +import function ns_fi(); // func0 -export function f(a:int, b:int):int { +export function f(a:int, b:int):int { // func1 var c:long = 8L; var d:float = 6.0f; var e:double = 7.0; @@ -191,7 +191,7 @@ export function f(a:int, b:int):int { return 0; } -function f_c() { +function f_c() { // func2 var a:int; loop L_a { a = 1; @@ -200,13 +200,13 @@ function f_c() { a; } -function signature() { +function signature() { // func3 } -function signature_1() { +function signature_1() { // func4 } -function f_f() { +function f_f() { // func5 } ;;; STDOUT ;;) diff --git a/test/decompile/code-metadata.txt b/test/decompile/code-metadata.txt index 1efd9d65b2..c66763bc66 100644 --- a/test/decompile/code-metadata.txt +++ b/test/decompile/code-metadata.txt @@ -8,7 +8,7 @@ return)) (;; STDOUT ;;; -function f_a(a:int):int { +function f_a(a:int):int { // func0 let t0 = a; // @metadata.code.test "aa\01a"; return 1234 + t0; diff --git a/test/decompile/loadstore.txt b/test/decompile/loadstore.txt index 6b48028674..acbe89011e 100644 --- a/test/decompile/loadstore.txt +++ b/test/decompile/loadstore.txt @@ -110,7 +110,7 @@ memory M_a(initial: 1, max: 0); data d_HelloWorld(offset: 10) = "Hello, World!\0a\00"; -export function f(a:{ a:float, b:float }, b:{ a:ushort, b:long }) { +export function f(a:{ a:float, b:float }, b:{ a:ushort, b:long }) { // func0 var c:{ a:float, b:float } var d:{ a:ushort, b:long } var e:int; diff --git a/test/decompile/names.txt b/test/decompile/names.txt index 3874b49c19..cc31f1c543 100644 --- a/test/decompile/names.txt +++ b/test/decompile/names.txt @@ -99,18 +99,18 @@ export global G1_EXPORT:int = 0; data D0_SYM(offset: 0) = "Hello, World!"; data D1_SYM(offset: 10) = "bar"; -function F0():int { +function F0():int { // func0 var L0:int; return L0; } -function F1_NS() { +function F1_NS() { // func1 } -function F2_SYM() { +function F2_SYM() { // func2 } -export function F3_EXPORT() { +export function F3_EXPORT() { // func3 } ;;; STDOUT ;;) diff --git a/test/decompile/precedence.txt b/test/decompile/precedence.txt index 8980255a3e..98fe31493a 100644 --- a/test/decompile/precedence.txt +++ b/test/decompile/precedence.txt @@ -39,7 +39,7 @@ (;; STDOUT ;;; memory M_a(initial: 1, max: 0); -export function precedence() { +export function precedence() { // func0 0[0]:int * 1 + 2 << 3 == 4 & 5; (((((6 & 5) == 4) << 3) + 2) * 1)[0]:int; } diff --git a/test/decompile/stack-flush.txt b/test/decompile/stack-flush.txt index cea4fe9bc8..772f81909f 100644 --- a/test/decompile/stack-flush.txt +++ b/test/decompile/stack-flush.txt @@ -50,7 +50,7 @@ (;; STDOUT ;;; memory M_a(initial: 1, max: 0); -export function f(a:int, b:int):int { +export function f(a:int, b:int):int { // func0 let t0 = s(); s(); let t1, t2 = s(), s(); @@ -70,11 +70,11 @@ export function f(a:int, b:int):int { return t7 == t8; } -export function s():int { +export function s():int { // func1 return 1 } -export function mv():(int, int) { +export function mv():(int, int) { // func2 return 1, 2 } diff --git a/test/regress/regress-1922.txt b/test/regress/regress-1922.txt index c6262a9672..12f7f6f057 100644 --- a/test/regress/regress-1922.txt +++ b/test/regress/regress-1922.txt @@ -9,7 +9,7 @@ i32.add end)) (;; STDOUT ;;; -function f_a(a:int, b:int):int { +function f_a(a:int, b:int):int { // func0 a + br_table[L_a, ..L_a](unreachable); return loop L_a { } diff --git a/test/regress/regress-1924.txt b/test/regress/regress-1924.txt index a755a55947..49111469fd 100644 --- a/test/regress/regress-1924.txt +++ b/test/regress/regress-1924.txt @@ -9,7 +9,7 @@ (;; STDOUT ;;; export global __empty:long = 8L; -function f_a():long { +function f_a():long { // func0 return __empty }