Commit graph

24 commits

Author SHA1 Message Date
Brian Carroll
d996eee72e Pointlessly improve how we handle a crazy edge case, because my brain wouldn't let it go 2021-10-25 13:26:50 +02:00
Brian Carroll
4e098be7fe Fix a test throwing a Wasm runtime error 2021-10-25 13:04:30 +02:00
Brian Carroll
3f404dd114 clippy 2021-10-25 12:23:24 +02:00
Brian Carroll
ddf66293e9 Fix and refactor number encodings 2021-10-25 12:15:04 +02:00
Brian Carroll
b6e442c9ee Fix locals code gen 2021-10-24 23:36:00 +02:00
Brian Carroll
11f327f722 Fix function call 2021-10-24 23:35:25 +02:00
Brian Carroll
6534da5055 Fix LEB encoding and refactor insertions 2021-10-24 11:54:21 +02:00
Brian Carroll
13577aa9ec Combine our handmade Code section with other sections from parity_wasm (tests compile but fail) 2021-10-23 17:12:49 +02:00
Brian Carroll
7c398ba238 tweak comment 2021-10-23 13:52:45 +02:00
Brian Carroll
973626fe2d Rename FunctionBuilder back to CodeBuilder 2021-10-23 13:48:20 +02:00
Brian Carroll
dbe6d195f7 Delete CodeBuilder 2021-10-23 13:40:10 +02:00
Brian Carroll
5ea313f256 update gen_wasm to use bumpalo::collections::Vec where possible 2021-10-21 21:14:15 +02:00
Brian Carroll
401f2ececd rename some methods 2021-10-18 21:35:16 +02:00
Brian Carroll
e4db06cbdd Add a debug assertion in code builder 2021-10-18 21:16:54 +02:00
Brian Carroll
64603a480c Get rid of Option in VM stack model 2021-10-18 21:03:54 +02:00
Brian Carroll
99468b0aac Clarify a comment 2021-10-17 11:24:25 +02:00
Brian Carroll
6206418b67 Fix clippy warnings 2021-10-14 00:13:47 +02:00
Brian Carroll
58549bdf07 CodeBuilder doc comments 2021-10-10 20:56:49 +01:00
Brian Carroll
041e26e807 rename CodeBuilder methods 2021-10-10 20:56:39 +01:00
Brian Carroll
476c1664ec Add debug logging to CodeBuilder and fix a minor bug 2021-10-09 17:24:37 +01:00
Brian Carroll
3aaafdefe1 Get Join/Jump working with VM storage 2021-10-09 16:46:59 +01:00
Brian Carroll
af823fe5a8 Get rid of unneeded local.set/get in common cases 2021-10-06 20:07:20 +01:00
Brian Carroll
d6bba482ee Treat the Virtual Machine stack as a form of SymbolStorage
Simulate the behaviour of the stack machine, mark where Symbol values
are created, and track where they are in the stack as we emit instructions.

This will allow us to be smarter with setting and getting locals.
However that's not actually implemented yet! At the moment,
we're still generating the same code as before but in a fancier way.

What's happening:

Let's say we have a function call that takes two arguments [A,B]
and that we are lucky and just happen to have a VM stack of [A,B]
That's great, we _should_ not have to do anything, just emit 'Call'

BUT what we are doing is "load A to the top" and then "load B to the top".
This sounds good but it's actually stupid
We are saying we want A at the top of the stack when we don't!!
We want it right where it is, just beneath the top!

So we are emitting code to bring it from 2nd position to the top.
How do we do that? By inserting a local.set instruction to save it,
and a local.get instruction to load it to the top!

What should be happening:

Check the entire VM stack at once for all the symbols we are trying to load.
If they happen to be there (which is likely given the IR structure) do nothing.
If it's not quite perfect... then emit lots of local.set and local.get. Whatever.

What would be the way to solve this properly?

Build the Wasm instructions as a tree, then serialise it depth-first.
The tree encodes all of the information about what needs to be on the
stack at what point in the program. If a tree node has two children,
it consumes two items from the stack. If you do it this way, all
of the instructions get executed just at the right time.
2021-10-05 21:39:19 +01:00
Brian Carroll
32f79b5ee2 Create CodeBuilder to track Wasm VM stack as we accumulate instructions 2021-10-03 22:50:11 +01:00