Declare exports via the WasmRuntime.

Also, redo how functions are named in the DummyRuntime. Use the FunctionName
field to just encode the wasm function index rather than trying to shoehorn
a printable name into it. And to make up for that, teach the wasm printer
to print export names as comments next to the function definitions.

This also makes the fields of DummyRuntime public, in preparation for
the DummyRuntime to have a more general-purpose debugging role, as well
as possibly to allow it to serve as a base for other implementations.
This commit is contained in:
Dan Gohman
2017-10-09 13:22:06 -07:00
parent 2c9d03f9bd
commit 653e8bb563
5 changed files with 146 additions and 78 deletions

View File

@@ -5,10 +5,8 @@ use sections_translator::{SectionParsingError, parse_function_signatures, parse_
parse_function_section, parse_export_section, parse_start_section,
parse_memory_section, parse_global_section, parse_table_section,
parse_elements_section, parse_data_section};
use translation_utils::FunctionIndex;
use cretonne::ir::{Function, FunctionName};
use cretonne::ir::Function;
use func_translator::FuncTranslator;
use std::collections::HashMap;
use std::error::Error;
use runtime::WasmRuntime;
@@ -34,7 +32,6 @@ pub fn translate_module(
}
ref s => panic!("modules should begin properly: {:?}", s),
}
let mut exports: HashMap<FunctionIndex, String> = HashMap::new();
let mut next_input = ParserInput::Default;
loop {
match *parser.read_with_input(next_input) {
@@ -92,8 +89,8 @@ pub fn translate_module(
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Export, .. } => {
match parse_export_section(&mut parser) {
Ok(exps) => exports = exps,
match parse_export_section(&mut parser, runtime) {
Ok(()) => {}
Err(SectionParsingError::WrongSectionContent(s)) => {
return Err(format!("wrong content in the export section: {}", s))
}
@@ -155,9 +152,7 @@ pub fn translate_module(
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());
}
func.name = runtime.get_name(function_index);
trans
.translate_from_reader(parser.create_binary_reader(), &mut func, runtime)
.map_err(|e| String::from(e.description()))?;