Update to latest stable rustfmt-preview.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
use cretonne_codegen::ir;
|
||||
use cretonne_wasm::GlobalIndex;
|
||||
use module::Module;
|
||||
use module::{Module, TableElements};
|
||||
use DataInitializer;
|
||||
|
||||
const PAGE_SIZE: usize = 65536;
|
||||
@@ -29,15 +29,14 @@ impl Instance {
|
||||
memories: Vec::new(),
|
||||
globals: Vec::new(),
|
||||
};
|
||||
result.instantiate_tables(module);
|
||||
result.instantiate_tables(module, &module.table_elements);
|
||||
result.instantiate_memories(module, data_initializers);
|
||||
result.instantiate_globals(module);
|
||||
result
|
||||
}
|
||||
|
||||
/// Allocate memory in `self` for just the tables of the current module,
|
||||
/// without any initializers applied yet.
|
||||
fn instantiate_tables(&mut self, module: &Module) {
|
||||
/// Allocate memory in `self` for just the tables of the current module.
|
||||
fn instantiate_tables(&mut self, module: &Module, table_initializers: &[TableElements]) {
|
||||
debug_assert!(self.tables.is_empty());
|
||||
self.tables.reserve_exact(module.tables.len());
|
||||
for table in &module.tables {
|
||||
@@ -46,10 +45,15 @@ impl Instance {
|
||||
v.resize(len, 0);
|
||||
self.tables.push(v);
|
||||
}
|
||||
for init in table_initializers {
|
||||
debug_assert!(init.base.is_none(), "globalvar base not supported yet");
|
||||
let to_init =
|
||||
&mut self.tables[init.table_index][init.offset..init.offset + init.elements.len()];
|
||||
to_init.copy_from_slice(&init.elements);
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocate memory in `instance` for just the memories of the current module,
|
||||
/// without any initializers applied yet.
|
||||
/// Allocate memory in `instance` for just the memories of the current module.
|
||||
fn instantiate_memories(&mut self, module: &Module, data_initializers: &[DataInitializer]) {
|
||||
debug_assert!(self.memories.is_empty());
|
||||
// Allocate the underlying memory and initialize it to all zeros.
|
||||
@@ -62,8 +66,8 @@ impl Instance {
|
||||
}
|
||||
for init in data_initializers {
|
||||
debug_assert!(init.base.is_none(), "globalvar base not supported yet");
|
||||
let to_init = &mut self.memories[init.memory_index][init.offset..
|
||||
init.offset + init.data.len()];
|
||||
let to_init =
|
||||
&mut self.memories[init.memory_index][init.offset..init.offset + init.data.len()];
|
||||
to_init.copy_from_slice(init.data);
|
||||
}
|
||||
}
|
||||
@@ -79,12 +83,9 @@ impl Instance {
|
||||
|
||||
/// Returns a slice of the contents of allocated linear memory.
|
||||
pub fn inspect_memory(&self, memory_index: usize, address: usize, len: usize) -> &[u8] {
|
||||
&self.memories.get(memory_index).expect(
|
||||
format!(
|
||||
"no memory for index {}",
|
||||
memory_index
|
||||
).as_str(),
|
||||
)
|
||||
&self.memories
|
||||
.get(memory_index)
|
||||
.expect(format!("no memory for index {}", memory_index).as_str())
|
||||
[address..address + len]
|
||||
}
|
||||
|
||||
|
||||
@@ -9,25 +9,25 @@ extern crate cretonne_codegen;
|
||||
extern crate cretonne_wasm;
|
||||
extern crate wasmparser;
|
||||
|
||||
pub mod module;
|
||||
pub mod compilation;
|
||||
pub mod instance;
|
||||
pub mod module;
|
||||
|
||||
pub use module::Module;
|
||||
pub use compilation::Compilation;
|
||||
pub use instance::Instance;
|
||||
pub use module::Module;
|
||||
|
||||
use cretonne_wasm::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, Global, Table, Memory,
|
||||
GlobalValue, SignatureIndex, FuncTranslator};
|
||||
use cretonne_codegen::ir::{InstBuilder, FuncRef, ExtFuncData, ExternalName, Signature, AbiParam,
|
||||
ArgumentPurpose, ArgumentLoc, ArgumentExtension, Function};
|
||||
use cretonne_codegen::ir::types::*;
|
||||
use cretonne_codegen::ir::immediates::Offset32;
|
||||
use cretonne_codegen::binemit;
|
||||
use cretonne_codegen::cursor::FuncCursor;
|
||||
use cretonne_codegen::ir;
|
||||
use cretonne_codegen::ir::immediates::Offset32;
|
||||
use cretonne_codegen::ir::types::*;
|
||||
use cretonne_codegen::ir::{AbiParam, ArgumentExtension, ArgumentLoc, ArgumentPurpose, ExtFuncData,
|
||||
ExternalName, FuncRef, Function, InstBuilder, Signature};
|
||||
use cretonne_codegen::isa;
|
||||
use cretonne_codegen::settings;
|
||||
use cretonne_codegen::binemit;
|
||||
use cretonne_wasm::{FuncTranslator, FunctionIndex, Global, GlobalIndex, GlobalValue, Memory,
|
||||
MemoryIndex, SignatureIndex, Table, TableIndex};
|
||||
|
||||
/// Compute a `ir::ExternalName` for a given wasm function index.
|
||||
pub fn get_func_name(func_index: FunctionIndex) -> cretonne_codegen::ir::ExternalName {
|
||||
@@ -96,7 +96,9 @@ impl binemit::RelocSink for RelocSink {
|
||||
|
||||
impl RelocSink {
|
||||
fn new() -> RelocSink {
|
||||
RelocSink { func_relocs: Vec::new() }
|
||||
RelocSink {
|
||||
func_relocs: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +223,11 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
|
||||
}
|
||||
|
||||
fn ptr_size(&self) -> usize {
|
||||
if self.settings_flags.is_64bit() { 8 } else { 4 }
|
||||
if self.settings_flags.is_64bit() {
|
||||
8
|
||||
} else {
|
||||
4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +281,9 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo
|
||||
base: ir::HeapBase::GlobalVar(heap_base),
|
||||
min_size: 0.into(),
|
||||
guard_size: 0x8000_0000.into(),
|
||||
style: ir::HeapStyle::Static { bound: 0x1_0000_0000.into() },
|
||||
style: ir::HeapStyle::Static {
|
||||
bound: 0x1_0000_0000.into(),
|
||||
},
|
||||
});
|
||||
h
|
||||
}
|
||||
@@ -422,10 +430,9 @@ impl<'data, 'module> cretonne_wasm::ModuleEnvironment<'data> for ModuleEnvironme
|
||||
);
|
||||
self.module.functions.push(sig_index);
|
||||
|
||||
self.module.imported_funcs.push((
|
||||
String::from(module),
|
||||
String::from(field),
|
||||
));
|
||||
self.module
|
||||
.imported_funcs
|
||||
.push((String::from(module), String::from(field)));
|
||||
}
|
||||
|
||||
fn get_num_func_imports(&self) -> usize {
|
||||
@@ -489,31 +496,27 @@ impl<'data, 'module> cretonne_wasm::ModuleEnvironment<'data> for ModuleEnvironme
|
||||
}
|
||||
|
||||
fn declare_func_export(&mut self, func_index: FunctionIndex, name: &str) {
|
||||
self.module.exports.insert(
|
||||
String::from(name),
|
||||
module::Export::Function(func_index),
|
||||
);
|
||||
self.module
|
||||
.exports
|
||||
.insert(String::from(name), module::Export::Function(func_index));
|
||||
}
|
||||
|
||||
fn declare_table_export(&mut self, table_index: TableIndex, name: &str) {
|
||||
self.module.exports.insert(
|
||||
String::from(name),
|
||||
module::Export::Table(table_index),
|
||||
);
|
||||
self.module
|
||||
.exports
|
||||
.insert(String::from(name), module::Export::Table(table_index));
|
||||
}
|
||||
|
||||
fn declare_memory_export(&mut self, memory_index: MemoryIndex, name: &str) {
|
||||
self.module.exports.insert(
|
||||
String::from(name),
|
||||
module::Export::Memory(memory_index),
|
||||
);
|
||||
self.module
|
||||
.exports
|
||||
.insert(String::from(name), module::Export::Memory(memory_index));
|
||||
}
|
||||
|
||||
fn declare_global_export(&mut self, global_index: GlobalIndex, name: &str) {
|
||||
self.module.exports.insert(
|
||||
String::from(name),
|
||||
module::Export::Global(global_index),
|
||||
);
|
||||
self.module
|
||||
.exports
|
||||
.insert(String::from(name), module::Export::Global(global_index));
|
||||
}
|
||||
|
||||
fn declare_start_func(&mut self, func_index: FunctionIndex) {
|
||||
@@ -573,8 +576,8 @@ impl<'data, 'module> ModuleTranslation<'data, 'module> {
|
||||
let func_index = i + self.module.imported_funcs.len();
|
||||
let mut context = cretonne_codegen::Context::new();
|
||||
context.func.name = get_func_name(func_index);
|
||||
context.func.signature = self.module.signatures[self.module.functions[func_index]]
|
||||
.clone();
|
||||
context.func.signature =
|
||||
self.module.signatures[self.module.functions[func_index]].clone();
|
||||
|
||||
let mut trans = FuncTranslator::new();
|
||||
let reader = wasmparser::BinaryReader::new(input);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! A `Module` contains all the relevant information translated from a
|
||||
//! WebAssembly module.
|
||||
|
||||
use cretonne_wasm::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, Global, Table, Memory,
|
||||
SignatureIndex};
|
||||
use cretonne_codegen::ir;
|
||||
use cretonne_wasm::{FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex,
|
||||
Table, TableIndex};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Possible values for a WebAssembly table element.
|
||||
|
||||
Reference in New Issue
Block a user