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

Output results of the wasm-decompile to be easier to understand which function is called by call_indirect #2384

Open
getumen opened this issue Feb 5, 2024 · 1 comment

Comments

@getumen
Copy link

getumen commented Feb 5, 2024

The decompiled output from wasm-decompile can be challenging to interpret since the function table is omitted from the resulting files. Annotating the function index within the output aids in comprehending which function is being invoked by the call_indirect instruction.
Consider the following WebAssembly text file, a.wat:

(module
  (type $FUNCSIG$i (func (param i32) (result i32)))
  (table 0 1 funcref)
  (elem (i32.const 0) funcref (ref.func $test))
  (memory $0 1)

  (func $test (type $FUNCSIG$i) (param $p i32) (result i32)
    local.get $p
    i32.const 42
    i32.add
  )

  (func $main (result i32)
    i32.const 42
    i32.const 0
    call_indirect (type $FUNCSIG$i)
  )
)

After running the following commands:

wat2wasm a.wat -o a.wasm
wasm-decompile a.wasm -o a.dcmp

I obtained the decompiled output as such:

memory M_a(initial: 1, max: 0);

table T_a:funcref(min: 0, max: 1);

function f_a(a:int):int {
  return a + 42
}

function f_b():int {
  return call_indirect(42, 0)
}

This decompiled file lacks information about the function table. Moreover, the arguments of the call_indirect function are not immediately clear.
For clearer understanding, consider the decompiled output if it were presented in the following manner:

memory M_a(initial: 1, max: 0);

table T_a:funcref[f_a];

// funcref[0]
function f_a(a:int):int {
  return a + 42
}

function f_b():int {
  return call_indirect(funcref[0])(42)
}

With such modifications, it would be more apparent which function the call_indirect is calling.

@getumen getumen changed the title Output results of the wasm-decompile to be easier to understand what function is called by call_indirect Output results of the wasm-decompile to be easier to understand which function is called by call_indirect Feb 5, 2024
@sbc100
Copy link
Member

sbc100 commented Feb 6, 2024

Unfortunately we don't have anyone who is actively working on wasm-decompile. If you would like to contribute such changes they would be most welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants