Rename SimpleJIT to JIT as it isn't simple anymore
This commit is contained in:
42
Cargo.lock
generated
42
Cargo.lock
generated
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -52,6 +52,6 @@
|
||||
emits native object files using the
|
||||
`object <https://github.com/gimli-rs/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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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();
|
||||
@@ -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<dyn TargetIsa>,
|
||||
symbols: HashMap<String, *const u8>,
|
||||
libcall_names: Box<dyn Fn(ir::LibCall) -> 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<dyn TargetIsa>,
|
||||
hotswap_enabled: bool,
|
||||
symbols: HashMap<String, *const u8>,
|
||||
@@ -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<DataId> {
|
||||
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<RelocRecord>,
|
||||
}
|
||||
|
||||
impl RelocSink for SimpleJITRelocSink {
|
||||
impl RelocSink for JITRelocSink {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
offset: CodeOffset,
|
||||
@@ -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");
|
||||
@@ -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![],
|
||||
@@ -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
|
||||
|
||||
@@ -39,7 +39,7 @@ const CRATES_TO_PUBLISH: &[&str] = &[
|
||||
"cranelift-object",
|
||||
"cranelift-interpreter",
|
||||
"cranelift",
|
||||
"cranelift-simplejit",
|
||||
"cranelift-jit",
|
||||
// wig/wiggle
|
||||
"wiggle-generate",
|
||||
"wiggle-macro",
|
||||
|
||||
Reference in New Issue
Block a user