Update to cranelift 0.16.1, target-lexicon 0.0.3, faerie 0.4.4.

This commit is contained in:
Dan Gohman
2018-07-20 15:31:04 -07:00
parent 7a26b76521
commit 2608dd0c47
16 changed files with 94 additions and 92 deletions

2
.gitignore vendored
View File

@@ -7,6 +7,6 @@ tags
target target
Cargo.lock Cargo.lock
.*.rustfmt .*.rustfmt
cretonne.dbg* cranelift.dbg*
.mypy_cache .mypy_cache
rusty-tags.* rusty-tags.*

View File

@@ -1,10 +1,10 @@
[package] [package]
name = "wasmtime_tools" name = "wasmtime_tools"
authors = ["The Cretonne Project Developers"] authors = ["The Cranelift Project Developers"]
version = "0.0.0" version = "0.0.0"
description = "Command-line interface for the wasmtime crate" description = "Command-line interface for the wasmtime crate"
license = "Apache-2.0 WITH LLVM-exception" license = "Apache-2.0 WITH LLVM-exception"
documentation = "https://cretonne.readthedocs.io/" documentation = "https://cranelift.readthedocs.io/"
repository = "https://github.com/sunfishcode/wasmtime" repository = "https://github.com/sunfishcode/wasmtime"
publish = false publish = false
@@ -17,11 +17,11 @@ name = "wasm2obj"
path = "src/wasm2obj.rs" path = "src/wasm2obj.rs"
[dependencies] [dependencies]
cretonne-codegen = "0.13.0" cranelift-codegen = "0.16.1"
cretonne-frontend = "0.13.0" cranelift-frontend = "0.16.1"
cretonne-reader = "0.13.0" cranelift-reader = "0.16.1"
cretonne-wasm = "0.13.0" cranelift-wasm = "0.16.1"
cretonne-native = "0.13.0" cranelift-native = "0.16.1"
wasmtime_runtime = { path = "lib/runtime" } wasmtime_runtime = { path = "lib/runtime" }
wasmtime_execute = { path = "lib/execute" } wasmtime_execute = { path = "lib/execute" }
wasmtime_obj = { path = "lib/obj" } wasmtime_obj = { path = "lib/obj" }
@@ -29,6 +29,6 @@ docopt = "1.0.0"
serde = "1.0.55" serde = "1.0.55"
serde_derive = "1.0.55" serde_derive = "1.0.55"
tempdir = "*" tempdir = "*"
faerie = "0.4.2" faerie = "0.4.4"
[workspace] [workspace]

View File

@@ -1,4 +1,4 @@
# wasmtime # wasmtime
Standalone JIT-style runtime support for WebAsssembly code in Cretonne Standalone JIT-style runtime support for WebAsssembly code in Cranelift
*This is a work in progress that is not currently functional.* *This is a work in progress that is not currently functional.*

View File

@@ -1,7 +1,7 @@
[package] [package]
name = "wasmtime_fuzz" name = "wasmtime_fuzz"
version = "0.0.1" version = "0.0.1"
authors = ["The Cretonne Project Developers"] authors = ["The Cranelift Project Developers"]
publish = false publish = false
[package.metadata] [package.metadata]
@@ -13,13 +13,13 @@ path = "../lib/runtime"
[dependencies.wasmtime_execute] [dependencies.wasmtime_execute]
path = "../lib/execute" path = "../lib/execute"
[dependencies.cretonne-codegen] [dependencies.cranelift-codegen]
version = "0.8.0" version = "0.8.0"
[dependencies.cretonne-wasm] [dependencies.cranelift-wasm]
version = "0.8.0" version = "0.8.0"
[dependencies.cretonne-native] [dependencies.cranelift-native]
version = "0.8.0" version = "0.8.0"
[dependencies.libfuzzer-sys] [dependencies.libfuzzer-sys]

View File

