Rename Cretonne to Cranelift!
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//! This module contains the bulk of the interesting code performing the translation between
|
||||
//! WebAssembly and Cretonne IR.
|
||||
//! WebAssembly and Cranelift IR.
|
||||
//!
|
||||
//! The translation is done in one pass, opcode by opcode. Two main data structures are used during
|
||||
//! code translations: the value stack and the control stack. The value stack mimics the execution
|
||||
@@ -22,11 +22,11 @@
|
||||
//!
|
||||
//! That is why `translate_function_body` takes an object having the `WasmRuntime` trait as
|
||||
//! argument.
|
||||
use cretonne_codegen::ir::condcodes::{FloatCC, IntCC};
|
||||
use cretonne_codegen::ir::types::*;
|
||||
use cretonne_codegen::ir::{self, InstBuilder, JumpTableData, MemFlags};
|
||||
use cretonne_codegen::packed_option::ReservedValue;
|
||||
use cretonne_frontend::{FunctionBuilder, Variable};
|
||||
use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
|
||||
use cranelift_codegen::ir::types::*;
|
||||
use cranelift_codegen::ir::{self, InstBuilder, JumpTableData, MemFlags};
|
||||
use cranelift_codegen::packed_option::ReservedValue;
|
||||
use cranelift_frontend::{FunctionBuilder, Variable};
|
||||
use environ::{FuncEnvironment, GlobalVariable, WasmError, WasmResult};
|
||||
use state::{ControlStackFrame, TranslationState};
|
||||
use std::collections::{hash_map, HashMap};
|
||||
@@ -38,7 +38,7 @@ use wasmparser::{MemoryImmediate, Operator};
|
||||
|
||||
// Clippy warns about "flags: _" but its important to document that the flags field is ignored
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(unneeded_field_pattern))]
|
||||
/// Translates wasm operators into Cretonne IR instructions. Returns `true` if it inserted
|
||||
/// Translates wasm operators into Cranelift IR instructions. Returns `true` if it inserted
|
||||
/// a return.
|
||||
pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
op: Operator,
|
||||
@@ -55,7 +55,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
match op {
|
||||
/********************************** Locals ****************************************
|
||||
* `get_local` and `set_local` are treated as non-SSA variables and will completely
|
||||
* disappear in the Cretonne Code
|
||||
* disappear in the Cranelift Code
|
||||
***********************************************************************************/
|
||||
Operator::GetLocal { local_index } => {
|
||||
state.push1(builder.use_var(Variable::with_u32(local_index)))
|
||||
@@ -218,7 +218,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
* Once the destination `Ebb` is found, we sometimes have to declare a certain depth
|
||||
* of the stack unreachable, because some branch instructions are terminator.
|
||||
*
|
||||
* The `br_table` case is much more complicated because Cretonne's `br_table` instruction
|
||||
* The `br_table` case is much more complicated because Cranelift's `br_table` instruction
|
||||
* does not support jump arguments like all the other branch instructions. That is why, in
|
||||
* the case where we would use jump arguments for every other branch instructions, we
|
||||
* need to split the critical edges leaving the `br_tables` by creating one `Ebb` per
|
||||
@@ -226,7 +226,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
* `Ebb`s contain only a jump instruction pointing to the final destination, this time with
|
||||
* jump arguments.
|
||||
*
|
||||
* This system is also implemented in Cretonne's SSA construction algorithm, because
|
||||
* This system is also implemented in Cranelift's SSA construction algorithm, because
|
||||
* `use_var` located in a destination `Ebb` of a `br_table` might trigger the addition
|
||||
* of jump arguments in each predecessor branch instruction, one of which might be a
|
||||
* `br_table`.
|
||||
@@ -291,7 +291,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
};
|
||||
builder.ins().jump(ebb, &[]);
|
||||
} else {
|
||||
// Here we have jump arguments, but Cretonne's br_table doesn't support them
|
||||
// Here we have jump arguments, but Cranelift's br_table doesn't support them
|
||||
// We then proceed to split the edges going out of the br_table
|
||||
let return_count = jump_args_count;
|
||||
let mut dest_ebb_sequence = Vec::new();
|
||||
@@ -413,7 +413,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
state.push1(environ.translate_memory_size(builder.cursor(), heap_index, heap)?);
|
||||
}
|
||||
/******************************* Load instructions ***********************************
|
||||
* Wasm specifies an integer alignment flag but we drop it in Cretonne.
|
||||
* Wasm specifies an integer alignment flag but we drop it in Cranelift.
|
||||
* The memory base address is provided by the environment.
|
||||
* TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not
|
||||
************************************************************************************/
|
||||
@@ -488,7 +488,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
translate_load(offset, ir::Opcode::Load, F64, builder, state, environ);
|
||||
}
|
||||
/****************************** Store instructions ***********************************
|
||||
* Wasm specifies an integer alignment flag but we drop it in Cretonne.
|
||||
* Wasm specifies an integer alignment flag but we drop it in Cranelift.
|
||||
* The memory base address is provided by the environment.
|
||||
* TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not
|
||||
************************************************************************************/
|
||||
@@ -1027,7 +1027,7 @@ fn translate_load<FE: FuncEnvironment + ?Sized>(
|
||||
let (base, offset) = get_heap_addr(heap, addr32, offset, environ.native_pointer(), builder);
|
||||
// Note that we don't set `is_aligned` here, even if the load instruction's
|
||||
// alignment immediate says it's aligned, because WebAssembly's immediate
|
||||
// field is just a hint, while Cretonne's aligned flag needs a guarantee.
|
||||
// field is just a hint, while Cranelift's aligned flag needs a guarantee.
|
||||
let flags = MemFlags::new();
|
||||
let (load, dfg) = builder
|
||||
.ins()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! "Dummy" environment for testing wasm translation.
|
||||
|
||||
use cretonne_codegen::cursor::FuncCursor;
|
||||
use cretonne_codegen::ir::types::*;
|
||||
use cretonne_codegen::ir::{self, InstBuilder};
|
||||
use cretonne_codegen::settings;
|
||||
use cranelift_codegen::cursor::FuncCursor;
|
||||
use cranelift_codegen::ir::types::*;
|
||||
use cranelift_codegen::ir::{self, InstBuilder};
|
||||
use cranelift_codegen::settings;
|
||||
use environ::{FuncEnvironment, GlobalVariable, ModuleEnvironment, WasmResult};
|
||||
use func_translator::FuncTranslator;
|
||||
use std::string::String;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! All the runtime support necessary for the wasm to cretonne translation is formalized by the
|
||||
//! All the runtime support necessary for the wasm to cranelift translation is formalized by the
|
||||
//! traits `FunctionEnvironment` and `ModuleEnvironment`.
|
||||
use cretonne_codegen::cursor::FuncCursor;
|
||||
use cretonne_codegen::ir::{self, InstBuilder};
|
||||
use cretonne_codegen::settings::Flags;
|
||||
use cranelift_codegen::cursor::FuncCursor;
|
||||
use cranelift_codegen::ir::{self, InstBuilder};
|
||||
use cranelift_codegen::settings::Flags;
|
||||
use std::vec::Vec;
|
||||
use target_lexicon::Triple;
|
||||
use translation_utils::{
|
||||
@@ -51,10 +51,10 @@ pub enum WasmError {
|
||||
|
||||
/// An implementation limit was exceeded.
|
||||
///
|
||||
/// Cretonne can compile very large and complicated functions, but the [implementation has
|
||||
/// Cranelift can compile very large and complicated functions, but the [implementation has
|
||||
/// limits][limits] that cause compilation to fail when they are exceeded.
|
||||
///
|
||||
/// [limits]: https://cretonne.readthedocs.io/en/latest/langref.html#implementation-limits
|
||||
/// [limits]: https://cranelift.readthedocs.io/en/latest/langref.html#implementation-limits
|
||||
#[fail(display = "Implementation limit exceeded")]
|
||||
ImplLimitExceeded,
|
||||
}
|
||||
@@ -72,7 +72,7 @@ pub type WasmResult<T> = Result<T, WasmError>;
|
||||
|
||||
/// Environment affecting the translation of a single WebAssembly function.
|
||||
///
|
||||
/// A `FuncEnvironment` trait object is required to translate a WebAssembly function to Cretonne
|
||||
/// A `FuncEnvironment` trait object is required to translate a WebAssembly function to Cranelift
|
||||
/// IR. The function environment provides information about the WebAssembly module as well as the
|
||||
/// runtime environment.
|
||||
pub trait FuncEnvironment {
|
||||
@@ -82,7 +82,7 @@ pub trait FuncEnvironment {
|
||||
/// Get the flags for the current compilation.
|
||||
fn flags(&self) -> &Flags;
|
||||
|
||||
/// Get the Cretonne integer type to use for native pointers.
|
||||
/// Get the Cranelift integer type to use for native pointers.
|
||||
///
|
||||
/// This returns `I64` for 64-bit architectures and `I32` for 32-bit architectures.
|
||||
fn native_pointer(&self) -> ir::Type {
|
||||
@@ -204,7 +204,7 @@ pub trait FuncEnvironment {
|
||||
|
||||
/// An object satisfying the `ModuleEnvironment` trait can be passed as argument to the
|
||||
/// [`translate_module`](fn.translate_module.html) function. These methods should not be called
|
||||
/// by the user, they are only for `cretonne-wasm` internal use.
|
||||
/// by the user, they are only for `cranelift-wasm` internal use.
|
||||
pub trait ModuleEnvironment<'data> {
|
||||
/// Get the flags for the current compilation.
|
||||
fn flags(&self) -> &Flags;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
//! Stand-alone WebAssembly to Cretonne IR translator.
|
||||
//! Stand-alone WebAssembly to Cranelift IR translator.
|
||||
//!
|
||||
//! This module defines the `FuncTranslator` type which can translate a single WebAssembly
|
||||
//! function to Cretonne IR guided by a `FuncEnvironment` which provides information about the
|
||||
//! function to Cranelift IR guided by a `FuncEnvironment` which provides information about the
|
||||
//! WebAssembly module and the runtime environment.
|
||||
|
||||
use code_translator::translate_operator;
|
||||
use cretonne_codegen::entity::EntityRef;
|
||||
use cretonne_codegen::ir::{self, Ebb, InstBuilder};
|
||||
use cretonne_codegen::timing;
|
||||
use cretonne_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
||||
use cranelift_codegen::entity::EntityRef;
|
||||
use cranelift_codegen::ir::{self, Ebb, InstBuilder};
|
||||
use cranelift_codegen::timing;
|
||||
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
||||
use environ::{FuncEnvironment, WasmError, WasmResult};
|
||||
use state::TranslationState;
|
||||
use wasmparser::{self, BinaryReader};
|
||||
|
||||
/// WebAssembly to Cretonne IR function translator.
|
||||
/// WebAssembly to Cranelift IR function translator.
|
||||
///
|
||||
/// A `FuncTranslator` is used to translate a binary WebAssembly function into Cretonne IR guided
|
||||
/// A `FuncTranslator` is used to translate a binary WebAssembly function into Cranelift IR guided
|
||||
/// by a `FuncEnvironment` object. A single translator instance can be reused to translate multiple
|
||||
/// functions which will reduce heap allocation traffic.
|
||||
pub struct FuncTranslator {
|
||||
@@ -45,7 +45,7 @@ impl FuncTranslator {
|
||||
///
|
||||
/// [wasm]: https://webassembly.github.io/spec/binary/modules.html#code-section
|
||||
///
|
||||
/// The Cretonne IR function `func` should be completely empty except for the `func.signature`
|
||||
/// The Cranelift IR function `func` should be completely empty except for the `func.signature`
|
||||
/// and `func.name` fields. The signature may contain special-purpose arguments which are not
|
||||
/// regarded as WebAssembly local variables. Any signature arguments marked as
|
||||
/// `ArgumentPurpose::Normal` are made accessible as WebAssembly local variables.
|
||||
@@ -226,7 +226,7 @@ fn parse_function_body<FE: FuncEnvironment + ?Sized>(
|
||||
fn cur_srcloc(reader: &BinaryReader) -> ir::SourceLoc {
|
||||
// We record source locations as byte code offsets relative to the beginning of the function.
|
||||
// This will wrap around of a single function's byte code is larger than 4 GB, but a) the
|
||||
// WebAssembly format doesn't allow for that, and b) that would hit other Cretonne
|
||||
// WebAssembly format doesn't allow for that, and b) that would hit other Cranelift
|
||||
// implementation limits anyway.
|
||||
ir::SourceLoc::new(reader.current_position() as u32)
|
||||
}
|
||||
@@ -234,8 +234,8 @@ fn cur_srcloc(reader: &BinaryReader) -> ir::SourceLoc {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::FuncTranslator;
|
||||
use cretonne_codegen::ir::types::I32;
|
||||
use cretonne_codegen::{ir, Context};
|
||||
use cranelift_codegen::ir::types::I32;
|
||||
use cranelift_codegen::{ir, Context};
|
||||
use environ::{DummyEnvironment, FuncEnvironment};
|
||||
use target_lexicon::Triple;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Performs translation from a wasm module in binary format to the in-memory form
|
||||
//! of Cretonne IR. More particularly, it translates the code of all the functions bodies and
|
||||
//! of Cranelift IR. More particularly, it translates the code of all the functions bodies and
|
||||
//! interacts with an environment implementing the
|
||||
//! [`ModuleEnvironment`](trait.ModuleEnvironment.html)
|
||||
//! trait to deal with tables, globals and linear memory.
|
||||
@@ -25,8 +25,8 @@
|
||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||
|
||||
#[macro_use(dbg)]
|
||||
extern crate cretonne_codegen;
|
||||
extern crate cretonne_frontend;
|
||||
extern crate cranelift_codegen;
|
||||
extern crate cranelift_frontend;
|
||||
extern crate target_lexicon;
|
||||
extern crate wasmparser;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Translation skeleton that traverses the whole WebAssembly module and call helper functions
|
||||
//! to deal with each part of it.
|
||||
use cretonne_codegen::timing;
|
||||
use cranelift_codegen::timing;
|
||||
use environ::{ModuleEnvironment, WasmError, WasmResult};
|
||||
use sections_translator::{
|
||||
parse_data_section, parse_elements_section, parse_export_section, parse_function_section,
|
||||
@@ -9,7 +9,7 @@ use sections_translator::{
|
||||
};
|
||||
use wasmparser::{Parser, ParserInput, ParserState, SectionCode, WasmDecoder};
|
||||
|
||||
/// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cretonne IR
|
||||
/// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cranelift IR
|
||||
/// [`Function`](../codegen/ir/function/struct.Function.html).
|
||||
/// Returns the functions and also the mappings for imported functions and signature between the
|
||||
/// indexes in the wasm module and the indexes inside each functions.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//! The special case of the initialize expressions for table elements offsets or global variables
|
||||
//! is handled, according to the semantics of WebAssembly, to only specific expressions that are
|
||||
//! interpreted on the fly.
|
||||
use cretonne_codegen::ir::{self, AbiParam, Signature};
|
||||
use cranelift_codegen::ir::{self, AbiParam, Signature};
|
||||
use environ::{ModuleEnvironment, WasmError, WasmResult};
|
||||
use std::str::from_utf8;
|
||||
use std::vec::Vec;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! The `TranslationState` struct defined in this module is used to keep track of the WebAssembly
|
||||
//! value and control stacks during the translation of a single function.
|
||||
|
||||
use cretonne_codegen::ir::{self, Ebb, Inst, Value};
|
||||
use cranelift_codegen::ir::{self, Ebb, Inst, Value};
|
||||
use environ::{FuncEnvironment, GlobalVariable};
|
||||
use std::collections::HashMap;
|
||||
use std::vec::Vec;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Helper functions and structures for the translation.
|
||||
use cretonne_codegen::ir;
|
||||
use cranelift_codegen::ir;
|
||||
use std::u32;
|
||||
use wasmparser;
|
||||
|
||||
@@ -71,7 +71,7 @@ pub struct Memory {
|
||||
pub shared: bool,
|
||||
}
|
||||
|
||||
/// Helper function translating wasmparser types to Cretonne types when possible.
|
||||
/// Helper function translating wasmparser types to Cranelift types when possible.
|
||||
pub fn type_to_type(ty: wasmparser::Type) -> Result<ir::Type, ()> {
|
||||
match ty {
|
||||
wasmparser::Type::I32 => Ok(ir::types::I32),
|
||||
@@ -82,17 +82,17 @@ pub fn type_to_type(ty: wasmparser::Type) -> Result<ir::Type, ()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Turns a `wasmparser` `f32` into a `Cretonne` one.
|
||||
/// Turns a `wasmparser` `f32` into a `Cranelift` one.
|
||||
pub fn f32_translation(x: wasmparser::Ieee32) -> ir::immediates::Ieee32 {
|
||||
ir::immediates::Ieee32::with_bits(x.bits())
|
||||
}
|
||||
|
||||
/// Turns a `wasmparser` `f64` into a `Cretonne` one.
|
||||
/// Turns a `wasmparser` `f64` into a `Cranelift` one.
|
||||
pub fn f64_translation(x: wasmparser::Ieee64) -> ir::immediates::Ieee64 {
|
||||
ir::immediates::Ieee64::with_bits(x.bits())
|
||||
}
|
||||
|
||||
/// Translate a `wasmparser` type into its `Cretonne` equivalent, when possible
|
||||
/// Translate a `wasmparser` type into its `Cranelift` equivalent, when possible
|
||||
pub fn num_return_values(ty: wasmparser::Type) -> usize {
|
||||
match ty {
|
||||
wasmparser::Type::EmptyBlockType => 0,
|
||||
|
||||
Reference in New Issue
Block a user