Skip to content

Commit

Permalink
Merge branch 'master' into feature/get-php-kind-of-working
Browse files Browse the repository at this point in the history
  • Loading branch information
xmclark authored Apr 4, 2019
2 parents 974656c + 77f8186 commit b6492c5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 76 deletions.
78 changes: 37 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/clif-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ edition = "2018"

[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" }
cranelift-native = "0.26.0"
cranelift-codegen = "0.26.0"
cranelift-entity = "0.26.0"
cranelift-wasm = "0.26.0"
cranelift-native = "0.30.0"
cranelift-codegen = "0.30.0"
cranelift-entity = "0.30.0"
cranelift-wasm = "0.30.0"
hashbrown = "0.1"
target-lexicon = "0.2.0"
target-lexicon = "0.3.0"
wasmparser = "0.23.0"
byteorder = "1"
nix = "0.13.0"
Expand Down
4 changes: 2 additions & 2 deletions lib/clif-backend/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ convert_clif_to_runtime_index![
(SignatureIndex: SigIndex),
];

impl<'a> From<Converter<&'a ir::Signature>> for FuncSig {
fn from(signature: Converter<&'a ir::Signature>) -> Self {
impl From<Converter<ir::Signature>> for FuncSig {
fn from(signature: Converter<ir::Signature>) -> Self {
FuncSig::new(
signature
.0
Expand Down
50 changes: 22 additions & 28 deletions lib/clif-backend/src/module_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ impl<'module, 'isa> ModuleEnv<'module, 'isa> {

Ok(self.func_bodies)
}

/// Return the global for the given global index.
pub fn get_global(&self, global_index: cranelift_wasm::GlobalIndex) -> &cranelift_wasm::Global {
&self.globals[Converter(global_index).into()]
}

/// Return the signature index for the given function index.
pub fn get_func_type(
&self,
func_index: cranelift_wasm::FuncIndex,
) -> cranelift_wasm::SignatureIndex {
let sig_index: SigIndex = self.module.info.func_assoc[Converter(func_index).into()];
Converter(sig_index).into()
}
}

impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa> {
Expand All @@ -59,16 +73,11 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
}

/// Declares a function signature to the environment.
fn declare_signature(&mut self, sig: &ir::Signature) {
fn declare_signature(&mut self, sig: ir::Signature) {
self.signatures.push(sig.clone());
self.module.info.signatures.push(Converter(sig).into());
}

/// Return the signature with the given index.
fn get_signature(&self, clif_sig_index: cranelift_wasm::SignatureIndex) -> &ir::Signature {
&self.signatures[Converter(clif_sig_index).into()]
}

/// Declares a function import to the environment.
fn declare_func_import(
&mut self,
Expand All @@ -92,11 +101,6 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
});
}

/// Return the number of imported funcs.
fn get_num_func_imports(&self) -> usize {
self.module.info.imported_functions.len()
}

/// Declares the type (signature) of a local function in the module.
fn declare_func_type(&mut self, clif_sig_index: cranelift_wasm::SignatureIndex) {
// We convert the cranelift signature index to
Expand All @@ -106,15 +110,6 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
self.module.info.func_assoc.push(sig_index);
}

/// Return the signature index for the given function index.
fn get_func_type(
&self,
func_index: cranelift_wasm::FuncIndex,
) -> cranelift_wasm::SignatureIndex {
let sig_index: SigIndex = self.module.info.func_assoc[Converter(func_index).into()];
Converter(sig_index).into()
}

/// Declares a global to the environment.
fn declare_global(&mut self, global: cranelift_wasm::Global) {
let desc = GlobalDescriptor {
Expand Down Expand Up @@ -180,11 +175,6 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
self.globals.push(global);
}

/// Return the global for the given global index.
fn get_global(&self, global_index: cranelift_wasm::GlobalIndex) -> &cranelift_wasm::Global {
&self.globals[Converter(global_index).into()]
}

/// Declares a table to the environment.
fn declare_table(&mut self, table: cranelift_wasm::Table) {
use cranelift_wasm::TableElementType;
Expand Down Expand Up @@ -238,7 +228,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
table_index: cranelift_wasm::TableIndex,
base: Option<cranelift_wasm::GlobalIndex>,
offset: usize,
elements: Vec<cranelift_wasm::FuncIndex>,
elements: Box<[cranelift_wasm::FuncIndex]>,
) {
// Convert Cranelift GlobalIndex to wamser GlobalIndex
// let base = base.map(|index| WasmerGlobalIndex::new(index.index()));
Expand Down Expand Up @@ -376,7 +366,11 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
}

/// Provides the contents of a function body.
fn define_function_body(&mut self, body_bytes: &'data [u8]) -> cranelift_wasm::WasmResult<()> {
fn define_function_body(
&mut self,
body_bytes: &'data [u8],
body_offset: usize,
) -> cranelift_wasm::WasmResult<()> {
let mut func_translator = FuncTranslator::new();

let func_body = {
Expand All @@ -390,7 +384,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>

let mut func = ir::Function::with_name_signature(name, sig);

func_translator.translate(body_bytes, &mut func, &mut func_env)?;
func_translator.translate(body_bytes, body_offset, &mut func, &mut func_env)?;

#[cfg(feature = "debug")]
{
Expand Down
2 changes: 2 additions & 0 deletions lib/clif-backend/src/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ pub enum TrapCode {
IntegerDivisionByZero,
BadConversionToInteger,
Interrupt,
UnreachableCodeReached,
User(u16),
}

Expand Down Expand Up @@ -297,6 +298,7 @@ impl binemit::TrapSink for LocalTrapSink {
ir::TrapCode::IntegerDivisionByZero => TrapCode::IntegerDivisionByZero,
ir::TrapCode::BadConversionToInteger => TrapCode::BadConversionToInteger,
ir::TrapCode::Interrupt => TrapCode::Interrupt,
ir::TrapCode::UnreachableCodeReached => TrapCode::UnreachableCodeReached,
ir::TrapCode::User(x) => TrapCode::User(x),
};

Expand Down

0 comments on commit b6492c5

Please sign in to comment.