Skip to content

Add wasm2wat function and CLI - #305

Draft
MaxDesiatov wants to merge 16 commits into
mainfrom
maxd/wasm2wat
Draft

Add wasm2wat function and CLI#305
MaxDesiatov wants to merge 16 commits into
mainfrom
maxd/wasm2wat

Conversation

@MaxDesiatov

@MaxDesiatov MaxDesiatov commented Feb 22, 2026

Copy link
Copy Markdown
Member

Counterpart to the existing wat2wasm function.

import WasmTypes

/// Collected information from all sections of a WebAssembly binary module.
struct ModuleInfo {

@MaxDesiatov MaxDesiatov Feb 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kateinoigakukun do you have a strong opinion whether introducing this new internal struct is fine, or should we collect into the existing public struct Wat that uses NameMapping?

@MaxDesiatov MaxDesiatov Feb 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing it more, I see that Wat has let parser: Parser text parser, which doesn't make sense to have when converting in an opposite direction: from binary to text. I don't think we can reuse Wat here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to collect all information here before emitting text? Can we streamingly emit text without collecting them?

@MaxDesiatov MaxDesiatov Feb 25, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem is that name section is the last section, but we need that to arrive before we can emit any named declarations (which is all if not most of them?). Do you think it still makes sense to consider streaming here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point. How about skimming all sections first without parsing contents, then parse dependent sections that we need to emit the rest of sections, then streamingly parse/emit the rest of sections?
My main concern for collecting everything as Swift data structure is that we need to model every Wasm entity in Swift even though we rarely manipulate them.

Comment thread Sources/WAT/Printer/TextInstructionVisitor.swift
@MaxDesiatov MaxDesiatov moved this to In Progress in Swift for Wasm Mar 13, 2026
@MaxDesiatov
MaxDesiatov marked this pull request as draft May 25, 2026 21:58
@MaxDesiatov
MaxDesiatov changed the base branch from main to maxd/exception-handling May 25, 2026 22:01
@MaxDesiatov
MaxDesiatov force-pushed the maxd/exception-handling branch 3 times, most recently from e9f27b5 to 4007331 Compare May 26, 2026 09:54
Base automatically changed from maxd/exception-handling to main June 16, 2026 17:02
@MaxDesiatov
MaxDesiatov force-pushed the maxd/wasm2wat branch 4 times, most recently from 412c21f to 23de740 Compare June 23, 2026 16:59
@MaxDesiatov
MaxDesiatov force-pushed the maxd/wasm2wat branch 2 times, most recently from 5975f10 to 0ba91d3 Compare June 30, 2026 18:39
Comment thread Sources/CLICommands/Wasm2wat.swift Outdated
Comment thread Sources/WasmParser/Parser+Streaming.swift Outdated
Comment thread Sources/WasmParser/Parser+Streaming.swift Outdated
Comment thread Sources/WasmParser/Parser+Streaming.swift Outdated
Comment thread Sources/WAT/Printer/ModuleCollector.swift Outdated
Comment thread Sources/WAT/Printer/ModuleCollector.swift Outdated
Comment thread Sources/WAT/Printer/ModuleCollector.swift Outdated
Co-authored-by: Max Desiatov <m_desiatov@apple.com>
# Conflicts:
#	Sources/WasmParser/Stream/FileHandleStream.swift
#	Sources/WasmParser/WasmParser.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants