Update to Cranelift 0.24.
This commit is contained in:
10
Cargo.toml
10
Cargo.toml
@@ -18,8 +18,10 @@ name = "wasm2obj"
|
||||
path = "src/wasm2obj.rs"
|
||||
|
||||
[dependencies]
|
||||
cranelift-codegen = "0.22.0"
|
||||
cranelift-native = "0.22.0"
|
||||
cranelift-codegen = "0.24.0"
|
||||
cranelift-native = "0.24.0"
|
||||
cranelift-entity = "0.24.0"
|
||||
cranelift-wasm = "0.24.0"
|
||||
wasmtime-environ = { path = "lib/environ" }
|
||||
wasmtime-execute = { path = "lib/execute" }
|
||||
wasmtime-obj = { path = "lib/obj" }
|
||||
@@ -27,7 +29,7 @@ docopt = "1.0.1"
|
||||
serde = "1.0.75"
|
||||
serde_derive = "1.0.75"
|
||||
tempdir = "*"
|
||||
faerie = "0.5.0"
|
||||
target-lexicon = { version = "0.0.3", default-features = false }
|
||||
faerie = "0.6.0"
|
||||
target-lexicon = { version = "0.2.0", default-features = false }
|
||||
|
||||
[workspace]
|
||||
|
||||
@@ -10,9 +10,9 @@ cargo-fuzz = true
|
||||
[dependencies]
|
||||
wasmtime-environ = { path = "../lib/environ" }
|
||||
wasmtime-execute = { path = "../lib/execute" }
|
||||
cranelift-codegen = "0.22.0"
|
||||
cranelift-wasm = "0.22.0"
|
||||
cranelift-native = "0.22.0"
|
||||
cranelift-codegen = "0.24.0"
|
||||
cranelift-wasm = "0.24.0"
|
||||
cranelift-native = "0.24.0"
|
||||
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
|
||||
wasmparser = { version = "0.17.2", default-features = false }
|
||||
|
||||
|
||||
@@ -10,10 +10,9 @@ license = "Apache-2.0 WITH LLVM-exception"
|
||||
readme = "README.md"
|
||||
|
||||
[dependencies]
|
||||
cranelift-codegen = "0.22.0"
|
||||
cranelift-entity = "0.22.0"
|
||||
cranelift-wasm = "0.22.0"
|
||||
target-lexicon = "0.0.3"
|
||||
cranelift-codegen = "0.24.0"
|
||||
cranelift-entity = "0.24.0"
|
||||
cranelift-wasm = "0.24.0"
|
||||
memoffset = "0.2.1"
|
||||
|
||||
[badges]
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
extern crate cranelift_codegen;
|
||||
extern crate cranelift_entity;
|
||||
extern crate cranelift_wasm;
|
||||
extern crate target_lexicon;
|
||||
#[macro_use]
|
||||
extern crate memoffset;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ pub enum Export {
|
||||
#[derive(Debug)]
|
||||
pub struct Module {
|
||||
/// Unprocessed signatures exactly as provided by `declare_signature()`.
|
||||
pub signatures: Vec<ir::Signature>,
|
||||
pub signatures: PrimaryMap<SignatureIndex, ir::Signature>,
|
||||
|
||||
/// Names of imported functions.
|
||||
pub imported_funcs: Vec<(String, String)>,
|
||||
@@ -48,13 +48,13 @@ pub struct Module {
|
||||
pub functions: PrimaryMap<FuncIndex, SignatureIndex>,
|
||||
|
||||
/// WebAssembly tables.
|
||||
pub tables: Vec<Table>,
|
||||
pub tables: PrimaryMap<TableIndex, Table>,
|
||||
|
||||
/// WebAssembly linear memories.
|
||||
pub memories: Vec<Memory>,
|
||||
pub memories: PrimaryMap<MemoryIndex, Memory>,
|
||||
|
||||
/// WebAssembly global variables.
|
||||
pub globals: Vec<Global>,
|
||||
pub globals: PrimaryMap<GlobalIndex, Global>,
|
||||
|
||||
/// Exported entities.
|
||||
pub exports: HashMap<String, Export>,
|
||||
@@ -70,12 +70,12 @@ impl Module {
|
||||
/// Allocates the module data structures.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
signatures: Vec::new(),
|
||||
signatures: PrimaryMap::new(),
|
||||
imported_funcs: Vec::new(),
|
||||
functions: PrimaryMap::new(),
|
||||
tables: Vec::new(),
|
||||
memories: Vec::new(),
|
||||
globals: Vec::new(),
|
||||
tables: PrimaryMap::new(),
|
||||
memories: PrimaryMap::new(),
|
||||
globals: PrimaryMap::new(),
|
||||
exports: HashMap::new(),
|
||||
start_func: None,
|
||||
table_elements: Vec::new(),
|
||||
|
||||
@@ -9,9 +9,9 @@ repository = "https://github.com/CraneStation/wasmtime"
|
||||
license = "Apache-2.0 WITH LLVM-exception"
|
||||
|
||||
[dependencies]
|
||||
cranelift-codegen = "0.22.0"
|
||||
cranelift-entity = "0.22.0"
|
||||
cranelift-wasm = "0.22.0"
|
||||
region = "0.3.0"
|
||||
cranelift-codegen = "0.24.0"
|
||||
cranelift-entity = "0.24.0"
|
||||
cranelift-wasm = "0.24.0"
|
||||
region = "1.0.0"
|
||||
wasmtime-environ = { path = "../environ" }
|
||||
memmap = "0.7.0"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use cranelift_codegen::binemit::Reloc;
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_entity::{EntityRef, PrimaryMap};
|
||||
use cranelift_wasm::{DefinedFuncIndex, MemoryIndex};
|
||||
use cranelift_wasm::{DefinedFuncIndex, MemoryIndex, TableIndex};
|
||||
use instance::Instance;
|
||||
use memory::LinearMemory;
|
||||
use region::protect;
|
||||
@@ -87,7 +87,7 @@ extern "C" fn grow_memory(size: u32, memory_index: u32, vmctx: *mut *mut u8) ->
|
||||
// FIXME: update the VMMemory's size
|
||||
let instance = (*vmctx.offset(4)) as *mut Instance;
|
||||
(*instance)
|
||||
.memory_mut(memory_index as MemoryIndex)
|
||||
.memory_mut(MemoryIndex::new(memory_index as usize))
|
||||
.grow(size)
|
||||
.unwrap_or(u32::max_value())
|
||||
}
|
||||
@@ -98,7 +98,7 @@ extern "C" fn current_memory(memory_index: u32, vmctx: *mut *mut u8) -> u32 {
|
||||
// FIXME: read the VMMemory's size instead
|
||||
let instance = (*vmctx.offset(4)) as *mut Instance;
|
||||
(*instance)
|
||||
.memory_mut(memory_index as MemoryIndex)
|
||||
.memory_mut(MemoryIndex::new(memory_index as usize))
|
||||
.current_size()
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ fn make_vmctx(instance: &mut Instance, mem_base_addrs: &mut [*mut u8]) -> Vec<*m
|
||||
|
||||
let (default_table_ptr, default_table_len) = instance
|
||||
.tables
|
||||
.get_mut(0)
|
||||
.get_mut(TableIndex::new(0))
|
||||
.map(|table| (table.as_mut_ptr() as *mut u8, table.len()))
|
||||
.unwrap_or((ptr::null_mut(), 0));
|
||||
|
||||
@@ -167,7 +167,7 @@ pub fn execute(
|
||||
// Collect all memory base addresses and Vec.
|
||||
let mut mem_base_addrs = instance
|
||||
.memories
|
||||
.iter_mut()
|
||||
.values_mut()
|
||||
.map(LinearMemory::base_addr)
|
||||
.collect::<Vec<_>>();
|
||||
let vmctx = make_vmctx(instance, &mut mem_base_addrs);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
//! module.
|
||||
|
||||
use cranelift_codegen::ir;
|
||||
use cranelift_wasm::GlobalIndex;
|
||||
use cranelift_entity::EntityRef;
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use cranelift_wasm::{GlobalIndex, MemoryIndex, TableIndex};
|
||||
use memory::LinearMemory;
|
||||
use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements};
|
||||
|
||||
@@ -10,10 +12,10 @@ use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements};
|
||||
#[derive(Debug)]
|
||||
pub struct Instance {
|
||||
/// WebAssembly table data.
|
||||
pub tables: Vec<Vec<usize>>,
|
||||
pub tables: PrimaryMap<TableIndex, Vec<usize>>,
|
||||
|
||||
/// WebAssembly linear memory data.
|
||||
pub memories: Vec<LinearMemory>,
|
||||
pub memories: PrimaryMap<MemoryIndex, LinearMemory>,
|
||||
|
||||
/// WebAssembly global variable data.
|
||||
pub globals: Vec<u8>,
|
||||
@@ -27,8 +29,8 @@ impl Instance {
|
||||
data_initializers: &[DataInitializer],
|
||||
) -> Self {
|
||||
let mut result = Self {
|
||||
tables: Vec::new(),
|
||||
memories: Vec::new(),
|
||||
tables: PrimaryMap::new(),
|
||||
memories: PrimaryMap::new(),
|
||||
globals: Vec::new(),
|
||||
};
|
||||
result.instantiate_tables(module, compilation, &module.table_elements);
|
||||
@@ -45,8 +47,9 @@ impl Instance {
|
||||
table_initializers: &[TableElements],
|
||||
) {
|
||||
debug_assert!(self.tables.is_empty());
|
||||
self.tables.reserve_exact(module.tables.len());
|
||||
for table in &module.tables {
|
||||
// TODO: Enable this once PrimaryMap supports this.
|
||||
//self.tables.reserve_exact(module.tables.len());
|
||||
for table in module.tables.values() {
|
||||
let len = table.size;
|
||||
let mut v = Vec::with_capacity(len);
|
||||
v.resize(len, 0);
|
||||
@@ -69,8 +72,9 @@ impl Instance {
|
||||
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.
|
||||
self.memories.reserve_exact(module.memories.len());
|
||||
for memory in &module.memories {
|
||||
// TODO: Enable this once PrimaryMap supports it.
|
||||
//self.memories.reserve_exact(module.memories.len());
|
||||
for memory in module.memories.values() {
|
||||
let v = LinearMemory::new(memory.pages_count as u32, memory.maximum.map(|m| m as u32));
|
||||
self.memories.push(v);
|
||||
}
|
||||
@@ -92,24 +96,24 @@ impl Instance {
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to a linear memory under the specified index.
|
||||
pub fn memory_mut(&mut self, memory_index: usize) -> &mut LinearMemory {
|
||||
pub fn memory_mut(&mut self, memory_index: MemoryIndex) -> &mut LinearMemory {
|
||||
self.memories
|
||||
.get_mut(memory_index)
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index))
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index.index()))
|
||||
}
|
||||
|
||||
/// Returns a slice of the contents of allocated linear memory.
|
||||
pub fn inspect_memory(&self, memory_index: usize, address: usize, len: usize) -> &[u8] {
|
||||
pub fn inspect_memory(&self, memory_index: MemoryIndex, address: usize, len: usize) -> &[u8] {
|
||||
&self
|
||||
.memories
|
||||
.get(memory_index)
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index))
|
||||
.unwrap_or_else(|| panic!("no memory for index {}", memory_index.index()))
|
||||
.as_ref()[address..address + len]
|
||||
}
|
||||
|
||||
/// Shows the value of a global variable.
|
||||
pub fn inspect_global(&self, global_index: GlobalIndex, ty: ir::Type) -> &[u8] {
|
||||
let offset = global_index * 8;
|
||||
let offset = global_index.index() * 8;
|
||||
let len = ty.bytes() as usize;
|
||||
&self.globals[offset..offset + len]
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ categories = ["wasm"]
|
||||
license = "Apache-2.0 WITH LLVM-exception"
|
||||
|
||||
[dependencies]
|
||||
cranelift-codegen = "0.22.0"
|
||||
cranelift-entity = "0.22.0"
|
||||
cranelift-codegen = "0.24.0"
|
||||
cranelift-entity = "0.24.0"
|
||||
wasmtime-environ = { path = "../environ" }
|
||||
faerie = "0.5.0"
|
||||
faerie = "0.6.0"
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
)]
|
||||
|
||||
extern crate cranelift_codegen;
|
||||
extern crate cranelift_entity;
|
||||
extern crate cranelift_native;
|
||||
extern crate cranelift_wasm;
|
||||
extern crate docopt;
|
||||
extern crate wasmtime_environ;
|
||||
extern crate wasmtime_execute;
|
||||
@@ -45,6 +47,8 @@ extern crate tempdir;
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::settings;
|
||||
use cranelift_codegen::settings::Configurable;
|
||||
use cranelift_entity::EntityRef;
|
||||
use cranelift_wasm::MemoryIndex;
|
||||
use docopt::Docopt;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
@@ -95,9 +99,10 @@ fn main() {
|
||||
.version(Some(String::from("0.0.0")))
|
||||
.deserialize()
|
||||
}).unwrap_or_else(|e| e.exit());
|
||||
let (mut flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| {
|
||||
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
|
||||
panic!("host machine is not a supported target");
|
||||
});
|
||||
let mut flag_builder = settings::builder();
|
||||
|
||||
// Enable verifier passes in debug mode.
|
||||
if cfg!(debug_assertions) {
|
||||
@@ -183,7 +188,7 @@ fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), Stri
|
||||
break;
|
||||
}
|
||||
let memory = instance.inspect_memory(
|
||||
str::parse(split[0]).unwrap(),
|
||||
MemoryIndex::new(str::parse(split[0]).unwrap()),
|
||||
str::parse(split[1]).unwrap(),
|
||||
str::parse(split[2]).unwrap(),
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ extern crate faerie;
|
||||
extern crate target_lexicon;
|
||||
|
||||
use cranelift_codegen::isa;
|
||||
use cranelift_codegen::settings::{self, Configurable};
|
||||
use cranelift_codegen::settings;
|
||||
use docopt::Docopt;
|
||||
use faerie::Artifact;
|
||||
use std::error::Error;
|
||||
@@ -55,7 +55,7 @@ use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use std::str::FromStr;
|
||||
use target_lexicon::{OperatingSystem, Triple};
|
||||
use target_lexicon::Triple;
|
||||
use wasmtime_environ::{compile_module, Module, ModuleEnvironment};
|
||||
use wasmtime_obj::emit_module;
|
||||
|
||||
@@ -116,31 +116,21 @@ fn handle_module(path: PathBuf, target: &Option<String>, output: &str) -> Result
|
||||
}
|
||||
};
|
||||
|
||||
let (flag_builder, isa_builder) = match *target {
|
||||
let isa_builder = match *target {
|
||||
Some(ref target) => {
|
||||
let target = Triple::from_str(&target).map_err(|_| "could not parse --target")?;
|
||||
let mut flag_builder = settings::builder();
|
||||
match target.operating_system {
|
||||
OperatingSystem::Windows => {
|
||||
flag_builder.set("call_conv", "windows_fastcall").unwrap();
|
||||
}
|
||||
_ => {
|
||||
flag_builder.set("call_conv", "system_v").unwrap();
|
||||
}
|
||||
};
|
||||
|
||||
let isa_builder = isa::lookup(target).map_err(|err| match err {
|
||||
isa::lookup(target).map_err(|err| match err {
|
||||
isa::LookupError::SupportDisabled => {
|
||||
"support for architecture disabled at compile time"
|
||||
}
|
||||
isa::LookupError::Unsupported => "unsupported architecture",
|
||||
})?;
|
||||
(flag_builder, isa_builder)
|
||||
})?
|
||||
}
|
||||
None => cranelift_native::builders().unwrap_or_else(|_| {
|
||||
None => cranelift_native::builder().unwrap_or_else(|_| {
|
||||
panic!("host machine is not a supported target");
|
||||
}),
|
||||
};
|
||||
let flag_builder = settings::builder();
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
|
||||
let mut obj = Artifact::new(isa.triple().clone(), String::from(output));
|
||||
|
||||
Reference in New Issue
Block a user