diff --git a/Cargo.toml b/Cargo.toml index 7961c569d7..fc93a4f3b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "wasmstandalone_tools" +name = "wasmtime_tools" authors = ["The Cretonne Project Developers"] version = "0.0.0" -description = "Command-line interface for the wasmstandalone crate" +description = "Command-line interface for the wasmtime crate" license = "MIT/Apache-2.0" documentation = "https://cretonne.readthedocs.io/" -repository = "https://github.com/sunfishcode/wasmstandalone" +repository = "https://github.com/sunfishcode/wasmtime" publish = false [[bin]] -name = "wasmstandalone" +name = "wasmtime" path = "src/main.rs" [[bin]] @@ -17,18 +17,18 @@ name = "wasm2obj" path = "src/wasm2obj.rs" [dependencies] -cretonne-codegen = "0.9.0" -cretonne-frontend = "0.9.0" -cretonne-reader = "0.9.0" -cretonne-wasm = "0.9.0" -cretonne-native = "0.9.0" -wasmstandalone_runtime = { path = "lib/runtime" } -wasmstandalone_execute = { path = "lib/execute" } -wasmstandalone_obj = { path = "lib/obj" } +cretonne-codegen = "0.13.0" +cretonne-frontend = "0.13.0" +cretonne-reader = "0.13.0" +cretonne-wasm = "0.13.0" +cretonne-native = "0.13.0" +wasmtime_runtime = { path = "lib/runtime" } +wasmtime_execute = { path = "lib/execute" } +wasmtime_obj = { path = "lib/obj" } docopt = "1.0.0" serde = "1.0.55" serde_derive = "1.0.55" tempdir = "*" -faerie = "0.4.1" +faerie = "0.4.2" [workspace] diff --git a/README.md b/README.md index 8e3c9d59b6..d3bfbf172e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# wasmstandalone +# wasmtime Standalone JIT-style runtime support for WebAsssembly code in Cretonne *This is a work in progress that is not currently functional.* diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 2e5c042b42..58274f28dc 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wasmstandalone_fuzz" +name = "wasmtime_fuzz" version = "0.0.1" authors = ["The Cretonne Project Developers"] publish = false @@ -7,10 +7,10 @@ publish = false [package.metadata] cargo-fuzz = true -[dependencies.wasmstandalone_runtime] +[dependencies.wasmtime_runtime] path = "../lib/runtime" -[dependencies.wasmstandalone_execute] +[dependencies.wasmtime_execute] path = "../lib/execute" [dependencies.cretonne-codegen] diff --git a/fuzz/fuzz_targets/compile.rs b/fuzz/fuzz_targets/compile.rs index 02e538af4e..149f64de79 100644 --- a/fuzz/fuzz_targets/compile.rs +++ b/fuzz/fuzz_targets/compile.rs @@ -5,8 +5,8 @@ extern crate libfuzzer_sys; extern crate cretonne; extern crate cton_wasm; extern crate cton_native; -extern crate wasmstandalone_runtime; -extern crate wasmstandalone_execute; +extern crate wasmtime_runtime; +extern crate wasmtime_execute; use cretonne::settings; use cton_wasm::translate_module; @@ -16,12 +16,12 @@ fuzz_target!(|data: &[u8]| { panic!("host machine is not a supported target"); }); let isa = isa_builder.finish(settings::Flags::new(&flag_builder)); - let mut runtime = wasmstandalone_runtime::Runtime::with_flags(isa.flags().clone()); + let mut runtime = wasmtime_runtime::Runtime::with_flags(isa.flags().clone()); let translation = match translate_module(&data, &mut runtime) { Ok(x) => x, Err(_) => return, }; - let _exec = match wasmstandalone_execute::compile_module(&translation, &*isa, &runtime) { + let _exec = match wasmtime_execute::compile_module(&translation, &*isa, &runtime) { Ok(x) => x, Err(_) => return, }; diff --git a/lib/execute/Cargo.toml b/lib/execute/Cargo.toml index d2b06e8405..a97e65223f 100644 --- a/lib/execute/Cargo.toml +++ b/lib/execute/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "wasmstandalone_execute" +name = "wasmtime_execute" version = "0.0.0" authors = ["The Cretonne Project Developers"] publish = false description = "JIT-style runtime support for WebAsssembly code in Cretonne" -repository = "https://github.com/sunfishcode/wasmstandalone" +repository = "https://github.com/sunfishcode/wasmtime" license = "MIT/Apache-2.0" [dependencies] -cretonne-codegen = "0.9.0" -cretonne-wasm = "0.9.0" +cretonne-codegen = "0.13.0" +cretonne-wasm = "0.13.0" region = "0.3.0" -wasmstandalone_runtime = { path = "../runtime" } +wasmtime_runtime = { path = "../runtime" } diff --git a/lib/execute/src/lib.rs b/lib/execute/src/lib.rs index f77781da01..7f550c4c85 100644 --- a/lib/execute/src/lib.rs +++ b/lib/execute/src/lib.rs @@ -5,7 +5,7 @@ extern crate cretonne_codegen; extern crate cretonne_wasm; extern crate region; -extern crate wasmstandalone_runtime; +extern crate wasmtime_runtime; use cretonne_codegen::binemit::Reloc; use cretonne_codegen::isa::TargetIsa; @@ -13,13 +13,13 @@ use region::protect; use region::Protection; use std::mem::transmute; use std::ptr::write_unaligned; -use wasmstandalone_runtime::Compilation; +use wasmtime_runtime::Compilation; /// Executes a module that has been translated with the `standalone::Runtime` runtime implementation. pub fn compile_module<'data, 'module>( isa: &TargetIsa, - translation: &wasmstandalone_runtime::ModuleTranslation<'data, 'module>, -) -> Result, String> { + translation: &wasmtime_runtime::ModuleTranslation<'data, 'module>, +) -> Result, String> { debug_assert!( translation.module.start_func.is_none() || translation.module.start_func.unwrap() >= translation.module.imported_funcs.len(), @@ -35,7 +35,7 @@ pub fn compile_module<'data, 'module>( } /// Performs the relocations inside the function bytecode, provided the necessary metadata -fn relocate(compilation: &mut Compilation, relocations: &wasmstandalone_runtime::Relocations) { +fn relocate(compilation: &mut Compilation, relocations: &wasmtime_runtime::Relocations) { // The relocations are relative to the relocation's address plus four bytes // TODO: Support architectures other than x64, and other reloc kinds. for (i, function_relocs) in relocations.iter().enumerate() { @@ -65,7 +65,7 @@ fn relocate(compilation: &mut Compilation, relocations: &wasmstandalone_runtime: /// Create the VmCtx data structure for the JIT'd code to use. This must /// match the VmCtx layout in the runtime. -fn make_vmctx(instance: &mut wasmstandalone_runtime::Instance) -> Vec<*mut u8> { +fn make_vmctx(instance: &mut wasmtime_runtime::Instance) -> Vec<*mut u8> { let mut memories = Vec::new(); let mut vmctx = Vec::new(); vmctx.push(instance.globals.as_mut_ptr()); @@ -78,8 +78,8 @@ fn make_vmctx(instance: &mut wasmstandalone_runtime::Instance) -> Vec<*mut u8> { /// Jumps to the code region of memory and execute the start function of the module. pub fn execute( - compilation: &wasmstandalone_runtime::Compilation, - instance: &mut wasmstandalone_runtime::Instance, + compilation: &wasmtime_runtime::Compilation, + instance: &mut wasmtime_runtime::Instance, ) -> Result<(), String> { let start_index = compilation .module diff --git a/lib/obj/Cargo.toml b/lib/obj/Cargo.toml index 00955a0b86..9664bf7710 100644 --- a/lib/obj/Cargo.toml +++ b/lib/obj/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "wasmstandalone_obj" +name = "wasmtime_obj" version = "0.0.0" authors = ["The Cretonne Project Developers"] publish = false [dependencies] -cretonne-codegen = "0.9.0" -cretonne-wasm = "0.9.0" -wasmstandalone_runtime = { path = "../runtime" } -faerie = "0.4.1" +cretonne-codegen = "0.13.0" +cretonne-wasm = "0.13.0" +wasmtime_runtime = { path = "../runtime" } +faerie = "0.4.2" diff --git a/lib/obj/src/emit_module.rs b/lib/obj/src/emit_module.rs index 7c3f01264a..b0af0b4da1 100644 --- a/lib/obj/src/emit_module.rs +++ b/lib/obj/src/emit_module.rs @@ -1,14 +1,14 @@ use cretonne_codegen::settings; use cretonne_codegen::settings::Configurable; use faerie::Artifact; -use wasmstandalone_runtime; +use wasmtime_runtime; /// Emits a module that has been emitted with the `WasmRuntime` runtime /// implementation to a native object file. pub fn emit_module<'module>( obj: &mut Artifact, - compilation: &wasmstandalone_runtime::Compilation<'module>, - relocations: &wasmstandalone_runtime::Relocations, + compilation: &wasmtime_runtime::Compilation<'module>, + relocations: &wasmtime_runtime::Relocations, ) -> Result<(), String> { debug_assert!( compilation.module.start_func.is_none() diff --git a/lib/obj/src/lib.rs b/lib/obj/src/lib.rs index 742ab99c6e..726a84b7b4 100644 --- a/lib/obj/src/lib.rs +++ b/lib/obj/src/lib.rs @@ -1,7 +1,7 @@ extern crate cretonne_codegen; extern crate cretonne_wasm; extern crate faerie; -extern crate wasmstandalone_runtime; +extern crate wasmtime_runtime; mod emit_module; diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index bef992ffd3..feb46b60b9 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "wasmstandalone_runtime" +name = "wasmtime_runtime" version = "0.0.0" authors = ["The Cretonne Project Developers"] publish = false description = "Standalone runtime support for WebAsssembly code in Cretonne" -repository = "https://github.com/sunfishcode/wasmstandalone" +repository = "https://github.com/sunfishcode/wasmtime" license = "Apache-2.0" [dependencies] -cretonne-codegen = "0.9.0" -cretonne-wasm = "0.9.0" -wasmparser = "0.16.1" -target-lexicon = "0.0.1" +cretonne-codegen = "0.13.0" +cretonne-wasm = "0.13.0" +wasmparser = "0.17.0" +target-lexicon = "0.0.2" diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index 9c28569651..84d09442a2 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -23,12 +23,16 @@ 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::ir::{ + AbiParam, ArgumentExtension, ArgumentLoc, ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, + Function, InstBuilder, Signature, +}; use cretonne_codegen::isa; use cretonne_codegen::settings; -use cretonne_wasm::{FuncTranslator, FunctionIndex, Global, GlobalIndex, GlobalValue, Memory, - MemoryIndex, SignatureIndex, Table, TableIndex, WasmResult}; +use cretonne_wasm::{ + FuncTranslator, FunctionIndex, Global, GlobalIndex, GlobalVariable, Memory, MemoryIndex, + SignatureIndex, Table, TableIndex, WasmResult, +}; use target_lexicon::Triple; /// Compute a `ir::ExternalName` for a given wasm function index. @@ -189,10 +193,10 @@ pub struct FuncEnvironment<'module_environment> { pub module: &'module_environment Module, /// The Cretonne global holding the base address of the memories vector. - pub memories_base: Option, + pub memories_base: Option, /// The Cretonne global holding the base address of the globals vector. - pub globals_base: Option, + pub globals_base: Option, /// The external function declaration for implementing wasm's `current_memory`. pub current_memory_extfunc: Option, @@ -235,13 +239,13 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo self.isa.triple() } - fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue { + fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalVariable { let ptr_size = self.ptr_size(); let globals_base = self.globals_base.unwrap_or_else(|| { let offset = 0 * ptr_size; let offset32 = offset as i32; debug_assert_eq!(offset32 as usize, offset); - let new_base = func.create_global_var(ir::GlobalVarData::VMContext { + let new_base = func.create_global_value(ir::GlobalValueData::VMContext { offset: Offset32::new(offset32), }); self.globals_base = Some(new_base); @@ -250,11 +254,11 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo let offset = index as usize * 8; let offset32 = offset as i32; debug_assert_eq!(offset32 as usize, offset); - let gv = func.create_global_var(ir::GlobalVarData::Deref { + let gv = func.create_global_value(ir::GlobalValueData::Deref { base: globals_base, offset: Offset32::new(offset32), }); - GlobalValue::Memory { + GlobalVariable::Memory { gv, ty: self.module.globals[index].ty, } @@ -263,7 +267,7 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo fn make_heap(&mut self, func: &mut ir::Function, index: MemoryIndex) -> ir::Heap { let ptr_size = self.ptr_size(); let memories_base = self.memories_base.unwrap_or_else(|| { - let new_base = func.create_global_var(ir::GlobalVarData::VMContext { + let new_base = func.create_global_value(ir::GlobalValueData::VMContext { offset: Offset32::new(ptr_size as i32), }); self.globals_base = Some(new_base); @@ -272,12 +276,16 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo let offset = index as usize * ptr_size; let offset32 = offset as i32; debug_assert_eq!(offset32 as usize, offset); - let heap_base = func.create_global_var(ir::GlobalVarData::Deref { + let heap_base_addr = func.create_global_value(ir::GlobalValueData::Deref { base: memories_base, offset: Offset32::new(offset32), }); + let heap_base = func.create_global_value(ir::GlobalValueData::Deref { + base: heap_base_addr, + offset: Offset32::new(0), + }); let h = func.create_heap(ir::HeapData { - base: ir::HeapBase::GlobalVar(heap_base), + base: ir::HeapBase::GlobalValue(heap_base), min_size: 0.into(), guard_size: 0x8000_0000.into(), style: ir::HeapStyle::Static { @@ -332,7 +340,7 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo Ok(pos.ins().call(callee, &real_call_args)) } - fn translate_grow_memory( + fn translate_memory_grow( &mut self, mut pos: FuncCursor, index: MemoryIndex, @@ -362,7 +370,7 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } - fn translate_current_memory( + fn translate_memory_size( &mut self, mut pos: FuncCursor, index: MemoryIndex, diff --git a/lib/runtime/src/module.rs b/lib/runtime/src/module.rs index 3b33c6b3b3..374209676d 100644 --- a/lib/runtime/src/module.rs +++ b/lib/runtime/src/module.rs @@ -2,8 +2,9 @@ //! WebAssembly module. use cretonne_codegen::ir; -use cretonne_wasm::{FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, - Table, TableIndex}; +use cretonne_wasm::{ + FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex, +}; use std::collections::HashMap; /// Possible values for a WebAssembly table element. diff --git a/src/main.rs b/src/main.rs index f8d33c36b5..64fa9db8a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -//! CLI tool to use the functions provided by the [wasmstandalone](../wasmstandalone/index.html) +//! CLI tool to use the functions provided by the [wasmtime](../wasmtime/index.html) //! crate. //! //! Reads Wasm binary files (one Wasm module per file), translates the functions' code to Cretonne @@ -9,8 +9,8 @@ extern crate cretonne_codegen; extern crate cretonne_native; extern crate cretonne_wasm; extern crate docopt; -extern crate wasmstandalone_execute; -extern crate wasmstandalone_runtime; +extern crate wasmtime_execute; +extern crate wasmtime_runtime; #[macro_use] extern crate serde_derive; extern crate tempdir; @@ -29,8 +29,8 @@ use std::path::Path; use std::path::PathBuf; use std::process::{exit, Command}; use tempdir::TempDir; -use wasmstandalone_execute::{compile_module, execute}; -use wasmstandalone_runtime::{Instance, Module, ModuleEnvironment}; +use wasmtime_execute::{compile_module, execute}; +use wasmtime_runtime::{Instance, Module, ModuleEnvironment}; const USAGE: &str = " Wasm to Cretonne IL translation utility. @@ -38,8 +38,8 @@ Takes a binary WebAssembly module and returns its functions in Cretonne IL forma The translation is dependent on the environment chosen. Usage: - wasmstandalone [-mop] ... - wasmstandalone --help | --version + wasmtime [-mop] ... + wasmtime --help | --version Options: -o, --optimize runs optimization passes on the translated functions diff --git a/src/wasm2obj.rs b/src/wasm2obj.rs index 90d649a829..7bb3f411a5 100644 --- a/src/wasm2obj.rs +++ b/src/wasm2obj.rs @@ -8,8 +8,8 @@ extern crate cretonne_codegen; extern crate cretonne_native; extern crate cretonne_wasm; extern crate docopt; -extern crate wasmstandalone_obj; -extern crate wasmstandalone_runtime; +extern crate wasmtime_obj; +extern crate wasmtime_runtime; #[macro_use] extern crate serde_derive; extern crate faerie; @@ -26,7 +26,7 @@ use std::io::prelude::*; use std::path::Path; use std::path::PathBuf; use std::process; -use wasmstandalone_obj::emit_module; +use wasmtime_obj::emit_module; const USAGE: &str = " Wasm to native object translation utility. @@ -90,8 +90,8 @@ fn handle_module(path: PathBuf, output: &str) -> Result<(), String> { }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut module = wasmstandalone_runtime::Module::new(); - let mut environ = wasmstandalone_runtime::ModuleEnvironment::new(&*isa, &mut module); + let mut module = wasmtime_runtime::Module::new(); + let mut environ = wasmtime_runtime::ModuleEnvironment::new(&*isa, &mut module); translate_module(&data, &mut environ).map_err(|e| e.to_string())?; let mut obj = Artifact::new(isa.triple().clone(), String::from(output));