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

Refactor wasmprinter to rely less on a String output #1592

Merged

Conversation

alexcrichton
Copy link
Member

This commit aims at starting to refactor wasmprinter to be able to output to a stream rather than unconditionally to a String. The fact that the current output is always an in-memory String is leveraged in a number of places in the internals to undo prints or capture temporary prints. These were all the easiest thing to do at the time but do not play well with the idea of streaming output. This commit instead refactors wasmprinter to remove all these bits and be more naturally oriented around "just stream out bytes at that's it". This is achieved with some internal refactorings, reorganization, and juggling some responsibilities.

A future PR will switch the internals to actually be std::io::Write or, my final goal, termcolor::WriteColor

Delegate the space-before-immediate to printing the immediate itself
rather than forcing a space between each immediate. Avoids the need to
`pop()` or otherwise test if space is already present in situations
where immediates are omitted.
Previously operators were printed to a temporary buffer and then
depending on what happened it would conditionally go into the actual
module or instead be discarded (e.g. the last `end`). This commit
refactors to instead avoid a temporary buffer entirely and
unconditionally emit instructions to the real output. This is done by
restructuring the printing slightly by having "before_op" and "after_op"
hooks while printing which are used to manage nesting/newlines instead
of the outer loop in the main printer. This is combined with a few other
minor things such as a `is_end_then_eof` method which is used to avoid
printing the final `end`.

One minor test update happened here with a `delegate` instruction from
the legacy exception-handling proposal which I think is a bugfix given
my read of the older proposal.
@sunfishcode sunfishcode added this pull request to the merge queue Jun 5, 2024
Merged via the queue into bytecodealliance:main with commit 7a7815f Jun 5, 2024
25 checks passed
@alexcrichton alexcrichton deleted the remove-print-weirdness branch June 5, 2024 16:07
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

Successfully merging this pull request may close these issues.

2 participants