@@ -2,17 +2,17 @@
#[macro_use] #[macro_use]
extern crate libfuzzer_sys; extern crate libfuzzer_sys;
extern crate cretonne; extern crate cranelift;
extern crate cton_wasm; extern crate cranelift_wasm;
extern crate cton_native; extern crate cranelift_native;
extern crate wasmtime_runtime; extern crate wasmtime_runtime;
extern crate wasmtime_execute; extern crate wasmtime_execute;
use cretonne::settings; use cranelift::settings;
use cton_wasm::translate_module; use cranelift_wasm::translate_module;
fuzz_target!(|data: &[u8]| { fuzz_target!(|data: &[u8]| {
let (flag_builder, isa_builder) = cton_native::builders().unwrap_or_else(|_| { let (flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| {
panic!("host machine is not a supported target"); panic!("host machine is not a supported target");
}); });
let isa = isa_builder.finish(settings::Flags::new(&flag_builder)); let isa = isa_builder.finish(settings::Flags::new(&flag_builder));

View File

@@ -1,14 +1,14 @@
[package] [package]
name = "wasmtime_execute" name = "wasmtime_execute"
version = "0.0.0" version = "0.0.0"
authors = ["The Cretonne Project Developers"] authors = ["The Cranelift Project Developers"]
publish = false publish = false
description = "JIT-style runtime support for WebAsssembly code in Cretonne" description = "JIT-style runtime support for WebAsssembly code in Cranelift"
repository = "https://github.com/sunfishcode/wasmtime" repository = "https://github.com/sunfishcode/wasmtime"
license = "Apache-2.0 WITH LLVM-exception" license = "Apache-2.0 WITH LLVM-exception"
[dependencies] [dependencies]
cretonne-codegen = "0.13.0" cranelift-codegen = "0.16.1"
cretonne-wasm = "0.13.0" cranelift-wasm = "0.16.1"
region = "0.3.0" region = "0.3.0"
wasmtime_runtime = { path = "../runtime" } wasmtime_runtime = { path = "../runtime" }

View File

@@ -1,14 +1,14 @@
//! JIT-style runtime for WebAssembly using Cretonne. //! JIT-style runtime for WebAssembly using Cranelift.
#![deny(missing_docs)] #![deny(missing_docs)]
extern crate cretonne_codegen; extern crate cranelift_codegen;
extern crate cretonne_wasm; extern crate cranelift_wasm;
extern crate region; extern crate region;
extern crate wasmtime_runtime; extern crate wasmtime_runtime;
use cretonne_codegen::binemit::Reloc; use cranelift_codegen::binemit::Reloc;
use cretonne_codegen::isa::TargetIsa; use cranelift_codegen::isa::TargetIsa;
use region::protect; use region::protect;
use region::Protection; use region::Protection;
use std::mem::transmute; use std::mem::transmute;

View File

@@ -1,12 +1,12 @@
[package] [package]
name = "wasmtime_obj" name = "wasmtime_obj"
version = "0.0.0" version = "0.0.0"
authors = ["The Cretonne Project Developers"] authors = ["The Cranelift Project Developers"]
publish = false publish = false
license = "Apache-2.0 WITH LLVM-exception" license = "Apache-2.0 WITH LLVM-exception"
[dependencies] [dependencies]
cretonne-codegen = "0.13.0" cranelift-codegen = "0.16.1"
cretonne-wasm = "0.13.0" cranelift-wasm = "0.16.1"
wasmtime_runtime = { path = "../runtime" } wasmtime_runtime = { path = "../runtime" }
faerie = "0.4.2" faerie = "0.4.4"

View File

@@ -1,5 +1,5 @@
use cretonne_codegen::settings; use cranelift_codegen::settings;
use cretonne_codegen::settings::Configurable; use cranelift_codegen::settings::Configurable;
use faerie::Artifact; use faerie::Artifact;
use wasmtime_runtime; use wasmtime_runtime;

View File

@@ -1,5 +1,5 @@
extern crate cretonne_codegen; extern crate cranelift_codegen;
extern crate cretonne_wasm; extern crate cranelift_wasm;
extern crate faerie; extern crate faerie;
extern crate wasmtime_runtime; extern crate wasmtime_runtime;

View File

@@ -1,14 +1,14 @@
[package] [package]
name = "wasmtime_runtime" name = "wasmtime_runtime"
version = "0.0.0" version = "0.0.0"
authors = ["The Cretonne Project Developers"] authors = ["The Cranelift Project Developers"]
publish = false publish = false
description = "Standalone runtime support for WebAsssembly code in Cretonne" description = "Standalone runtime support for WebAsssembly code in Cranelift"
repository = "https://github.com/sunfishcode/wasmtime" repository = "https://github.com/sunfishcode/wasmtime"
license = "Apache-2.0 WITH LLVM-exception" license = "Apache-2.0 WITH LLVM-exception"
[dependencies] [dependencies]
cretonne-codegen = "0.13.0" cranelift-codegen = "0.16.1"
cretonne-wasm = "0.13.0" cranelift-wasm = "0.16.1"
wasmparser = "0.17.0" wasmparser = "0.17.2"
target-lexicon = "0.0.2" target-lexicon = "0.0.3"

View File

@@ -1,8 +1,8 @@
//! An `Instance` contains all the runtime state used by execution of a wasm //! An `Instance` contains all the runtime state used by execution of a wasm
//! module. //! module.
use cretonne_codegen::ir; use cranelift_codegen::ir;
use cretonne_wasm::GlobalIndex; use cranelift_wasm::GlobalIndex;
use module::{Module, TableElements}; use module::{Module, TableElements};
use DataInitializer; use DataInitializer;

View File

@@ -1,12 +1,12 @@
//! Standalone runtime for WebAssembly using Cretonne. Provides functions to translate //! Standalone runtime for WebAssembly using Cranelift. Provides functions to translate
//! `get_global`, `set_global`, `current_memory`, `grow_memory`, `call_indirect` that hardcode in //! `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 //! the translation the base addresses of regions of memory that will hold the globals, tables and
//! linear memories. //! linear memories.
#![deny(missing_docs)] #![deny(missing_docs)]
extern crate cretonne_codegen; extern crate cranelift_codegen;
extern crate cretonne_wasm; extern crate cranelift_wasm;
extern crate target_lexicon; extern crate target_lexicon;
extern crate wasmparser; extern crate wasmparser;
@@ -18,25 +18,25 @@ pub use compilation::Compilation;
pub use instance::Instance; pub use instance::Instance;
pub use module::Module; pub use module::Module;
use cretonne_codegen::binemit; use cranelift_codegen::binemit;
use cretonne_codegen::cursor::FuncCursor; use cranelift_codegen::cursor::FuncCursor;
use cretonne_codegen::ir; use cranelift_codegen::ir;
use cretonne_codegen::ir::immediates::Offset32; use cranelift_codegen::ir::immediates::Offset32;
use cretonne_codegen::ir::types::*; use cranelift_codegen::ir::types::*;
use cretonne_codegen::ir::{ use cranelift_codegen::ir::{
AbiParam, ArgumentExtension, ArgumentLoc, ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, AbiParam, ArgumentExtension, ArgumentLoc, ArgumentPurpose, ExtFuncData, ExternalName, FuncRef,
Function, InstBuilder, Signature, Function, InstBuilder, Signature,
}; };
use cretonne_codegen::isa; use cranelift_codegen::isa;
use cretonne_codegen::settings; use cranelift_codegen::settings;
use cretonne_wasm::{ use cranelift_wasm::{
FuncTranslator, FunctionIndex, Global, GlobalIndex, GlobalVariable, Memory, MemoryIndex, FuncTranslator, FunctionIndex, Global, GlobalIndex, GlobalVariable, Memory, MemoryIndex,
SignatureIndex, Table, TableIndex, WasmResult, SignatureIndex, Table, TableIndex, WasmResult,
}; };
use target_lexicon::Triple; use target_lexicon::Triple;
/// Compute a `ir::ExternalName` for a given wasm function index. /// Compute a `ir::ExternalName` for a given wasm function index.
pub fn get_func_name(func_index: FunctionIndex) -> cretonne_codegen::ir::ExternalName { pub fn get_func_name(func_index: FunctionIndex) -> cranelift_codegen::ir::ExternalName {
debug_assert!(func_index as u32 as FunctionIndex == func_index); debug_assert!(func_index as u32 as FunctionIndex == func_index);
ir::ExternalName::user(0, func_index as u32) ir::ExternalName::user(0, func_index as u32)
} }
@@ -140,7 +140,7 @@ impl<'data> LazyContents<'data> {
} }
/// Object containing the standalone runtime information. To be passed after creation as argument /// Object containing the standalone runtime information. To be passed after creation as argument
/// to `cretonne_wasm::translatemodule`. /// to `cranelift_wasm::translatemodule`.
pub struct ModuleEnvironment<'data, 'module> { pub struct ModuleEnvironment<'data, 'module> {
/// Compilation setting flags. /// Compilation setting flags.
pub isa: &'module isa::TargetIsa, pub isa: &'module isa::TargetIsa,
@@ -167,7 +167,7 @@ impl<'data, 'module> ModuleEnvironment<'data, 'module> {
} }
fn native_pointer(&self) -> ir::Type { fn native_pointer(&self) -> ir::Type {
use cretonne_wasm::FuncEnvironment; use cranelift_wasm::FuncEnvironment;
self.func_env().native_pointer() self.func_env().native_pointer()
} }
@@ -192,10 +192,10 @@ pub struct FuncEnvironment<'module_environment> {
/// The module-level environment which this function-level environment belongs to. /// The module-level environment which this function-level environment belongs to.
pub module: &'module_environment Module, pub module: &'module_environment Module,
/// The Cretonne global holding the base address of the memories vector. /// The Cranelift global holding the base address of the memories vector.
pub memories_base: Option<ir::GlobalValue>, pub memories_base: Option<ir::GlobalValue>,
/// The Cretonne global holding the base address of the globals vector. /// The Cranelift global holding the base address of the globals vector.
pub globals_base: Option<ir::GlobalValue>, pub globals_base: Option<ir::GlobalValue>,
/// The external function declaration for implementing wasm's `current_memory`. /// The external function declaration for implementing wasm's `current_memory`.
@@ -230,7 +230,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
} }
} }
impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'module_environment> { impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'module_environment> {
fn flags(&self) -> &settings::Flags { fn flags(&self) -> &settings::Flags {
&self.isa.flags() &self.isa.flags()
} }
@@ -322,7 +322,7 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo
callee: ir::Value, callee: ir::Value,
call_args: &[ir::Value], call_args: &[ir::Value],
) -> WasmResult<ir::Inst> { ) -> WasmResult<ir::Inst> {
// TODO: Cretonne's call_indirect doesn't implement bounds checking // TODO: Cranelift's call_indirect doesn't implement bounds checking
// or signature checking, so we need to implement it ourselves. // or signature checking, so we need to implement it ourselves.
debug_assert_eq!(table_index, 0, "non-default tables not supported yet"); debug_assert_eq!(table_index, 0, "non-default tables not supported yet");
let real_call_args = FuncEnvironment::get_real_call_args(pos.func, call_args); let real_call_args = FuncEnvironment::get_real_call_args(pos.func, call_args);
@@ -401,11 +401,13 @@ impl<'module_environment> cretonne_wasm::FuncEnvironment for FuncEnvironment<'mo
} }
/// This trait is useful for /// This trait is useful for
/// `cretonne_wasm::translatemodule` because it /// `cranelift_wasm::translatemodule` because it
/// tells how to translate runtime-dependent wasm instructions. These functions should not be /// tells how to translate runtime-dependent wasm instructions. These functions should not be
/// called by the user. /// called by the user.
impl<'data, 'module> cretonne_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data, 'module> { impl<'data, 'module> cranelift_wasm::ModuleEnvironment<'data>
fn get_func_name(&self, func_index: FunctionIndex) -> cretonne_codegen::ir::ExternalName { for ModuleEnvironment<'data, 'module>
{
fn get_func_name(&self, func_index: FunctionIndex) -> cranelift_codegen::ir::ExternalName {
get_func_name(func_index) get_func_name(func_index)
} }
@@ -458,7 +460,7 @@ impl<'data, 'module> cretonne_wasm::ModuleEnvironment<'data> for ModuleEnvironme
self.module.globals.push(global); self.module.globals.push(global);
} }
fn get_global(&self, global_index: GlobalIndex) -> &cretonne_wasm::Global { fn get_global(&self, global_index: GlobalIndex) -> &cranelift_wasm::Global {
&self.module.globals[global_index] &self.module.globals[global_index]
} }
@@ -581,7 +583,7 @@ impl<'data, 'module> ModuleTranslation<'data, 'module> {
let mut relocations = Vec::new(); let mut relocations = Vec::new();
for (i, input) in self.lazy.function_body_inputs.iter().enumerate() { for (i, input) in self.lazy.function_body_inputs.iter().enumerate() {
let func_index = i + self.module.imported_funcs.len(); let func_index = i + self.module.imported_funcs.len();
let mut context = cretonne_codegen::Context::new(); let mut context = cranelift_codegen::Context::new();
context.func.name = get_func_name(func_index); context.func.name = get_func_name(func_index);
context.func.signature = context.func.signature =
self.module.signatures[self.module.functions[func_index]].clone(); self.module.signatures[self.module.functions[func_index]].clone();

View File

@@ -1,8 +1,8 @@
//! A `Module` contains all the relevant information translated from a //! A `Module` contains all the relevant information translated from a
//! WebAssembly module. //! WebAssembly module.
use cretonne_codegen::ir; use cranelift_codegen::ir;
use cretonne_wasm::{ use cranelift_wasm::{
FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex, FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex,
}; };
use std::collections::HashMap; use std::collections::HashMap;

View File

@@ -1,13 +1,13 @@
//! CLI tool to use the functions provided by the [wasmtime](../wasmtime/index.html) //! CLI tool to use the functions provided by the [wasmtime](../wasmtime/index.html)
//! crate. //! crate.
//! //!
//! Reads Wasm binary files (one Wasm module per file), translates the functions' code to Cretonne //! Reads Wasm binary files (one Wasm module per file), translates the functions' code to Cranelift
//! IL. Can also executes the `start` function of the module by laying out the memories, globals //! IL. Can also executes the `start` function of the module by laying out the memories, globals
//! and tables, then emitting the translated code with hardcoded addresses to memory. //! and tables, then emitting the translated code with hardcoded addresses to memory.
extern crate cretonne_codegen; extern crate cranelift_codegen;
extern crate cretonne_native; extern crate cranelift_native;
extern crate cretonne_wasm; extern crate cranelift_wasm;
extern crate docopt; extern crate docopt;
extern crate wasmtime_execute; extern crate wasmtime_execute;
extern crate wasmtime_runtime; extern crate wasmtime_runtime;
@@ -15,10 +15,10 @@ extern crate wasmtime_runtime;
extern crate serde_derive; extern crate serde_derive;
extern crate tempdir; extern crate tempdir;
use cretonne_codegen::isa::TargetIsa; use cranelift_codegen::isa::TargetIsa;
use cretonne_codegen::settings; use cranelift_codegen::settings;
use cretonne_codegen::settings::Configurable; use cranelift_codegen::settings::Configurable;
use cretonne_wasm::translate_module; use cranelift_wasm::translate_module;
use docopt::Docopt; use docopt::Docopt;
use std::error::Error; use std::error::Error;
use std::fs::File; use std::fs::File;
@@ -33,8 +33,8 @@ use wasmtime_execute::{compile_module, execute};
use wasmtime_runtime::{Instance, Module, ModuleEnvironment}; use wasmtime_runtime::{Instance, Module, ModuleEnvironment};
const USAGE: &str = " const USAGE: &str = "
Wasm to Cretonne IL translation utility. Wasm to Cranelift IL translation utility.
Takes a binary WebAssembly module and returns its functions in Cretonne IL format. Takes a binary WebAssembly module and returns its functions in Cranelift IL format.
The translation is dependent on the environment chosen. The translation is dependent on the environment chosen.
Usage: Usage:
@@ -45,7 +45,7 @@ Options:
-o, --optimize runs optimization passes on the translated functions -o, --optimize runs optimization passes on the translated functions
-m, --memory interactive memory inspector after execution -m, --memory interactive memory inspector after execution
-h, --help print this help message -h, --help print this help message
--version print the Cretonne version --version print the Cranelift version
"; ";
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
@@ -70,7 +70,7 @@ fn main() {
.deserialize() .deserialize()
}) })
.unwrap_or_else(|e| e.exit()); .unwrap_or_else(|e| e.exit());
let (mut flag_builder, isa_builder) = cretonne_native::builders().unwrap_or_else(|_| { let (mut flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| {
panic!("host machine is not a supported target"); panic!("host machine is not a supported target");
}); });
@@ -101,7 +101,7 @@ fn main() {
fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), String> { fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), String> {
let mut data = read_to_end(path.clone()).map_err(|err| String::from(err.description()))?; let mut data = read_to_end(path.clone()).map_err(|err| String::from(err.description()))?;
if !data.starts_with(&[b'\0', b'a', b's', b'm']) { if !data.starts_with(&[b'\0', b'a', b's', b'm']) {
let tmp_dir = TempDir::new("cretonne-wasm").unwrap(); let tmp_dir = TempDir::new("cranelift-wasm").unwrap();
let file_path = tmp_dir.path().join("module.wasm"); let file_path = tmp_dir.path().join("module.wasm");
File::create(file_path.clone()).unwrap(); File::create(file_path.clone()).unwrap();
Command::new("wat2wasm") Command::new("wat2wasm")

View File

@@ -1,12 +1,12 @@
//! Translation from wasm to native object files. //! Translation from wasm to native object files.
//! //!
//! Reads a Wasm binary file, translates the functions' code to Cretonne //! Reads a Wasm binary file, translates the functions' code to Cranelift
//! IL, then translates it to native code, and writes it out to a native //! IL, then translates it to native code, and writes it out to a native
//! object file with relocations. //! object file with relocations.
extern crate cretonne_codegen; extern crate cranelift_codegen;
extern crate cretonne_native; extern crate cranelift_native;
extern crate cretonne_wasm; extern crate cranelift_wasm;
extern crate docopt; extern crate docopt;
extern crate wasmtime_obj; extern crate wasmtime_obj;
extern crate wasmtime_runtime; extern crate wasmtime_runtime;
@@ -14,8 +14,8 @@ extern crate wasmtime_runtime;
extern crate serde_derive; extern crate serde_derive;
extern crate faerie; extern crate faerie;
use cretonne_codegen::settings; use cranelift_codegen::settings;
use cretonne_wasm::translate_module; use cranelift_wasm::translate_module;
use docopt::Docopt; use docopt::Docopt;
use faerie::Artifact; use faerie::Artifact;
use std::error::Error; use std::error::Error;
@@ -41,7 +41,7 @@ Usage:
Options: Options:
-v, --verbose displays the module and translated functions -v, --verbose displays the module and translated functions
-h, --help print this help message -h, --help print this help message
--version print the Cretonne version --version print the Cranelift version
"; ";
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
@@ -85,7 +85,7 @@ fn handle_module(path: PathBuf, output: &str) -> Result<(), String> {
}; };
// FIXME: Make the target a parameter. // FIXME: Make the target a parameter.
let (flag_builder, isa_builder) = cretonne_native::builders().unwrap_or_else(|_| { let (flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| {
panic!("host machine is not a supported target"); panic!("host machine is not a supported target");
}); });
let isa = isa_builder.finish(settings::Flags::new(flag_builder)); let isa = isa_builder.finish(settings::Flags::new(flag_builder));