Skip to content
\n

generates types like

\n
(type $type$14 (struct (field (mut i32))))\n
\n

which is convenient because it makes the type hierarchy visible in the text and function types become simpler. However the number 14 here is not the actual struct index in the original program, binaryen renumbered the types.

\n

To avoid renumbering I can use another pass that won't renumber the types:

\n
wasm-opt -all --nominal test.wasm -o test.wat -S --vacuum\n
\n

But that prints types like

\n
(type ${mut:i32} (struct (field (mut i32))))\n
\n

Now I can't see the struct type hierarchy in the output and I can't map a struct type index to the type in the output.

\n

Is there a way to generate wat with type numbers but without renumbering?

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

I don't think there is a way to do that, sorry. --name-types picks arbitrary indexes for the types, and it's not possible to match them to the binary indexes, because Binaryen will reorder types in the binary writing. That is, in Binaryen IR we don't have type indexes, just types. When we write a binary we collect the types, sort by use frequency (to minimize binary size) and then use those indexes.

","upvoteCount":1,"url":"https://github.com/WebAssembly/binaryen/discussions/5785#discussioncomment-6295919"}}}

Wasm binary to wat conversion with type numbers but no renumbering? #5785

Answered by kripken
osa1 asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think there is a way to do that, sorry. --name-types picks arbitrary indexes for the types, and it's not possible to match them to the binary indexes, because Binaryen will reorder types in the binary writing. That is, in Binaryen IR we don't have type indexes, just types. When we write a binary we collect the types, sort by use frequency (to minimize binary size) and then use those indexes.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by osa1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants