Use the WasmRuntime's type list rather than keeping a separate list.
This commit is contained in:
@@ -5,7 +5,7 @@ use sections_translator::{SectionParsingError, parse_function_signatures, parse_
|
||||
parse_function_section, parse_export_section, parse_memory_section,
|
||||
parse_global_section, parse_table_section, parse_elements_section,
|
||||
parse_data_section};
|
||||
use translation_utils::{Import, SignatureIndex, FunctionIndex};
|
||||
use translation_utils::{Import, FunctionIndex};
|
||||
use cretonne::ir::{Function, FunctionName};
|
||||
use func_translator::FuncTranslator;
|
||||
use std::collections::HashMap;
|
||||
@@ -39,7 +39,6 @@ pub fn translate_module(
|
||||
}
|
||||
ref s => panic!("modules should begin properly: {:?}", s),
|
||||
}
|
||||
let mut functions: Vec<SignatureIndex> = Vec::new();
|
||||
let mut globals = Vec::new();
|
||||
let mut exports: HashMap<FunctionIndex, String> = HashMap::new();
|
||||
let mut next_input = ParserInput::Default;
|
||||
@@ -62,7 +61,6 @@ pub fn translate_module(
|
||||
for import in imps {
|
||||
match import {
|
||||
Import::Function { sig_index } => {
|
||||
functions.push(sig_index as SignatureIndex);
|
||||
function_index += 1;
|
||||
}
|
||||
Import::Memory(mem) => {
|
||||
@@ -86,9 +84,7 @@ pub fn translate_module(
|
||||
}
|
||||
ParserState::BeginSection { code: SectionCode::Function, .. } => {
|
||||
match parse_function_section(&mut parser, runtime) {
|
||||
Ok(funcs) => {
|
||||
functions.extend(funcs);
|
||||
}
|
||||
Ok(()) => {}
|
||||
Err(SectionParsingError::WrongSectionContent(s)) => {
|
||||
return Err(format!("wrong content in the function section: {}", s))
|
||||
}
|
||||
@@ -193,7 +189,9 @@ pub fn translate_module(
|
||||
runtime.next_function();
|
||||
// First we build the Function object with its name and signature
|
||||
let mut func = Function::new();
|
||||
func.signature = runtime.get_signature(functions[function_index]).clone();
|
||||
func.signature = runtime
|
||||
.get_signature(runtime.get_func_type(function_index))
|
||||
.clone();
|
||||
if let Some(name) = exports.get(&function_index) {
|
||||
func.name = FunctionName::new(name.clone());
|
||||
}
|
||||
|
||||
@@ -146,6 +146,10 @@ impl WasmRuntime for DummyRuntime {
|
||||
self.func_types.push(sig_index);
|
||||
}
|
||||
|
||||
fn get_func_type(&self, func_index: FunctionIndex) -> SignatureIndex {
|
||||
self.func_types[func_index]
|
||||
}
|
||||
|
||||
fn declare_global(&mut self, global: Global) {
|
||||
self.globals.push(global);
|
||||
}
|
||||
|
||||
@@ -162,6 +162,9 @@ pub trait WasmRuntime: FuncEnvironment {
|
||||
/// Declares the type (signature) of a local function in the module.
|
||||
fn declare_func_type(&mut self, sig_index: SignatureIndex);
|
||||
|
||||
/// Return the signature index for the given function index.
|
||||
fn get_func_type(&self, func_index: FunctionIndex) -> SignatureIndex;
|
||||
|
||||
/// Declares a global to the runtime.
|
||||
fn declare_global(&mut self, global: Global);
|
||||
/// Declares a table to the runtime.
|
||||
|
||||
@@ -113,19 +113,17 @@ pub fn parse_import_section(
|
||||
pub fn parse_function_section(
|
||||
parser: &mut Parser,
|
||||
runtime: &mut WasmRuntime,
|
||||
) -> Result<Vec<SignatureIndex>, SectionParsingError> {
|
||||
let mut funcs = Vec::new();
|
||||
) -> Result<(), SectionParsingError> {
|
||||
loop {
|
||||
match *parser.read() {
|
||||
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))),
|
||||
};
|
||||
}
|
||||
Ok(funcs)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Retrieves the names of the functions from the export section
|
||||
|
||||
Reference in New Issue
Block a user