summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill R. <iam@python273.pw>2024-10-08 20:55:47 +0300
committerGitHub <noreply@github.com>2024-10-08 10:55:47 -0700
commitb15a13ef84b5a12aadeb1200521a89a2c95dce19 (patch)
tree661d812e5eeb8afd6dd5166950c5d8f132332e44
parent646785d8b2b15a104d4ed0431125b2c781e141ea (diff)
downloadwabt-b15a13ef84b5a12aadeb1200521a89a2c95dce19.tar.gz
wabt-b15a13ef84b5a12aadeb1200521a89a2c95dce19.tar.bz2
wabt-b15a13ef84b5a12aadeb1200521a89a2c95dce19.zip
wasm-decompile: add function index comments (#2482)
-rw-r--r--src/decompiler.cc4
-rw-r--r--test/decompile/basic.txt12
-rw-r--r--test/decompile/code-metadata.txt2
-rw-r--r--test/decompile/loadstore.txt2
-rw-r--r--test/decompile/names.txt8
-rw-r--r--test/decompile/precedence.txt2
-rw-r--r--test/decompile/stack-flush.txt6
-rw-r--r--test/regress/regress-1922.txt2
-rw-r--r--test/regress/regress-1924.txt2
9 files changed, 20 insertions, 20 deletions
diff --git a/src/decompiler.cc b/src/decompiler.cc
index 257de836..cdb0a783 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 b8cdaead..6564de89 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 1efd9d65..c66763bc 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 6b480286..acbe8901 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 3874b49c..cc31f1c5 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 8980255a..98fe3149 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 cea4fe9b..772f8190 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 c6262a96..12f7f6f0 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 a755a559..49111469 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
}