Skip to content

Commit b15a13e

Browse files
authored
wasm-decompile: add function index comments (#2482)
1 parent 646785d commit b15a13e

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

src/decompiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,9 @@ struct Decompiler {
826826
}
827827
}
828828
if (is_import) {
829-
s += ";";
829+
s += cat("; // func", std::to_string(func_index));
830830
} else {
831-
s += " {\n";
831+
s += cat(" { // func", std::to_string(func_index), "\n");
832832
auto val = DecompileExpr(ast.exp_stack[0], nullptr);
833833
IndentValue(val, indent_amount, {});
834834
for (auto& stat : val.v) {

test/decompile/basic.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ data d_abcdefghijklmnoqrstuvwxyzabc(offset: 100) =
149149
data d_c(offset: 200) = "hi";
150150
data d_d(offset: 300) = "Hello, World!\0a\00";
151151

152-
import function ns_fi();
152+
import function ns_fi(); // func0
153153

154-
export function f(a:int, b:int):int {
154+
export function f(a:int, b:int):int { // func1
155155
var c:long = 8L;
156156
var d:float = 6.0f;
157157
var e:double = 7.0;
@@ -191,7 +191,7 @@ export function f(a:int, b:int):int {
191191
return 0;
192192
}
193193

194-
function f_c() {
194+
function f_c() { // func2
195195
var a:int;
196196
loop L_a {
197197
a = 1;
@@ -200,13 +200,13 @@ function f_c() {
200200
a;
201201
}
202202

203-
function signature() {
203+
function signature() { // func3
204204
}
205205

206-
function signature_1() {
206+
function signature_1() { // func4
207207
}
208208

209-
function f_f() {
209+
function f_f() { // func5
210210
}
211211

212212
;;; STDOUT ;;)

test/decompile/code-metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
return))
99

1010
(;; STDOUT ;;;
11-
function f_a(a:int):int {
11+
function f_a(a:int):int { // func0
1212
let t0 = a;
1313
// @metadata.code.test "aa\01a";
1414
return 1234 + t0;

test/decompile/loadstore.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ memory M_a(initial: 1, max: 0);
110110

111111
data d_HelloWorld(offset: 10) = "Hello, World!\0a\00";
112112

113-
export function f(a:{ a:float, b:float }, b:{ a:ushort, b:long }) {
113+
export function f(a:{ a:float, b:float }, b:{ a:ushort, b:long }) { // func0
114114
var c:{ a:float, b:float }
115115
var d:{ a:ushort, b:long }
116116
var e:int;

test/decompile/names.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ export global G1_EXPORT:int = 0;
9999
data D0_SYM(offset: 0) = "Hello, World!";
100100
data D1_SYM(offset: 10) = "bar";
101101

102-
function F0():int {
102+
function F0():int { // func0
103103
var L0:int;
104104
return L0;
105105
}
106106

107-
function F1_NS() {
107+
function F1_NS() { // func1
108108
}
109109

110-
function F2_SYM() {
110+
function F2_SYM() { // func2
111111
}
112112

113-
export function F3_EXPORT() {
113+
export function F3_EXPORT() { // func3
114114
}
115115

116116
;;; STDOUT ;;)

test/decompile/precedence.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
(;; STDOUT ;;;
4040
memory M_a(initial: 1, max: 0);
4141

42-
export function precedence() {
42+
export function precedence() { // func0
4343
0[0]:int * 1 + 2 << 3 == 4 & 5;
4444
(((((6 & 5) == 4) << 3) + 2) * 1)[0]:int;
4545
}

test/decompile/stack-flush.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
(;; STDOUT ;;;
5151
memory M_a(initial: 1, max: 0);
5252

53-
export function f(a:int, b:int):int {
53+
export function f(a:int, b:int):int { // func0
5454
let t0 = s();
5555
s();
5656
let t1, t2 = s(), s();
@@ -70,11 +70,11 @@ export function f(a:int, b:int):int {
7070
return t7 == t8;
7171
}
7272

73-
export function s():int {
73+
export function s():int { // func1
7474
return 1
7575
}
7676

77-
export function mv():(int, int) {
77+
export function mv():(int, int) { // func2
7878
return 1, 2
7979
}
8080

test/regress/regress-1922.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
i32.add
1010
end))
1111
(;; STDOUT ;;;
12-
function f_a(a:int, b:int):int {
12+
function f_a(a:int, b:int):int { // func0
1313
a + br_table[L_a, ..L_a](unreachable);
1414
return loop L_a {
1515
}

test/regress/regress-1924.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
(;; STDOUT ;;;
1010
export global __empty:long = 8L;
1111

12-
function f_a():long {
12+
function f_a():long { // func0
1313
return __empty
1414
}
1515

0 commit comments

Comments
 (0)