diff --git a/Cargo.lock b/Cargo.lock index 6f458b7096..844b60b4bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -462,6 +462,26 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cranelift-jit" +version = "0.68.0" +dependencies = [ + "anyhow", + "cranelift", + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "cranelift-module", + "cranelift-native", + "errno", + "libc", + "log", + "memmap", + "region", + "target-lexicon", + "winapi", +] + [[package]] name = "cranelift-module" version = "0.68.0" @@ -527,26 +547,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "cranelift-simplejit" -version = "0.68.0" -dependencies = [ - "anyhow", - "cranelift", - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "cranelift-module", - "cranelift-native", - "errno", - "libc", - "log", - "memmap", - "region", - "target-lexicon", - "winapi", -] - [[package]] name = "cranelift-tools" version = "0.66.0" @@ -560,13 +560,13 @@ dependencies = [ "cranelift-filetests", "cranelift-frontend", "cranelift-interpreter", + "cranelift-jit", "cranelift-module", "cranelift-native", "cranelift-object", "cranelift-preopt", "cranelift-reader", "cranelift-serde", - "cranelift-simplejit", "cranelift-wasm", "file-per-thread-logger", "filecheck", diff --git a/cranelift/Cargo.toml b/cranelift/Cargo.toml index 9594f22bf0..cd33d160a2 100644 --- a/cranelift/Cargo.toml +++ b/cranelift/Cargo.toml @@ -26,7 +26,7 @@ cranelift-native = { path = "native", version = "0.68.0" } cranelift-filetests = { path = "filetests", version = "0.66.0" } cranelift-module = { path = "module", version = "0.68.0" } cranelift-object = { path = "object", version = "0.68.0" } -cranelift-simplejit = { path = "simplejit", version = "0.68.0" } +cranelift-jit = { path = "jit", version = "0.68.0" } cranelift-preopt = { path = "preopt", version = "0.68.0" } cranelift = { path = "umbrella", version = "0.68.0" } filecheck = "0.5.0" diff --git a/cranelift/README.md b/cranelift/README.md index 7f35e570f7..52d4e0cf8f 100644 --- a/cranelift/README.md +++ b/cranelift/README.md @@ -16,10 +16,10 @@ into executable machine code. For more information, see [the documentation](docs/index.md). -For an example of how to use the JIT, see the [SimpleJIT Demo], which +For an example of how to use the JIT, see the [JIT Demo], which implements a toy language. -[SimpleJIT Demo]: https://github.com/bytecodealliance/simplejit-demo +[JIT Demo]: https://github.com/bytecodealliance/simplejit-demo For an example of how to use Cranelift to run WebAssembly code, see [Wasmtime], which implements a standalone, embeddable, VM using Cranelift. diff --git a/cranelift/docs/index.md b/cranelift/docs/index.md index 2334325f15..62c4e51bd8 100644 --- a/cranelift/docs/index.md +++ b/cranelift/docs/index.md @@ -52,6 +52,6 @@ emits native object files using the `object `_ library. - - [cranelift-simplejit](https://docs.rs/cranelift-simplejit) - This crate provides a simple JIT backend for `cranelift-module`, which + - [cranelift-jit](https://docs.rs/cranelift-jit) + This crate provides a JIT backend for `cranelift-module`, which emits code and data into memory. diff --git a/cranelift/filetests/src/function_runner.rs b/cranelift/filetests/src/function_runner.rs index ed8411f448..01ddc1f3dd 100644 --- a/cranelift/filetests/src/function_runner.rs +++ b/cranelift/filetests/src/function_runner.rs @@ -21,7 +21,7 @@ use thiserror::Error; /// `CompiledFunction`s and subsequently calling them through the use of a `Trampoline`. As its /// name indicates, this compiler is limited: any functionality that requires knowledge of things /// outside the [Function] will likely not work (e.g. global values, calls). For an example of this -/// "outside-of-function" functionality, see `cranelift_simplejit::backend::SimpleJITBackend`. +/// "outside-of-function" functionality, see `cranelift_jit::backend::JITBackend`. /// /// ``` /// use cranelift_filetests::SingleFunctionCompiler; diff --git a/cranelift/simplejit/Cargo.toml b/cranelift/jit/Cargo.toml similarity index 89% rename from cranelift/simplejit/Cargo.toml rename to cranelift/jit/Cargo.toml index ea8165035a..1b07e23c86 100644 --- a/cranelift/simplejit/Cargo.toml +++ b/cranelift/jit/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "cranelift-simplejit" +name = "cranelift-jit" version = "0.68.0" authors = ["The Cranelift Project Developers"] -description = "A simple JIT library backed by Cranelift" +description = "A JIT library backed by Cranelift" repository = "https://github.com/bytecodealliance/wasmtime" -documentation = "https://docs.rs/cranelift-simplejit" +documentation = "https://docs.rs/cranelift-jit" license = "Apache-2.0 WITH LLVM-exception" readme = "README.md" edition = "2018" diff --git a/cranelift/simplejit/LICENSE b/cranelift/jit/LICENSE similarity index 100% rename from cranelift/simplejit/LICENSE rename to cranelift/jit/LICENSE diff --git a/cranelift/simplejit/README.md b/cranelift/jit/README.md similarity index 66% rename from cranelift/simplejit/README.md rename to cranelift/jit/README.md index c3b0693b17..652f181fc8 100644 --- a/cranelift/simplejit/README.md +++ b/cranelift/jit/README.md @@ -1,8 +1,8 @@ -This crate provides a simple JIT library that uses +This crate provides a JIT library that uses [Cranelift](https://crates.io/crates/cranelift). This crate is extremely experimental. See the [example program] for a brief overview of how to use this. -[example program]: https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/simplejit/examples/simplejit-minimal.rs +[example program]: https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/jit/examples/jit-minimal.rs diff --git a/cranelift/simplejit/examples/simplejit-minimal.rs b/cranelift/jit/examples/jit-minimal.rs similarity index 94% rename from cranelift/simplejit/examples/simplejit-minimal.rs rename to cranelift/jit/examples/jit-minimal.rs index 7274c4d5e7..138c545831 100644 --- a/cranelift/simplejit/examples/simplejit-minimal.rs +++ b/cranelift/jit/examples/jit-minimal.rs @@ -1,8 +1,8 @@ use cranelift::prelude::*; use cranelift_codegen::binemit::NullTrapSink; use cranelift_codegen::settings::{self, Configurable}; +use cranelift_jit::{JITBuilder, JITModule}; use cranelift_module::{default_libcall_names, Linkage, Module}; -use cranelift_simplejit::{SimpleJITBuilder, SimpleJITModule}; use std::mem; fn main() { @@ -14,8 +14,7 @@ fn main() { panic!("host machine is not supported: {}", msg); }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut module: SimpleJITModule = - SimpleJITModule::new(SimpleJITBuilder::with_isa(isa, default_libcall_names())); + let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); let mut ctx = module.make_context(); let mut func_ctx = FunctionBuilderContext::new(); diff --git a/cranelift/simplejit/src/backend.rs b/cranelift/jit/src/backend.rs similarity index 96% rename from cranelift/simplejit/src/backend.rs rename to cranelift/jit/src/backend.rs index 67ba0f8a37..418b26ef58 100644 --- a/cranelift/simplejit/src/backend.rs +++ b/cranelift/jit/src/backend.rs @@ -1,4 +1,4 @@ -//! Defines `SimpleJITModule`. +//! Defines `JITModule`. use crate::{compiled_blob::CompiledBlob, memory::Memory}; use cranelift_codegen::isa::TargetIsa; @@ -31,16 +31,16 @@ const EXECUTABLE_DATA_ALIGNMENT: u64 = 0x10; const WRITABLE_DATA_ALIGNMENT: u64 = 0x8; const READONLY_DATA_ALIGNMENT: u64 = 0x1; -/// A builder for `SimpleJITModule`. -pub struct SimpleJITBuilder { +/// A builder for `JITModule`. +pub struct JITBuilder { isa: Box, symbols: HashMap, libcall_names: Box String + Send + Sync>, hotswap_enabled: bool, } -impl SimpleJITBuilder { - /// Create a new `SimpleJITBuilder`. +impl JITBuilder { + /// Create a new `JITBuilder`. /// /// The `libcall_names` function provides a way to translate `cranelift_codegen`'s `ir::LibCall` /// enum to symbols. LibCalls are inserted in the IR as part of the legalization for certain @@ -60,12 +60,10 @@ impl SimpleJITBuilder { Self::with_isa(isa, libcall_names) } - /// Create a new `SimpleJITBuilder` with an arbitrary target. This is mainly + /// Create a new `JITBuilder` with an arbitrary target. This is mainly /// useful for testing. /// - /// SimpleJIT requires a `TargetIsa` configured for non-PIC. - /// - /// To create a `SimpleJITBuilder` for native use, use the `new` constructor + /// To create a `JITBuilder` for native use, use the `new` constructor /// instead. /// /// The `libcall_names` function provides a way to translate `cranelift_codegen`'s `ir::LibCall` @@ -121,19 +119,21 @@ impl SimpleJITBuilder { self } - /// Enable or disable hotswap support. See [`SimpleJITModule::prepare_for_function_redefine`] + /// Enable or disable hotswap support. See [`JITModule::prepare_for_function_redefine`] /// for more information. + /// + /// Enabling hotswap support requires PIC code. pub fn hotswap(&mut self, enabled: bool) -> &mut Self { self.hotswap_enabled = enabled; self } } -/// A `SimpleJITModule` implements `Module` and emits code and data into memory where it can be +/// A `JITModule` implements `Module` and emits code and data into memory where it can be /// directly called and accessed. /// -/// See the `SimpleJITBuilder` for a convenient way to construct `SimpleJITModule` instances. -pub struct SimpleJITModule { +/// See the `JITBuilder` for a convenient way to construct `JITModule` instances. +pub struct JITModule { isa: Box, hotswap_enabled: bool, symbols: HashMap, @@ -158,7 +158,7 @@ struct MemoryHandle { writable: Memory, } -impl SimpleJITModule { +impl JITModule { /// Free memory allocated for code and data segments of compiled functions. /// /// # Safety @@ -369,8 +369,8 @@ impl SimpleJITModule { self.memory.code.set_readable_and_executable(); } - /// Create a new `SimpleJITModule`. - pub fn new(builder: SimpleJITBuilder) -> Self { + /// Create a new `JITModule`. + pub fn new(builder: JITBuilder) -> Self { if builder.hotswap_enabled { assert!( builder.isa.flags().is_pic(), @@ -450,7 +450,7 @@ impl SimpleJITModule { /// Allow a single future `define_function` on a previously defined function. This allows for /// hot code swapping and lazy compilation of functions. /// - /// This requires hotswap support to be enabled first using [`SimpleJITBuilder::hotswap`]. + /// This requires hotswap support to be enabled first using [`JITBuilder::hotswap`]. pub fn prepare_for_function_redefine(&mut self, func_id: FuncId) -> ModuleResult<()> { assert!(self.hotswap_enabled, "Hotswap support is not enabled"); let decl = self.declarations.get_function_decl(func_id); @@ -473,7 +473,7 @@ impl SimpleJITModule { } } -impl<'simple_jit_backend> Module for SimpleJITModule { +impl Module for JITModule { fn isa(&self) -> &dyn TargetIsa { &*self.isa } @@ -533,7 +533,7 @@ impl<'simple_jit_backend> Module for SimpleJITModule { writable: bool, tls: bool, ) -> ModuleResult { - assert!(!tls, "SimpleJIT doesn't yet support TLS"); + assert!(!tls, "JIT doesn't yet support TLS"); let (id, _decl) = self .declarations .declare_data(name, linkage, writable, tls)?; @@ -627,7 +627,7 @@ impl<'simple_jit_backend> Module for SimpleJITModule { .allocate(size, EXECUTABLE_DATA_ALIGNMENT) .expect("TODO: handle OOM etc."); - let mut reloc_sink = SimpleJITRelocSink::default(); + let mut reloc_sink = JITRelocSink::default(); let mut stack_map_sink = binemit::NullStackMapSink {}; unsafe { ctx.emit_to_memory( @@ -750,7 +750,7 @@ impl<'simple_jit_backend> Module for SimpleJITModule { return Err(ModuleError::DuplicateDefinition(decl.name.to_owned())); } - assert!(!decl.tls, "SimpleJIT doesn't yet support TLS"); + assert!(!decl.tls, "JIT doesn't yet support TLS"); let &DataDescription { ref init, @@ -850,11 +850,11 @@ fn lookup_with_dlsym(name: &str) -> Option<*const u8> { } #[derive(Default)] -struct SimpleJITRelocSink { +struct JITRelocSink { relocs: Vec, } -impl RelocSink for SimpleJITRelocSink { +impl RelocSink for JITRelocSink { fn reloc_external( &mut self, offset: CodeOffset, diff --git a/cranelift/simplejit/src/compiled_blob.rs b/cranelift/jit/src/compiled_blob.rs similarity index 100% rename from cranelift/simplejit/src/compiled_blob.rs rename to cranelift/jit/src/compiled_blob.rs diff --git a/cranelift/simplejit/src/lib.rs b/cranelift/jit/src/lib.rs similarity index 87% rename from cranelift/simplejit/src/lib.rs rename to cranelift/jit/src/lib.rs index d558b44396..6e66ca8dd6 100644 --- a/cranelift/simplejit/src/lib.rs +++ b/cranelift/jit/src/lib.rs @@ -1,4 +1,4 @@ -//! Top-level lib.rs for `cranelift_simplejit`. +//! Top-level lib.rs for `cranelift_jit`. #![deny( missing_docs, @@ -27,7 +27,7 @@ mod backend; mod compiled_blob; mod memory; -pub use crate::backend::{SimpleJITBuilder, SimpleJITModule}; +pub use crate::backend::{JITBuilder, JITModule}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/cranelift/simplejit/src/memory.rs b/cranelift/jit/src/memory.rs similarity index 100% rename from cranelift/simplejit/src/memory.rs rename to cranelift/jit/src/memory.rs diff --git a/cranelift/simplejit/tests/basic.rs b/cranelift/jit/tests/basic.rs similarity index 93% rename from cranelift/simplejit/tests/basic.rs rename to cranelift/jit/tests/basic.rs index fc3f5b0056..9e7e3cbe52 100644 --- a/cranelift/simplejit/tests/basic.rs +++ b/cranelift/jit/tests/basic.rs @@ -5,8 +5,8 @@ use cranelift_codegen::settings::{self, Configurable}; use cranelift_codegen::{ir::types::I16, Context}; use cranelift_entity::EntityRef; use cranelift_frontend::*; +use cranelift_jit::*; use cranelift_module::*; -use cranelift_simplejit::*; #[test] fn error_on_incompatible_sig_in_declare_function() { @@ -18,8 +18,7 @@ fn error_on_incompatible_sig_in_declare_function() { panic!("host machine is not supported: {}", msg); }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut module: SimpleJITModule = - SimpleJITModule::new(SimpleJITBuilder::with_isa(isa, default_libcall_names())); + let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); let mut sig = Signature { params: vec![AbiParam::new(types::I64)], @@ -36,7 +35,7 @@ fn error_on_incompatible_sig_in_declare_function() { .unwrap(); // Make sure this is an error } -fn define_simple_function(module: &mut SimpleJITModule) -> FuncId { +fn define_simple_function(module: &mut JITModule) -> FuncId { let sig = Signature { params: vec![], returns: vec![], @@ -76,8 +75,7 @@ fn panic_on_define_after_finalize() { panic!("host machine is not supported: {}", msg); }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut module: SimpleJITModule = - SimpleJITModule::new(SimpleJITBuilder::with_isa(isa, default_libcall_names())); + let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); define_simple_function(&mut module); define_simple_function(&mut module); @@ -166,8 +164,7 @@ fn libcall_function() { panic!("host machine is not supported: {}", msg); }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut module: SimpleJITModule = - SimpleJITModule::new(SimpleJITBuilder::with_isa(isa, default_libcall_names())); + let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); let sig = Signature { params: vec![], diff --git a/cranelift/module/README.md b/cranelift/module/README.md index 1727975f96..09caf7e270 100644 --- a/cranelift/module/README.md +++ b/cranelift/module/README.md @@ -10,10 +10,8 @@ A module is a collection of functions and data objects that are linked together. The `Module` trait that defines a common interface for various kinds of modules. Most users will use one of the following `Module` implementations: - - `SimpleJITModule`, provided by [cranelift-simplejit], which JITs - code to memory for direct execution. - - `ObjectModule`, provided by [cranelift-object], which emits native - object files. + - `JITModule`, provided by [cranelift-jit], which JITs code to memory for direct execution. + - `ObjectModule`, provided by [cranelift-object], which emits native object files. -[cranelift-simplejit]: https://crates.io/crates/cranelift-simplejit +[cranelift-jit]: https://crates.io/crates/cranelift-jit [cranelift-object]: https://crates.io/crates/cranelift-object diff --git a/scripts/publish.rs b/scripts/publish.rs index a56e03b351..330a7e0dfb 100644 --- a/scripts/publish.rs +++ b/scripts/publish.rs @@ -39,7 +39,7 @@ const CRATES_TO_PUBLISH: &[&str] = &[ "cranelift-object", "cranelift-interpreter", "cranelift", - "cranelift-simplejit", + "cranelift-jit", // wig/wiggle "wiggle-generate", "wiggle-macro",