wasm-decompile: add function index comments#2482
Conversation
83e2564 to
047514f
Compare
sbc100
left a comment
There was a problem hiding this comment.
I assume you find this feature useful? Can you explain a little more about why its useful? I assumed the point of the decompiler was so that the user would not have to worry about things like the internal index spaces that live in the binary format?
| } | ||
| if (is_import) { | ||
| s += ";"; | ||
| s += cat("; // f", std::to_string(func_index)); |
There was a problem hiding this comment.
I think there are other types that are also indexed? So a unique prefix seems better, can change to func if it makes more sense.
There was a problem hiding this comment.
Yes, I've just never seen f0, f1 used to refer to function indexes, so its not obvious to me as the reader what it means.
|
You still have to cross-reference with other tools, all of which show function indexes: Chromium debugger, .wat, Cetus. So it's easier to search for functions in text editors when there's a numeric index. |
But doesn't the chromium debugger and the wat format both use function names (from the name section)? Also, I assume in the case when there is no name in the name section the decompiler will use the function index as the function name? |
047514f to
c533954
Compare
|
I'm new to WASM, so not sure in which cases names are available. Here's how most functions look in a random WASM game (Unity, Emscripten): Chromium / Firefox devtools: .wat wasm-decompile: The names are only shown for imported/exported functions: So in the end you need numerical indexes to navigate. |
If you build you module with a name section I think you will see the actual names here.
Ah... where is
import/exported names are just one way to give a function a name. The better way to to use the names section. |
|
BTW, this change LGTM, with comments resolved. |
It's not my module and I don't have the source code :)
So I tried adding a cmd arg for |
In those cases I would hope the decompiler would put the function index into the name, not only in a comment.
So is
|
It's generated from an index, so 704 = caa, 25 = z, 26 = aa, 27 = ba: wabt/include/wabt/generate-names.h Lines 33 to 42 in b15a13e
Just slightly easier to read/remember |
Interesting! That seems like pointless obfuscation to me... why not put the useful information in the name? |
No description provided.