diff --git a/src/backend/mod.rs b/src/backend/mod.rs index f7fd76e..0936cfc 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -6,6 +6,7 @@ use crate::ir::{ExportKind, FuncDecl, FunctionBody, ImportKind, Module, Type, Va use crate::passes::rpo::RPO; use crate::Operator; use anyhow::Result; +use rayon::prelude::*; use std::borrow::Cow; pub mod stackify; @@ -689,10 +690,19 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result> { into_mod.section(&elem); let mut code = wasm_encoder::CodeSection::new(); - for (func, func_decl) in module.funcs().skip(num_func_imports) { - let body = func_decl.body().unwrap(); - log::debug!("Compiling {}", func); - let body = WasmFuncBackend::new(body)?.compile()?; + let bodies = module + .funcs() + .skip(num_func_imports) + .collect::>() + .par_iter() + .map(|(func, func_decl)| -> Result { + let body = func_decl.body().unwrap(); + log::debug!("Compiling {}", func); + WasmFuncBackend::new(body)?.compile() + }) + .collect::>>()?; + + for body in bodies { code.function(&body); } into_mod.section(&code);