Merge branch 'master' into no_std

This commit is contained in:
morenzg
2018-04-17 16:41:27 -04:00
364 changed files with 3412 additions and 1024 deletions

View File

@@ -22,11 +22,11 @@
//!
//! That is why `translate_function_body` takes an object having the `WasmRuntime` trait as
//! argument.
use cretonne::ir::condcodes::{FloatCC, IntCC};
use cretonne::ir::types::*;
use cretonne::ir::{self, InstBuilder, JumpTableData, MemFlags};
use cretonne::packed_option::ReservedValue;
use cton_frontend::{FunctionBuilder, Variable};
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 environ::{FuncEnvironment, GlobalValue};
use state::{ControlStackFrame, TranslationState};
use std::collections::{hash_map, HashMap};

View File

@@ -1,9 +1,9 @@
//! "Dummy" environment for testing wasm translation.
use cretonne::cursor::FuncCursor;
use cretonne::ir::types::*;
use cretonne::ir::{self, InstBuilder};
use cretonne::settings;
use cretonne_codegen::cursor::FuncCursor;
use cretonne_codegen::ir::types::*;
use cretonne_codegen::ir::{self, InstBuilder};
use cretonne_codegen::settings;
use environ::{FuncEnvironment, GlobalValue, ModuleEnvironment};
use func_translator::FuncTranslator;
use std::string::String;
@@ -150,7 +150,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue {
// Just create a dummy `vmctx` global.
let offset = ((index * 8) as i32 + 8).into();
let gv = func.create_global_var(ir::GlobalVarData::VmCtx { offset });
let gv = func.create_global_var(ir::GlobalVarData::VMContext { offset });
GlobalValue::Memory {
gv,
ty: self.mod_info.globals[index].entity.ty,
@@ -159,7 +159,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
fn make_heap(&mut self, func: &mut ir::Function, _index: MemoryIndex) -> ir::Heap {
// Create a static heap whose base address is stored at `vmctx+0`.
let gv = func.create_global_var(ir::GlobalVarData::VmCtx { offset: 0.into() });
let gv = func.create_global_var(ir::GlobalVarData::VMContext { offset: 0.into() });
func.create_heap(ir::HeapData {
base: ir::HeapBase::GlobalVar(gv),
@@ -181,7 +181,11 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
// And maybe attempt some signature de-duplication.
let signature = func.import_signature(self.vmctx_sig(sigidx));
let name = get_func_name(index);
func.import_function(ir::ExtFuncData { name, signature })
func.import_function(ir::ExtFuncData {
name,
signature,
colocated: false,
})
}
fn translate_call_indirect(
@@ -221,7 +225,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
args.push(vmctx, &mut pos.func.dfg.value_lists);
pos.ins()
.IndirectCall(ir::Opcode::CallIndirect, ir::types::VOID, sig_ref, args)
.CallIndirect(ir::Opcode::CallIndirect, ir::types::VOID, sig_ref, args)
.0
}

View File

@@ -1,8 +1,8 @@
//! All the runtime support necessary for the wasm to cretonne translation is formalized by the
//! traits `FunctionEnvironment` and `ModuleEnvironment`.
use cretonne::cursor::FuncCursor;
use cretonne::ir::{self, InstBuilder};
use cretonne::settings::Flags;
use cretonne_codegen::cursor::FuncCursor;
use cretonne_codegen::ir::{self, InstBuilder};
use cretonne_codegen::settings::Flags;
use std::string::String;
use std::vec::Vec;
use translation_utils::{FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex,

View File

@@ -5,11 +5,11 @@
//! WebAssembly module and the runtime environment.
use code_translator::translate_operator;
use cretonne::entity::EntityRef;
use cretonne::ir::{self, Ebb, InstBuilder};
use cretonne::result::{CtonError, CtonResult};
use cretonne::timing;
use cton_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
use cretonne_codegen::entity::EntityRef;
use cretonne_codegen::ir::{self, Ebb, InstBuilder};
use cretonne_codegen::result::{CtonError, CtonResult};
use cretonne_codegen::timing;
use cretonne_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
use environ::FuncEnvironment;
use state::TranslationState;
use wasmparser::{self, BinaryReader};
@@ -233,8 +233,8 @@ fn cur_srcloc(reader: &BinaryReader) -> ir::SourceLoc {
#[cfg(test)]
mod tests {
use super::FuncTranslator;
use cretonne::ir::types::I32;
use cretonne::{ir, Context};
use cretonne_codegen::ir::types::I32;
use cretonne_codegen::{ir, Context};
use environ::{DummyEnvironment, FuncEnvironment};
#[test]

View File

@@ -25,8 +25,8 @@ extern crate alloc;
extern crate hashmap_core;
#[macro_use(dbg)]
extern crate cretonne;
extern crate cton_frontend;
extern crate cretonne_codegen;
extern crate cretonne_frontend;
extern crate wasmparser;
mod code_translator;

View File

@@ -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::timing;
use cretonne_codegen::timing;
use environ::ModuleEnvironment;
use sections_translator::{parse_data_section, parse_elements_section, parse_export_section,
parse_function_section, parse_function_signatures, parse_global_section,
@@ -11,7 +11,7 @@ use wasmparser::{BinaryReaderError, Parser, ParserInput, ParserState, SectionCod
use std::string::String;
/// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cretonne IR
/// [`Function`](../cretonne/ir/function/struct.Function.html).
/// [`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.
pub fn translate_module<'data>(

View File

@@ -7,8 +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;
use cretonne::ir::{AbiParam, CallConv, Signature};
use cretonne_codegen::ir::{self, AbiParam, CallConv, Signature};
use environ::ModuleEnvironment;
use std::str::from_utf8;
use std::string::String;
@@ -38,13 +37,13 @@ pub fn parse_function_signatures(
}) => {
let mut sig = Signature::new(CallConv::SystemV);
sig.params.extend(params.iter().map(|ty| {
let cret_arg: cretonne::ir::Type = type_to_type(ty).expect(
let cret_arg: ir::Type = type_to_type(ty).expect(
"only numeric types are supported in function signatures",
);
AbiParam::new(cret_arg)
}));
sig.returns.extend(returns.iter().map(|ty| {
let cret_arg: cretonne::ir::Type = type_to_type(ty).expect(
let cret_arg: ir::Type = type_to_type(ty).expect(
"only numeric types are supported in function signatures",
);
AbiParam::new(cret_arg)

View File

@@ -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::ir::{self, Ebb, Inst, Value};
use cretonne_codegen::ir::{self, Ebb, Inst, Value};
use environ::{FuncEnvironment, GlobalValue};
use std::collections::HashMap;
use std::vec::Vec;

View File

@@ -1,5 +1,5 @@
//! Helper functions and structures for the translation.
use cretonne;
use cretonne_codegen::ir;
use std::u32;
use wasmparser;
@@ -18,7 +18,7 @@ pub type SignatureIndex = usize;
#[derive(Debug, Clone, Copy)]
pub struct Global {
/// The type of the value stored in the global.
pub ty: cretonne::ir::Type,
pub ty: ir::Type,
/// A flag indicating whether the value may change at runtime.
pub mutability: bool,
/// The source of the initial value.
@@ -56,7 +56,7 @@ pub struct Table {
/// WebAssembly table element. Can be a function or a scalar type.
#[derive(Debug, Clone, Copy)]
pub enum TableElementType {
Val(cretonne::ir::Type),
Val(ir::Type),
Func(),
}
@@ -72,24 +72,24 @@ pub struct Memory {
}
/// Helper function translating wasmparser types to Cretonne types when possible.
pub fn type_to_type(ty: &wasmparser::Type) -> Result<cretonne::ir::Type, ()> {
pub fn type_to_type(ty: &wasmparser::Type) -> Result<ir::Type, ()> {
match *ty {
wasmparser::Type::I32 => Ok(cretonne::ir::types::I32),
wasmparser::Type::I64 => Ok(cretonne::ir::types::I64),
wasmparser::Type::F32 => Ok(cretonne::ir::types::F32),
wasmparser::Type::F64 => Ok(cretonne::ir::types::F64),
wasmparser::Type::I32 => Ok(ir::types::I32),
wasmparser::Type::I64 => Ok(ir::types::I64),
wasmparser::Type::F32 => Ok(ir::types::F32),
wasmparser::Type::F64 => Ok(ir::types::F64),
_ => Err(()),
}
}
/// Turns a `wasmparser` `f32` into a `Cretonne` one.
pub fn f32_translation(x: wasmparser::Ieee32) -> cretonne::ir::immediates::Ieee32 {
cretonne::ir::immediates::Ieee32::with_bits(x.bits())
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.
pub fn f64_translation(x: wasmparser::Ieee64) -> cretonne::ir::immediates::Ieee64 {
cretonne::ir::immediates::Ieee64::with_bits(x.bits())
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