Split the runtime and execution code into separate crates.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasmstandalone-tools"
|
name = "wasmstandalone_tools"
|
||||||
authors = ["The Cretonne Project Developers"]
|
authors = ["The Cretonne Project Developers"]
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
description = "Command-line interface for the wasmstandalone crate"
|
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-reader = { git = "https://github.com/stoklund/cretonne.git" }
|
||||||
cretonne-wasm = { 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" }
|
cretonne-native = { git = "https://github.com/stoklund/cretonne.git" }
|
||||||
wasmstandalone = { path = "lib/wasmstandalone" }
|
wasmstandalone_runtime = { path = "lib/runtime" }
|
||||||
wasm2obj = { path = "lib/wasm2obj" }
|
wasmstandalone_execute = { path = "lib/execute" }
|
||||||
|
wasmstandalone_obj = { path = "lib/obj" }
|
||||||
wasmparser = "0.11.2"
|
wasmparser = "0.11.2"
|
||||||
wasmtext = { git = "https://github.com/yurydelendik/wasmtext" }
|
wasmtext = { git = "https://github.com/yurydelendik/wasmtext" }
|
||||||
filecheck = "0.0.1"
|
filecheck = "0.0.1"
|
||||||
|
|||||||
14
lib/execute/Cargo.toml
Normal file
14
lib/execute/Cargo.toml
Normal file
@@ -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" }
|
||||||
@@ -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::Context;
|
||||||
use cretonne::settings;
|
use cretonne::settings;
|
||||||
use cretonne::isa::TargetIsa;
|
use cretonne::isa::TargetIsa;
|
||||||
@@ -15,7 +24,6 @@ use region::protect;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ptr::write_unaligned;
|
use std::ptr::write_unaligned;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use standalone;
|
|
||||||
|
|
||||||
type RelocRef = u16;
|
type RelocRef = u16;
|
||||||
|
|
||||||
@@ -64,7 +72,7 @@ pub struct ExecutableCode {
|
|||||||
pub fn compile_module(
|
pub fn compile_module(
|
||||||
trans_result: &TranslationResult,
|
trans_result: &TranslationResult,
|
||||||
isa: &TargetIsa,
|
isa: &TargetIsa,
|
||||||
runtime: &standalone::Runtime,
|
runtime: &wasmstandalone_runtime::Runtime,
|
||||||
) -> Result<ExecutableCode, String> {
|
) -> Result<ExecutableCode, String> {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
trans_result.start_index.is_none() ||
|
trans_result.start_index.is_none() ||
|
||||||
@@ -149,7 +157,7 @@ pub fn execute(exec: &ExecutableCode) -> Result<(), String> {
|
|||||||
fn relocate(
|
fn relocate(
|
||||||
functions_metatada: &[FunctionMetaData],
|
functions_metatada: &[FunctionMetaData],
|
||||||
functions_code: &mut Vec<Vec<u8>>,
|
functions_code: &mut Vec<Vec<u8>>,
|
||||||
runtime: &standalone::Runtime,
|
runtime: &wasmstandalone_runtime::Runtime,
|
||||||
) {
|
) {
|
||||||
// The relocations are relative to the relocation's address plus four bytes
|
// The relocations are relative to the relocation's address plus four bytes
|
||||||
for (func_index, function_in_memory) in functions_metatada.iter().enumerate() {
|
for (func_index, function_in_memory) in functions_metatada.iter().enumerate() {
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm2obj"
|
name = "wasmstandalone_obj"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
authors = ["The Cretonne Project Developers"]
|
authors = ["The Cretonne Project Developers"]
|
||||||
publish = false
|
publish = false
|
||||||
@@ -7,5 +7,5 @@ publish = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cretonne = { git = "https://github.com/stoklund/cretonne.git" }
|
cretonne = { git = "https://github.com/stoklund/cretonne.git" }
|
||||||
cretonne-wasm = { 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" }
|
faerie = { git = "https://github.com/m4b/faerie" }
|
||||||
@@ -11,7 +11,7 @@ use cretonne::binemit::{RelocSink, Reloc, CodeOffset};
|
|||||||
use cton_wasm::TranslationResult;
|
use cton_wasm::TranslationResult;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use faerie::Artifact;
|
use faerie::Artifact;
|
||||||
use wasmstandalone;
|
use wasmstandalone_runtime;
|
||||||
|
|
||||||
type RelocRef = u16;
|
type RelocRef = u16;
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ pub fn emit_module(
|
|||||||
trans_result: &TranslationResult,
|
trans_result: &TranslationResult,
|
||||||
obj: &mut Artifact,
|
obj: &mut Artifact,
|
||||||
isa: &TargetIsa,
|
isa: &TargetIsa,
|
||||||
runtime: &wasmstandalone::Runtime,
|
runtime: &wasmstandalone_runtime::Runtime,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
trans_result.start_index.is_none() ||
|
trans_result.start_index.is_none() ||
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate cretonne;
|
extern crate cretonne;
|
||||||
extern crate cton_wasm;
|
extern crate cton_wasm;
|
||||||
extern crate faerie;
|
extern crate faerie;
|
||||||
extern crate wasmstandalone;
|
extern crate wasmstandalone_runtime;
|
||||||
|
|
||||||
mod emit_module;
|
mod emit_module;
|
||||||
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasmstandalone"
|
name = "wasmstandalone_runtime"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
authors = ["The Cretonne Project Developers"]
|
authors = ["The Cretonne Project Developers"]
|
||||||
publish = false
|
publish = false
|
||||||
description = "Standalone JIT-style runtime support for WebAsssembly code in Cretonne"
|
description = "Standalone runtime support for WebAsssembly code in Cretonne"
|
||||||
repository = "https://github.com/stoklund/cretonne"
|
repository = "https://github.com/sunfishcode/wasmstandalone"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cretonne = { git = "https://github.com/stoklund/cretonne.git" }
|
cretonne = { git = "https://github.com/stoklund/cretonne.git" }
|
||||||
cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" }
|
cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" }
|
||||||
region = "0.0.8"
|
|
||||||
@@ -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,
|
use cton_wasm::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, Global, GlobalInit, Table,
|
||||||
Memory, WasmRuntime, FuncEnvironment, GlobalValue, SignatureIndex};
|
Memory, WasmRuntime, FuncEnvironment, GlobalValue, SignatureIndex};
|
||||||
use cretonne::ir::{InstBuilder, FuncRef, ExtFuncData, FunctionName, Signature, ArgumentType,
|
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::copy_nonoverlapping;
|
||||||
use std::ptr::write;
|
use std::ptr::write;
|
||||||
|
|
||||||
|
/// Runtime state of a WebAssembly table element.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum TableElement {
|
pub enum TableElement {
|
||||||
|
/// A element that, if called, produces a trap.
|
||||||
Trap(),
|
Trap(),
|
||||||
|
/// A function.
|
||||||
Function(FunctionIndex),
|
Function(FunctionIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GlobalInfo {
|
/// Information about a WebAssembly global variable.
|
||||||
|
pub struct GlobalInfo {
|
||||||
global: Global,
|
global: Global,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runtime state of a WebAssembly global variable.
|
||||||
pub struct GlobalsData {
|
pub struct GlobalsData {
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
info: Vec<GlobalInfo>,
|
info: Vec<GlobalInfo>,
|
||||||
@@ -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;
|
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
extern crate cton_wasm;
|
extern crate cton_wasm;
|
||||||
extern crate cton_native;
|
extern crate cton_native;
|
||||||
extern crate wasmstandalone;
|
extern crate wasmstandalone_runtime;
|
||||||
|
extern crate wasmstandalone_execute;
|
||||||
extern crate wasmparser;
|
extern crate wasmparser;
|
||||||
extern crate cretonne;
|
extern crate cretonne;
|
||||||
extern crate wasmtext;
|
extern crate wasmtext;
|
||||||
@@ -18,7 +19,7 @@ extern crate term;
|
|||||||
extern crate tempdir;
|
extern crate tempdir;
|
||||||
|
|
||||||
use cton_wasm::{translate_module, TranslationResult};
|
use cton_wasm::{translate_module, TranslationResult};
|
||||||
use wasmstandalone::{compile_module, execute};
|
use wasmstandalone_execute::{compile_module, execute};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use wasmparser::{Parser, ParserState, WasmDecoder, SectionCode};
|
use wasmparser::{Parser, ParserState, WasmDecoder, SectionCode};
|
||||||
use wasmtext::Writer;
|
use wasmtext::Writer;
|
||||||
@@ -157,7 +158,7 @@ fn handle_module(args: &Args, path: PathBuf, name: &str, isa: &TargetIsa) -> Res
|
|||||||
|err| String::from(err.description()),
|
|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 = {
|
let translation = {
|
||||||
match translate_module(&data, &mut runtime) {
|
match translate_module(&data, &mut runtime) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
@@ -320,7 +321,7 @@ fn pretty_print_translation(
|
|||||||
writer_wat: &mut Write,
|
writer_wat: &mut Write,
|
||||||
writer_cretonne: &mut Write,
|
writer_cretonne: &mut Write,
|
||||||
isa: &TargetIsa,
|
isa: &TargetIsa,
|
||||||
runtime: &wasmstandalone::Runtime,
|
runtime: &wasmstandalone_runtime::Runtime,
|
||||||
) -> Result<(), io::Error> {
|
) -> Result<(), io::Error> {
|
||||||
let mut terminal = term::stdout().unwrap();
|
let mut terminal = term::stdout().unwrap();
|
||||||
let mut parser = Parser::new(data);
|
let mut parser = Parser::new(data);
|
||||||
|
|||||||
@@ -5,19 +5,19 @@
|
|||||||
//! object file with relocations.
|
//! object file with relocations.
|
||||||
|
|
||||||
extern crate cton_wasm;
|
extern crate cton_wasm;
|
||||||
extern crate wasm2obj;
|
extern crate wasmstandalone_obj;
|
||||||
|
extern crate wasmstandalone_runtime;
|
||||||
extern crate cretonne;
|
extern crate cretonne;
|
||||||
extern crate cton_native;
|
extern crate cton_native;
|
||||||
extern crate docopt;
|
extern crate docopt;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate wasmstandalone;
|
|
||||||
extern crate faerie;
|
extern crate faerie;
|
||||||
|
|
||||||
use cton_wasm::translate_module;
|
use cton_wasm::translate_module;
|
||||||
use cretonne::settings;
|
use cretonne::settings;
|
||||||
use cretonne::isa;
|
use cretonne::isa;
|
||||||
use wasm2obj::emit_module;
|
use wasmstandalone_obj::emit_module;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::error::Error;
|
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 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 = {
|
let translation = {
|
||||||
match translate_module(&data, &mut runtime) {
|
match translate_module(&data, &mut runtime) {
|
||||||
|
|||||||
Reference in New Issue
Block a user