Split the runtime and execution code into separate crates.

This commit is contained in:
Dan Gohman
2017-10-03 14:57:52 -07:00
parent 6ded83332f
commit 23bafd1218
13 changed files with 62 additions and 40 deletions

14
lib/execute/Cargo.toml Normal file
View 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" }

View File

@@ -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<ExecutableCode, String> {
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<Vec<u8>>,
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() {

View File

@@ -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" }

View File

@@ -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() ||

View File

@@ -1,7 +1,7 @@
extern crate cretonne;
extern crate cton_wasm;
extern crate faerie;
extern crate wasmstandalone;
extern crate wasmstandalone_runtime;
mod emit_module;

View File

@@ -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"

View File

@@ -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<u8>,
info: Vec<GlobalInfo>,

View File

@@ -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;