Switch over to raw Vec<u8> for compiled funcs.
This commit is contained in:
parent
efa07f16cf
commit
eab940024b
|
@ -1303,11 +1303,6 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
|
|||
|
||||
let mut code = wasm_encoder::CodeSection::new();
|
||||
|
||||
enum FuncOrRawBytes<'a> {
|
||||
Raw(&'a [u8]),
|
||||
Func(Cow<'a, wasm_encoder::Function>),
|
||||
}
|
||||
|
||||
let bodies = module
|
||||
.funcs
|
||||
.entries()
|
||||
|
@ -1318,16 +1313,14 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
|
|||
match func_decl {
|
||||
FuncDecl::Lazy(_, _name, reader) => {
|
||||
let data = &module.orig_bytes[reader.range()];
|
||||
Ok(FuncOrRawBytes::Raw(data))
|
||||
}
|
||||
FuncDecl::Compiled(_, _name, encoder) => {
|
||||
Ok(FuncOrRawBytes::Func(Cow::Borrowed(encoder)))
|
||||
Ok(Cow::Borrowed(data))
|
||||
}
|
||||
FuncDecl::Compiled(_, _name, bytes) => Ok(Cow::Borrowed(&bytes[..])),
|
||||
FuncDecl::Body(_, name, body) => {
|
||||
log::debug!("Compiling {} \"{}\"", func, name);
|
||||
WasmFuncBackend::new(body)?
|
||||
.compile()
|
||||
.map(|func| FuncOrRawBytes::Func(Cow::Owned(func)))
|
||||
.map(|func| Cow::Owned(func.into_raw_body()))
|
||||
}
|
||||
FuncDecl::Import(_, _) => unreachable!("Should have skipped imports"),
|
||||
FuncDecl::None => panic!("FuncDecl::None at compilation time"),
|
||||
|
@ -1336,14 +1329,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
|
|||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
for body in bodies {
|
||||
match body {
|
||||
FuncOrRawBytes::Raw(bytes) => {
|
||||
code.raw(bytes);
|
||||
}
|
||||
FuncOrRawBytes::Func(func) => {
|
||||
code.function(&*func);
|
||||
}
|
||||
}
|
||||
code.raw(&body);
|
||||
}
|
||||
into_mod.section(&code);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ pub enum FuncDecl<'a> {
|
|||
/// A modified or new function body that requires compilation.
|
||||
Body(Signature, String, FunctionBody),
|
||||
/// A compiled function body (was IR, has been collapsed back to bytecode).
|
||||
Compiled(Signature, String, wasm_encoder::Function),
|
||||
Compiled(Signature, String, Vec<u8>),
|
||||
/// A placeholder.
|
||||
#[default]
|
||||
None,
|
||||
|
|
Loading…
Reference in a new issue