Add a FuncEnvironment::make_direct_func() callback.

This allows the environment to control the signatures used for direct
function calls. The signature and calling convention may depend on
whether the function is imported or local.

Also add WasmRuntime::declare_func_{import,type} to notify the runtime
about imported and local functions. This is necessary so the runtime
knows what function indexes are referring to .

Since imported and local functions are now declared to the runtime, it
is no longer necessary to return hashes mapping between WebAssembly
indexes and Cretonne entities.

Also stop return null entries for the imported functions in the
TranslationResult. Just return a vector of local functions.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-06 11:44:52 -07:00
parent 45b093ea59
commit dc2bee9cef
10 changed files with 154 additions and 223 deletions

View File

@@ -5,7 +5,7 @@
//! IL. Can also executes the `start` function of the module by laying out the memories, globals
//! and tables, then emitting the translated code with hardcoded addresses to memory.
use cton_wasm::{translate_module, FunctionTranslation, DummyRuntime, WasmRuntime};
use cton_wasm::{translate_module, DummyRuntime, WasmRuntime};
use std::path::PathBuf;
use cretonne::loop_analysis::LoopAnalysis;
use cretonne::flowgraph::ControlFlowGraph;
@@ -149,13 +149,9 @@ fn handle_module(
vprint!(flag_verbose, "Checking... ");
terminal.reset().unwrap();
for func in &translation.functions {
let il = match *func {
FunctionTranslation::Import() => continue,
FunctionTranslation::Code { ref il, .. } => il.clone(),
};
match verifier::verify_function(&il, None) {
match verifier::verify_function(func, None) {
Ok(()) => (),
Err(err) => return Err(pretty_verifier_error(&il, None, err)),
Err(err) => return Err(pretty_verifier_error(func, None, err)),
}
}
terminal.fg(term::color::GREEN).unwrap();
@@ -167,10 +163,7 @@ fn handle_module(
vprint!(flag_verbose, "Optimizing... ");
terminal.reset().unwrap();
for func in &translation.functions {
let mut il = match *func {
FunctionTranslation::Import() => continue,
FunctionTranslation::Code { ref il, .. } => il.clone(),
};
let mut il = func.clone();
let mut loop_analysis = LoopAnalysis::new();
let mut cfg = ControlFlowGraph::new();
cfg.compute(&il);