Add a custom section hook to ModuleEnvironment

This commit adds a hook to the `ModuleEnvironment` trait to learn when a
custom section in a wasm file is read. This hook can in theory be used
to parse and handle custom sections as they appear in the wasm file
without having to re-iterate over the wasm file after cranelift has
already parsed the wasm file.

The `translate_module` function is now less strict in that it doesn't
require sections to be in a particular order, but it's figured that the
wasm file is already validated elsewhere to verify the section order.
This commit is contained in:
Alex Crichton
2019-08-13 13:11:22 -07:00
committed by Dan Gohman
parent 8fd1128990
commit dfda794f55
2 changed files with 79 additions and 124 deletions

View File

@@ -467,4 +467,14 @@ pub trait ModuleEnvironment<'data> {
offset: usize,
data: &'data [u8],
) -> WasmResult<()>;
/// Indicates that a custom section has been found in the wasm file
fn custom_section(
&mut self,
name: &'data str,
data: &'data [u8],
) -> WasmResult<()> {
drop((name, data));
Ok(())
}
}