Commit graph

126 commits

Author SHA1 Message Date
Brian Carroll
c57d99c1ac Create types for DataSection 2021-11-04 18:58:17 +00:00
Brian Carroll
ad9b761fce Move wasm file format code into a submodule 2021-11-03 11:20:16 +00:00
Brian Carroll
87f6246851 Remove parity-wasm! 2021-11-03 10:36:08 +00:00
Brian Carroll
59757d638a Migrate the last sections: Type and Function 2021-11-03 10:24:03 +00:00
Brian Carroll
b0aeafc066 Refactor code section to get rid of a copy 2021-11-02 20:34:57 +00:00
Brian Carroll
d8c1017aec refactor stack pointer initialisation 2021-11-02 14:00:22 +00:00
Brian Carroll
baf896f6f9 Migrate linking and relocation sections 2021-11-02 13:56:47 +00:00
Brian Carroll
e720873c05 Migrate to own Global and Memory sections 2021-11-02 13:32:54 +00:00
Brian Carroll
edadd4ce13 Temporary setup to gradually migrate sections from parity_wasm to our own module_builder
Previously we just had our own code section.
Now we also have export section, and a way of switching them over one by one,
running tests in between.
2021-11-02 12:46:15 +00:00
Brian Carroll
6ab00d164c Create WasmModule struct 2021-11-01 00:06:25 +00:00
Brian Carroll
63f65947bc Remove excessive calls to LayoutIds::default() 2021-11-01 00:02:28 +00:00
Brian Carroll
b0e0c14dd8 clippy 2021-10-30 17:52:38 +01:00
Brian Carroll
b8eea9be2b Fix linking bugs from wasm-objdump analysis 2021-10-30 17:47:13 +01:00
Brian Carroll
99b08ad395 Skip relocations for test_wrapper since we don't run a linker on it anyway. 2021-10-30 09:50:53 +01:00
Brian Carroll
b541802819 Change custom section names to string slice
We will never need to create these names dynamically.
e.g. "reloc.CODE", "reloc.DATA", and "linking" will all
come from specific places in our backend code.
It's a different story for function names etc.
2021-10-30 09:26:40 +01:00
Brian Carroll
2da2e51895 Move relocations code into the backend and code builder 2021-10-30 09:20:16 +01:00
Brian Carroll
9780cce4dd Rough draft of function name relocations 2021-10-30 08:55:33 +01:00
Brian Carroll
3c9375af28 Start creating module_builder 2021-10-28 13:18:14 +01:00
Brian Carroll
82acf55d38 Create serializer module 2021-10-28 11:50:55 +01:00
Brian Carroll
eb47b5183c Slightly refactor code section swapping 2021-10-27 19:41:52 +01:00
Brian Carroll
f066adbe05 Adjust relocation offset to account for inserts, preamble, function offset, etc. 2021-10-27 16:50:30 +01:00
Brian Carroll
1def56ea04 Build up a vector of relocations 2021-10-26 23:31:36 +01:00
Brian Carroll
fd3d8f5227 Get rid of procedure sorting 2021-10-26 22:44:28 +01:00
Brian Carroll
a0d2b7e6e1 Unit tests for LEB-128 encoders 2021-10-26 18:08:40 +01: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
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
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
74e3239a1c Switch over to function_builder 2021-10-23 13:39:54 +02:00
Brian Carroll
bca9f31c58 Implement insertions for byte-level code gen 2021-10-23 00:02:14 +02:00
Brian Carroll
dc1779d41d Finalisation and serialisation for byte-level function builder 2021-10-22 19:02:03 +02:00
Brian Carroll
4f958e8a80 Get most common instruction patterns to compile 2021-10-22 12:01:22 +02:00
Brian Carroll
4563e2af49 Get function_builder compiling 2021-10-22 10:38:53 +02:00
Brian Carroll
e168d175c4 Start writing a byte-level function_builder 2021-10-21 21:30:51 +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
1be6fd1222 Switch to fork of parity-wasm that can support bumpalo vectors 2021-10-21 17:14:07 +02:00
Brian Carroll
401f2ececd rename some methods 2021-10-18 21:35:16 +02:00
Brian Carroll
1b97675f1f Refactor the optimisation for immediately-returned Let statements
The original intention was to avoid creating a local when we define
and immediately return a primitive value. But now our default path
does avoids unnecessary locals anyway!

For StackMemory values we do need an optimised path but it's nicer
to just pass a flag to Storage::allocate.
2021-10-18 13:18:10 +02:00
Brian Carroll
041e26e807 rename CodeBuilder methods 2021-10-10 20:56:39 +01:00
Brian Carroll
c5ee41af25 rename code_builder 2021-10-10 20:56:32 +01:00
Brian Carroll
8164a14dfa rename module_builder 2021-10-10 20:56:20 +01:00
Brian Carroll
d796bbcc68 add a couple of assertions 2021-10-05 21:19:08 +01:00
Brian Carroll
32f79b5ee2 Create CodeBuilder to track Wasm VM stack as we accumulate instructions 2021-10-03 22:50:11 +01:00
Brian Carroll
79a4f2bbf7 Refactor SymbolStorage local_id code, and copy_memory
SymbolStorage had some rather ad-hoc methods for extracting pieces of data.
This change makes that more intentional and organised.

Also cleaned up the API for the related function copy_memory,
as it had lots of positional arguments with the same types.
Created a struct for this just to name them and make the code clearer.
2021-10-02 22:31:48 +01:00
Brian Carroll
ffa6ff0a62 gen_wasm: Get rid of individual locals for values in stack memory
All values in stack memory can share the stack frame pointer,
with different offsets.

This avoids having to generate initialisation code for individual
pointers we used to have. It should also make things more efficient
when the runtime compiles Wasm to machine code. It can just assign
the stack frame pointer to a single CPU register and leave it there.

The original idea was to make params and local variables work the same.
(A struct param will be passed as a pointer to caller stack memory.)
But now I don't think that's worth it. Some match expressions get more
awkward this way but we might be able to refactor that to be nicer.
2021-10-02 15:12:25 +01:00
Brian Carroll
4aa2452e01 gen_wasm: Change some compiler bugs error handling from Result to panic
Result makes sense where I have something meaningful to say to the user like
"X is not implemented yet". And also for public functions that may interface
with other parts of the project like Backend.

But for private functions internal to gen_wasm, it's just unhelpful to get a stack trace
to where the Result is unwrapped! I want a stack trace to the root cause.
I always end up temporarily rewriting Err("oops") to panic!("oops") and then waiting
for it to recompile.

This feels like a more balanced approach, using each technique where it makes sense.
2021-10-02 13:40:44 +01:00
Brian Carroll
7ac7e16f60 Ensure stack frame is always popped when procedure returns from inside a branch 2021-09-30 17:04:16 +01:00
Brian Carroll
7ea59ad9d4 PR tidy-ups 2021-09-29 06:15:58 +01:00