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:
@@ -64,13 +64,21 @@ pub fn parse_function_signatures(
|
||||
}
|
||||
|
||||
/// Retrieves the imports from the imports section of the binary.
|
||||
pub fn parse_import_section(parser: &mut Parser) -> Result<Vec<Import>, SectionParsingError> {
|
||||
pub fn parse_import_section(
|
||||
parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
) -> Result<Vec<Import>, SectionParsingError> {
|
||||
let mut imports = Vec::new();
|
||||
loop {
|
||||
match *parser.read() {
|
||||
ParserState::ImportSectionEntry {
|
||||
ty: ImportSectionEntryType::Function(sig), ..
|
||||
} => imports.push(Import::Function { sig_index: sig }),
|
||||
ty: ImportSectionEntryType::Function(sig),
|
||||
module,
|
||||
field,
|
||||
} => {
|
||||
runtime.declare_func_import(sig as SignatureIndex, module, field);
|
||||
imports.push(Import::Function { sig_index: sig });
|
||||
}
|
||||
ParserState::ImportSectionEntry {
|
||||
ty: ImportSectionEntryType::Memory(MemoryType { limits: ref memlimits }), ..
|
||||
} => {
|
||||
@@ -110,11 +118,15 @@ pub fn parse_import_section(parser: &mut Parser) -> Result<Vec<Import>, SectionP
|
||||
/// Retrieves the correspondances between functions and signatures from the function section
|
||||
pub fn parse_function_section(
|
||||
parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
) -> Result<Vec<SignatureIndex>, SectionParsingError> {
|
||||
let mut funcs = Vec::new();
|
||||
loop {
|
||||
match *parser.read() {
|
||||
ParserState::FunctionSectionEntry(sigindex) => funcs.push(sigindex as SignatureIndex),
|
||||
ParserState::FunctionSectionEntry(sigindex) => {
|
||||
runtime.declare_func_type(sigindex as SignatureIndex);
|
||||
funcs.push(sigindex as SignatureIndex);
|
||||
}
|
||||
ParserState::EndSection => break,
|
||||
ref s => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user