Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-decompile: add function index comments #2482

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/decompiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions test/decompile/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 ;;)
2 changes: 1 addition & 1 deletion test/decompile/code-metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/decompile/loadstore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/decompile/names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;)
2 changes: 1 addition & 1 deletion test/decompile/precedence.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions test/decompile/stack-flush.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion test/regress/regress-1922.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand Down
2 changes: 1 addition & 1 deletion test/regress/regress-1924.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(;; STDOUT ;;;
export global __empty:long = 8L;

function f_a():long {
function f_a():long { // func0
return __empty
}

Expand Down
Loading