Commit graph

34 commits

Author SHA1 Message Date
Brian Carroll
d88b86e884 Wasm: change TypeSection tests to unit tests rather than integration tests 2022-01-13 05:41:52 +00:00
Brian Carroll
8e7f398e50 Wasm: Remove code to adjust function indices based on imports
With pre-linking we don't need this anymore. Pure Roc code can't add Imports.
2022-01-13 05:41:52 +00:00
Brian Carroll
c5653951a4 Wasm: improve the TypeSection preload test 2022-01-10 10:26:43 +00:00
Brian Carroll
8f73b722ff Wasm: fix release build 2022-01-10 10:26:43 +00:00
Brian Carroll
fc677e8d58 Wasm: add preloading logic for Types section 2022-01-10 10:26:43 +00:00
Brian Carroll
c89f74f7e8 Wasm: clippy fixes 2022-01-10 10:26:43 +00:00
Brian Carroll
a1f737d6d8 Wasm: Create OpaqueSection for sections that may be used in builtins but not by us 2022-01-10 10:26:43 +00:00
Brian Carroll
738434329e Wasm: refactor the model of the Linking section 2022-01-10 10:26:42 +00:00
Brian Carroll
6db7dbed1c Wasm: Store DataSection as bytes and segment count 2022-01-10 10:26:42 +00:00
Brian Carroll
b8f51fb1bb Wasm: add preloaded_bytes and preloaded_count to Code section 2022-01-10 10:26:42 +00:00
Brian Carroll
743e14148c Wasm: Store Function section as bytes and a count 2022-01-10 10:26:42 +00:00
Brian Carroll
7a6c6b675c Wasm: Store type signatures in serialized form 2022-01-10 10:26:42 +00:00
Brian Carroll
1f86ad3438 Fix Wasm function indices for generated helpers 2021-12-26 10:40:45 +00:00
Brian Carroll
b8f40011b9 Generate a test "platform" with libc allocator functions 2021-11-16 11:59:46 +00:00
Brian Carroll
a5c3809290 Delete DataCountSection. Not well-supported and only needed for instructions we don't use
https://webassembly.github.io/spec/core/binary/modules.html#binary-datacountsec

Tools like wasm2wat and wasm-validate reject the module when this section is included!
Its purpose is to enable single-pass validation for two specific instructions that were
not in the original Wasm MVP: memory.init and data.drop.
We don't use them in our Roc backend. It seems to make sense just to drop the section.
2021-11-15 12:59:28 +00:00
Brian Carroll
830003c9a3 Change wasm opcodes to an enum 2021-11-10 20:18:55 +00:00
Brian Carroll
d0ffaabe83 Re-index all internal functions to make room for imported external functions
Linked external functions must be declared in the Import section,
and they must come first in the function index space.
In other words, internal function numbers start at the number of imports.

However we don't know in advance how many builtins the code may call,
and we don't want to add more passes over the full IR. Instead we re-index
function references at the end of code generation.
2021-11-09 14:50:53 +00:00
Brian Carroll
9e6147a9de Add Debug implementations for sections 2021-11-09 14:28:15 +00:00
Brian Carroll
5bfc0093ec Intitialise CodeSection with just the right capacity 2021-11-08 14:59:49 +00:00
Brian Carroll
34b57cf315 Refactor after creating constant linking data 2021-11-07 11:23:20 +00:00
Brian Carroll
38d9fc5bbd Add linker data for strings, and deduplicate them
For references to addresses of constant strings, we make an entry in
reloc.CODE and configure the relocation type to say it points at a
memory address. (At least I think this is right, I can't test it yet!)

The same info can also be used for de-duplication.

It turns out we don't need reloc.DATA. I had misunderstood it.
The use case for that would be constant nested data structures,
where constant data would contain pointers to other constant data.
I don't think we're doing this in Roc at all, but not sure.
2021-11-07 11:20:32 +00:00
Brian Carroll
e5a0738681 Rename CodeSection serializer, since it doesn't actually mutate 2021-11-05 12:25:27 +00:00
Brian Carroll
01b47a2ec7 Add inline directives to ensure unit placeholders are optimised away 2021-11-05 12:11:37 +00:00
Brian Carroll
d220ed7a23 Refactor module section serialization 2021-11-05 12:11:33 +00:00
Brian Carroll
4dcb65cc46 Fix data count section for the case where data section is empty 2021-11-05 08:36:18 +00:00
Brian Carroll
c5d99433f7 Fix build error
And slightly improve efficiency by exiting early from an iteration
2021-11-04 23:21:48 +00:00
Brian Carroll
09f2ce327c Change some comments after self-review 2021-11-04 21:19:23 +00:00
Brian Carroll
0d1946a782 Don't generate a DataSection unless we actually need it! 2021-11-04 20:50:32 +00:00
Brian Carroll
414c9e6f86 Move WasmModule initialisation into WasmBackend
It helps to coordinate different sections with related values,
based on knowledge of Roc rather than Wasm.
2021-11-04 20:41:23 +00:00
Brian Carroll
1b91fd9533 Get rid of some overcomplicated Data section stuff
Currently a Wasm module can only have one memory
The Data Segment spec allows for more in future
But the format is confusing enough already without that!
Let's just get rid of that complexity, we don't need it.
2021-11-04 19:44:10 +00:00
Brian Carroll
c57d99c1ac Create types for DataSection 2021-11-04 18:58:17 +00:00
Brian Carroll
b432d923b1 Create a linking module 2021-11-03 11:46:46 +00:00
Brian Carroll
d87db20478 clippy 2021-11-03 11:31:12 +00:00
Brian Carroll
ad9b761fce Move wasm file format code into a submodule 2021-11-03 11:20:16 +00:00
Renamed from compiler/gen_wasm/src/module_builder.rs (Browse further)