diff --git a/Cargo.toml b/Cargo.toml index e74552e04b..4d5f85a533 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wasmstandalone-tools" +name = "wasmstandalone_tools" authors = ["The Cretonne Project Developers"] version = "0.0.0" description = "Command-line interface for the wasmstandalone crate" @@ -22,8 +22,9 @@ cretonne-frontend = { git = "https://github.com/stoklund/cretonne.git" } cretonne-reader = { git = "https://github.com/stoklund/cretonne.git" } cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" } cretonne-native = { git = "https://github.com/stoklund/cretonne.git" } -wasmstandalone = { path = "lib/wasmstandalone" } -wasm2obj = { path = "lib/wasm2obj" } +wasmstandalone_runtime = { path = "lib/runtime" } +wasmstandalone_execute = { path = "lib/execute" } +wasmstandalone_obj = { path = "lib/obj" } wasmparser = "0.11.2" wasmtext = { git = "https://github.com/yurydelendik/wasmtext" } filecheck = "0.0.1" diff --git a/lib/execute/Cargo.toml b/lib/execute/Cargo.toml new file mode 100644 index 0000000000..9d14af0dcd --- /dev/null +++ b/lib/execute/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "wasmstandalone_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" +license = "MIT/Apache-2.0" + +[dependencies] +cretonne = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" } +region = "0.0.8" +wasmstandalone_runtime = { path = "../runtime" } diff --git a/lib/wasmstandalone/src/execution.rs b/lib/execute/src/lib.rs similarity index 96% rename from lib/wasmstandalone/src/execution.rs rename to lib/execute/src/lib.rs index 4313ed7e2e..d07dd97d1b 100644 --- a/lib/wasmstandalone/src/execution.rs +++ b/lib/execute/src/lib.rs @@ -1,3 +1,12 @@ +//! JIT-style runtime for WebAssembly using Cretonne. + +#![deny(missing_docs)] + +extern crate cretonne; +extern crate cton_wasm; +extern crate region; +extern crate wasmstandalone_runtime; + use cretonne::Context; use cretonne::settings; use cretonne::isa::TargetIsa; @@ -15,7 +24,6 @@ use region::protect; use std::collections::HashMap; use std::ptr::write_unaligned; use std::fmt::Write; -use standalone; type RelocRef = u16; @@ -64,7 +72,7 @@ pub struct ExecutableCode { pub fn compile_module( trans_result: &TranslationResult, isa: &TargetIsa, - runtime: &standalone::Runtime, + runtime: &wasmstandalone_runtime::Runtime, ) -> Result { debug_assert!( trans_result.start_index.is_none() || @@ -149,7 +157,7 @@ pub fn execute(exec: &ExecutableCode) -> Result<(), String> { fn relocate( functions_metatada: &[FunctionMetaData], functions_code: &mut Vec>, - runtime: &standalone::Runtime, + runtime: &wasmstandalone_runtime::Runtime, ) { // The relocations are relative to the relocation's address plus four bytes for (func_index, function_in_memory) in functions_metatada.iter().enumerate() { diff --git a/lib/wasm2obj/.gitignore b/lib/obj/.gitignore similarity index 100% rename from lib/wasm2obj/.gitignore rename to lib/obj/.gitignore diff --git a/lib/wasm2obj/Cargo.toml b/lib/obj/Cargo.toml similarity index 79% rename from lib/wasm2obj/Cargo.toml rename to lib/obj/Cargo.toml index 3e663acd39..3bfd515f11 100644 --- a/lib/wasm2obj/Cargo.toml +++ b/lib/obj/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wasm2obj" +name = "wasmstandalone_obj" version = "0.0.0" authors = ["The Cretonne Project Developers"] publish = false @@ -7,5 +7,5 @@ publish = false [dependencies] cretonne = { git = "https://github.com/stoklund/cretonne.git" } cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" } -wasmstandalone = { path = "../wasmstandalone" } +wasmstandalone_runtime = { path = "../runtime" } faerie = { git = "https://github.com/m4b/faerie" } diff --git a/lib/wasm2obj/src/emit_module.rs b/lib/obj/src/emit_module.rs similarity index 98% rename from lib/wasm2obj/src/emit_module.rs rename to lib/obj/src/emit_module.rs index 1caf3d269a..ae26f11af9 100644 --- a/lib/wasm2obj/src/emit_module.rs +++ b/lib/obj/src/emit_module.rs @@ -11,7 +11,7 @@ use cretonne::binemit::{RelocSink, Reloc, CodeOffset}; use cton_wasm::TranslationResult; use std::fmt::Write; use faerie::Artifact; -use wasmstandalone; +use wasmstandalone_runtime; type RelocRef = u16; @@ -50,7 +50,7 @@ pub fn emit_module( trans_result: &TranslationResult, obj: &mut Artifact, isa: &TargetIsa, - runtime: &wasmstandalone::Runtime, + runtime: &wasmstandalone_runtime::Runtime, ) -> Result<(), String> { debug_assert!( trans_result.start_index.is_none() || diff --git a/lib/wasm2obj/src/lib.rs b/lib/obj/src/lib.rs similarity index 76% rename from lib/wasm2obj/src/lib.rs rename to lib/obj/src/lib.rs index 1157eb17ce..69d9ec291e 100644 --- a/lib/wasm2obj/src/lib.rs +++ b/lib/obj/src/lib.rs @@ -1,7 +1,7 @@ extern crate cretonne; extern crate cton_wasm; extern crate faerie; -extern crate wasmstandalone; +extern crate wasmstandalone_runtime; mod emit_module; diff --git a/lib/wasmstandalone/.gitignore b/lib/runtime/.gitignore similarity index 100% rename from lib/wasmstandalone/.gitignore rename to lib/runtime/.gitignore diff --git a/lib/wasmstandalone/Cargo.toml b/lib/runtime/Cargo.toml similarity index 59% rename from lib/wasmstandalone/Cargo.toml rename to lib/runtime/Cargo.toml index 91d6dfd881..174ed8d893 100644 --- a/lib/wasmstandalone/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -1,13 +1,12 @@ [package] -name = "wasmstandalone" +name = "wasmstandalone_runtime" version = "0.0.0" authors = ["The Cretonne Project Developers"] publish = false -description = "Standalone JIT-style runtime support for WebAsssembly code in Cretonne" -repository = "https://github.com/stoklund/cretonne" +description = "Standalone runtime support for WebAsssembly code in Cretonne" +repository = "https://github.com/sunfishcode/wasmstandalone" license = "Apache-2.0" [dependencies] cretonne = { git = "https://github.com/stoklund/cretonne.git" } cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" } -region = "0.0.8" diff --git a/lib/wasmstandalone/src/standalone.rs b/lib/runtime/src/lib.rs similarity index 95% rename from lib/wasmstandalone/src/standalone.rs rename to lib/runtime/src/lib.rs index 7ab7afecea..1f26c578e5 100644 --- a/lib/wasmstandalone/src/standalone.rs +++ b/lib/runtime/src/lib.rs @@ -1,3 +1,13 @@ +//! Standalone runtime for WebAssembly using Cretonne. Provides functions to translate +//! `get_global`, `set_global`, `current_memory`, `grow_memory`, `call_indirect` that hardcode in +//! the translation the base addresses of regions of memory that will hold the globals, tables and +//! linear memories. + +#![deny(missing_docs)] + +extern crate cretonne; +extern crate cton_wasm; + use cton_wasm::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, Global, GlobalInit, Table, Memory, WasmRuntime, FuncEnvironment, GlobalValue, SignatureIndex}; use cretonne::ir::{InstBuilder, FuncRef, ExtFuncData, FunctionName, Signature, ArgumentType, @@ -12,17 +22,22 @@ use std::mem::transmute; use std::ptr::copy_nonoverlapping; use std::ptr::write; +/// Runtime state of a WebAssembly table element. #[derive(Clone, Debug)] pub enum TableElement { + /// A element that, if called, produces a trap. Trap(), + /// A function. Function(FunctionIndex), } -struct GlobalInfo { +/// Information about a WebAssembly global variable. +pub struct GlobalInfo { global: Global, offset: usize, } +/// Runtime state of a WebAssembly global variable. pub struct GlobalsData { data: Vec, info: Vec, diff --git a/lib/wasmstandalone/src/lib.rs b/lib/wasmstandalone/src/lib.rs deleted file mode 100644 index d60026589d..0000000000 --- a/lib/wasmstandalone/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -//! Standalone JIT-style runtime for WebAssembly using Cretonne. Provides functions to translate -//! `get_global`, `set_global`, `current_memory`, `grow_memory`, `call_indirect` that hardcode in -//! the translation the base addresses of regions of memory that will hold the globals, tables and -//! linear memories. - -#![deny(missing_docs)] - -extern crate cretonne; -extern crate cton_wasm; -extern crate region; - -mod execution; -mod standalone; - -pub use execution::{compile_module, execute, ExecutableCode}; -pub use standalone::Runtime; diff --git a/src/main.rs b/src/main.rs index f4749f1114..538a681e4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,8 @@ extern crate cton_wasm; extern crate cton_native; -extern crate wasmstandalone; +extern crate wasmstandalone_runtime; +extern crate wasmstandalone_execute; extern crate wasmparser; extern crate cretonne; extern crate wasmtext; @@ -18,7 +19,7 @@ extern crate term; extern crate tempdir; use cton_wasm::{translate_module, TranslationResult}; -use wasmstandalone::{compile_module, execute}; +use wasmstandalone_execute::{compile_module, execute}; use std::path::PathBuf; use wasmparser::{Parser, ParserState, WasmDecoder, SectionCode}; use wasmtext::Writer; @@ -157,7 +158,7 @@ fn handle_module(args: &Args, path: PathBuf, name: &str, isa: &TargetIsa) -> Res |err| String::from(err.description()), )?; } - let mut runtime = wasmstandalone::Runtime::with_flags(isa.flags().clone()); + let mut runtime = wasmstandalone_runtime::Runtime::with_flags(isa.flags().clone()); let translation = { match translate_module(&data, &mut runtime) { Ok(x) => x, @@ -320,7 +321,7 @@ fn pretty_print_translation( writer_wat: &mut Write, writer_cretonne: &mut Write, isa: &TargetIsa, - runtime: &wasmstandalone::Runtime, + runtime: &wasmstandalone_runtime::Runtime, ) -> Result<(), io::Error> { let mut terminal = term::stdout().unwrap(); let mut parser = Parser::new(data); diff --git a/src/wasm2obj.rs b/src/wasm2obj.rs index 3392c944cc..73bbf0f6ab 100644 --- a/src/wasm2obj.rs +++ b/src/wasm2obj.rs @@ -5,19 +5,19 @@ //! object file with relocations. extern crate cton_wasm; -extern crate wasm2obj; +extern crate wasmstandalone_obj; +extern crate wasmstandalone_runtime; extern crate cretonne; extern crate cton_native; extern crate docopt; #[macro_use] extern crate serde_derive; -extern crate wasmstandalone; extern crate faerie; use cton_wasm::translate_module; use cretonne::settings; use cretonne::isa; -use wasm2obj::emit_module; +use wasmstandalone_obj::emit_module; use std::path::PathBuf; use std::fs::File; use std::error::Error; @@ -91,7 +91,7 @@ fn handle_module(path: PathBuf, output: &str) -> Result<(), String> { }); let isa = isa_builder.finish(settings::Flags::new(&flag_builder)); - let mut runtime = wasmstandalone::Runtime::with_flags(isa.flags().clone()); + let mut runtime = wasmstandalone_runtime::Runtime::with_flags(isa.flags().clone()); let translation = { match translate_module(&data, &mut runtime) {