Move the 'data lifetime parameter to the ModuleEnvironment trait.

This is needed to allow implementations to have 'data-lifetime
references if they choose to. The DummyEnvironment is an example of an
implementation that doesn't choose to.
This commit is contained in:
Dan Gohman
2017-10-11 21:28:36 -07:00
parent d6ab7e3abf
commit bd94a3b202
4 changed files with 26 additions and 26 deletions

View File

@@ -13,7 +13,7 @@ use runtime::ModuleEnvironment;
/// indexes in the wasm module and the indexes inside each functions.
pub fn translate_module<'data>(
data: &'data [u8],
environ: &mut ModuleEnvironment,
environ: &mut ModuleEnvironment<'data>,
) -> Result<(), String> {
let mut parser = Parser::new(data);
match *parser.read() {

View File

@@ -195,7 +195,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
}
}
impl ModuleEnvironment for DummyEnvironment {
impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
fn get_func_name(&self, func_index: FunctionIndex) -> ir::FunctionName {
get_func_name(func_index)
}
@@ -208,7 +208,7 @@ impl ModuleEnvironment for DummyEnvironment {
&self.info.signatures[sig_index]
}
fn declare_func_import<'data>(
fn declare_func_import(
&mut self,
sig_index: SignatureIndex,
module: &'data str,
@@ -261,7 +261,7 @@ impl ModuleEnvironment for DummyEnvironment {
fn declare_memory(&mut self, memory: Memory) {
self.info.memories.push(Exportable::new(memory));
}
fn declare_data_initialization<'data>(
fn declare_data_initialization(
&mut self,
_memory_index: MemoryIndex,
_base: Option<GlobalIndex>,
@@ -271,7 +271,7 @@ impl ModuleEnvironment for DummyEnvironment {
// We do nothing
}
fn declare_func_export<'data>(&mut self, func_index: FunctionIndex, name: &'data str) {
fn declare_func_export(&mut self, func_index: FunctionIndex, name: &'data str) {
self.info.functions[func_index].export_names.push(
String::from(
name,
@@ -279,13 +279,13 @@ impl ModuleEnvironment for DummyEnvironment {
);
}
fn declare_table_export<'data>(&mut self, table_index: TableIndex, name: &'data str) {
fn declare_table_export(&mut self, table_index: TableIndex, name: &'data str) {
self.info.tables[table_index].export_names.push(
String::from(name),
);
}
fn declare_memory_export<'data>(&mut self, memory_index: MemoryIndex, name: &'data str) {
fn declare_memory_export(&mut self, memory_index: MemoryIndex, name: &'data str) {
self.info.memories[memory_index].export_names.push(
String::from(
name,
@@ -293,7 +293,7 @@ impl ModuleEnvironment for DummyEnvironment {
);
}
fn declare_global_export<'data>(&mut self, global_index: GlobalIndex, name: &'data str) {
fn declare_global_export(&mut self, global_index: GlobalIndex, name: &'data str) {
self.info.globals[global_index].export_names.push(
String::from(
name,
@@ -307,7 +307,7 @@ impl ModuleEnvironment for DummyEnvironment {
}
/// Provides the contents of a function body.
fn define_function_body<'data>(&mut self, body_bytes: &'data [u8]) -> Result<(), String> {
fn define_function_body(&mut self, body_bytes: &'data [u8]) -> Result<(), String> {
let function_index = self.get_num_func_imports() + self.info.function_bodies.len();
let name = get_func_name(function_index);
let sig = self.get_signature(self.get_func_type(function_index))

View File

@@ -149,7 +149,7 @@ pub trait FuncEnvironment {
/// An object satisfyng the `ModuleEnvironment` trait can be passed as argument to the
/// [`translate_module`](fn.translate_module.html) function. These methods should not be called
/// by the user, they are only for `cretonne-wasm` internal use.
pub trait ModuleEnvironment {
pub trait ModuleEnvironment<'data> {
/// Return the name for the given function index.
fn get_func_name(&self, func_index: FunctionIndex) -> ir::FunctionName;
@@ -160,7 +160,7 @@ pub trait ModuleEnvironment {
fn get_signature(&self, sig_index: SignatureIndex) -> &ir::Signature;
/// Declares a function import to the environment.
fn declare_func_import<'data>(
fn declare_func_import(
&mut self,
sig_index: SignatureIndex,
module: &'data str,
@@ -195,7 +195,7 @@ pub trait ModuleEnvironment {
/// Declares a memory to the environment
fn declare_memory(&mut self, memory: Memory);
/// Fills a declared memory with bytes at module instantiation.
fn declare_data_initialization<'data>(
fn declare_data_initialization(
&mut self,
memory_index: MemoryIndex,
base: Option<GlobalIndex>,
@@ -204,17 +204,17 @@ pub trait ModuleEnvironment {
);
/// Declares a function export to the environment.
fn declare_func_export<'data>(&mut self, func_index: FunctionIndex, name: &'data str);
fn declare_func_export(&mut self, func_index: FunctionIndex, name: &'data str);
/// Declares a table export to the environment.
fn declare_table_export<'data>(&mut self, table_index: TableIndex, name: &'data str);
fn declare_table_export(&mut self, table_index: TableIndex, name: &'data str);
/// Declares a memory export to the environment.
fn declare_memory_export<'data>(&mut self, memory_index: MemoryIndex, name: &'data str);
fn declare_memory_export(&mut self, memory_index: MemoryIndex, name: &'data str);
/// Declares a global export to the environment.
fn declare_global_export<'data>(&mut self, global_index: GlobalIndex, name: &'data str);
fn declare_global_export(&mut self, global_index: GlobalIndex, name: &'data str);
/// Declares a start function.
fn declare_start_func(&mut self, index: FunctionIndex);
/// Provides the contents of a function body.
fn define_function_body<'data>(&mut self, body_bytes: &'data [u8]) -> Result<(), String>;
fn define_function_body(&mut self, body_bytes: &'data [u8]) -> Result<(), String>;
}

View File

@@ -56,9 +56,9 @@ pub fn parse_function_signatures(
}
/// Retrieves the imports from the imports section of the binary.
pub fn parse_import_section(
parser: &mut Parser,
environ: &mut ModuleEnvironment,
pub fn parse_import_section<'data>(
parser: &mut Parser<'data>,
environ: &mut ModuleEnvironment<'data>,
) -> Result<(), SectionParsingError> {
loop {
match *parser.read() {
@@ -128,9 +128,9 @@ pub fn parse_function_section(
}
/// Retrieves the names of the functions from the export section
pub fn parse_export_section(
parser: &mut Parser,
environ: &mut ModuleEnvironment,
pub fn parse_export_section<'data>(
parser: &mut Parser<'data>,
environ: &mut ModuleEnvironment<'data>,
) -> Result<(), SectionParsingError> {
loop {
match *parser.read() {
@@ -246,9 +246,9 @@ pub fn parse_global_section(
Ok(())
}
pub fn parse_data_section(
parser: &mut Parser,
environ: &mut ModuleEnvironment,
pub fn parse_data_section<'data>(
parser: &mut Parser<'data>,
environ: &mut ModuleEnvironment<'data>,
) -> Result<(), SectionParsingError> {
loop {
let memory_index = match *parser.read() {