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

Stage2: wasm - Implement the MIR pass #10153

Merged
merged 10 commits into from
Nov 15, 2021
Merged

Conversation

Luukdegram
Copy link
Member

This implements the MIR pass for the wasm backend. Right now it re-uses the values of the opcode for each MIR tag, which allows us to easily write its value to memory without having to map from MIR to a wasm opcode. We will however have to add synthetic tags such as debug lines etc. Although not all 256 values are being used, the spec does reserve them and have in the past added new opcodes to those reserved slots. However, an option could be to have synthetic tags use a secondary_tag field, as we will need those anyway for some of the wasm opcodes that are beyond u8. This has the added benefit that each MIR instruction will remain 5 bytes max, as we can keep Tag 1 byte, rather than 2.

This declares the initial most-used instructions for wasm as
well as the data that represents them.
TODO: Add binary operand opcodes.

By re-using the wasm opcode values, we can emit each opcode very easily
by simply using `@enumToInt()`. However, this poses a possible problem:
If we use all of wasm's opcodes, it leaves us no room to use synthetic opcodes such as debugging instructions.
We could use reserved opcodes, but the wasm spec may use them at some point.
TODO: Check if we should perhaps use a 16bit tag where the highest bits are used for synthetic opcodes.
- This implements lowering to MIR from AIR for storing and loading of locals
as well as emitting immediates.
- Relocating function indexes has been simplified a lot as well as we no
longer need to patch offsets and we write a relocatable value instead.
- Locals are now emitted at the beginning of the function section entry
meaning all offsets we generate are stable.
- 64bit immediates are now stored in 2 seperate u32's.
- 64bit floats are now stored in 2 seperate u32's.
- `mem_arg` is now stored as a seperate payload in extra.
@kubkon kubkon merged commit d3135f7 into ziglang:master Nov 15, 2021
@kubkon
Copy link
Member

kubkon commented Nov 15, 2021

Awesome work!

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