forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5020116
commit 5eef30c
Showing
14 changed files
with
225 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ version = "0.16.2" | |
license = "MIT" | ||
authors = ["The Wasmer Engineering Team <[email protected]>"] | ||
repository = "https://github.com/wasmerio/wasmer" | ||
keywords = ["wasm", "webassembly", "compiler", "JIT", "llvm"] | ||
keywords = ["webassembly", "wasm", "compiler", "llvm"] | ||
categories = ["wasm"] | ||
edition = "2018" | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "wasmer-compiler-singlepass" | ||
version = "0.16.2" | ||
authors = ["Wasmer Engineering Team <[email protected]>"] | ||
description = "Standalone environment support for WebAsssembly code in Singlepass" | ||
license = "MIT OR (Apache-2.0 WITH LLVM-exception)" | ||
repository = "https://github.com/wasmerio/wasmer" | ||
documentation = "https://docs.rs/wasmer-compiler-singlepass/" | ||
categories = ["wasm"] | ||
keywords = ["webassembly", "wasm", "compiler", "singlepass"] | ||
readme = "README.md" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
hashbrown = { version = "0.7.1", optional = true } | ||
log = { version = "0.4.8", default-features = false } | ||
wasmer-compiler = { path = "../compiler", version = "0.16.2", default-features = false } | ||
wasmer-runtime = { path = "../runtime", version = "0.16.2" } | ||
wasm-common = { path = "../wasm-common", version = "0.16.2", default-features = false } | ||
wasmparser = "0.51.4" | ||
rayon = "1.3.0" | ||
serde = { version = "1.0.106", features = ["derive"] } | ||
more-asserts = "0.2.1" | ||
|
||
[badges] | ||
maintenance = { status = "actively-developed" } | ||
|
||
[features] | ||
default = ["std", "enable-serde"] | ||
enable-serde = ["wasmer-compiler/enable-serde", "wasm-common/enable-serde"] | ||
std = ["wasmer-compiler/std", "wasm-common/std"] | ||
core = ["hashbrown"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//! Support for compiling with Singlepass. | ||
// Allow unused imports while developing. | ||
#![allow(unused_imports, dead_code)] | ||
|
||
use crate::config::SinglepassConfig; | ||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; | ||
use wasm_common::entity::{EntityRef, PrimaryMap}; | ||
use wasm_common::Features; | ||
use wasm_common::{FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, TableIndex}; | ||
use wasmer_compiler::FunctionBodyData; | ||
use wasmer_compiler::TrapInformation; | ||
use wasmer_compiler::{Compilation, CompileError, CompiledFunction, Compiler}; | ||
use wasmer_compiler::{CompilerConfig, ModuleTranslationState, Target}; | ||
use wasmer_runtime::Module; | ||
use wasmer_runtime::TrapCode; | ||
use wasmer_runtime::{MemoryPlan, TablePlan}; | ||
|
||
/// A compiler that compiles a WebAssembly module with Singlepass. | ||
/// It does the compilation in one pass | ||
pub struct SinglepassCompiler { | ||
config: SinglepassConfig, | ||
} | ||
|
||
impl SinglepassCompiler { | ||
/// Creates a new Singlepass compiler | ||
pub fn new(config: &SinglepassConfig) -> Self { | ||
Self { | ||
config: config.clone(), | ||
} | ||
} | ||
|
||
/// Gets the WebAssembly features for this Compiler | ||
fn config(&self) -> &SinglepassConfig { | ||
&self.config | ||
} | ||
} | ||
|
||
impl Compiler for SinglepassCompiler { | ||
/// Gets the WebAssembly features for this Compiler | ||
fn features(&self) -> &Features { | ||
self.config.features() | ||
} | ||
|
||
/// Gets the target associated to this Compiler. | ||
fn target(&self) -> &Target { | ||
self.config.target() | ||
} | ||
|
||
/// Compile the module using LLVM, producing a compilation result with | ||
/// associated relocations. | ||
fn compile_module( | ||
&self, | ||
_module: &Module, | ||
_module_translation: &ModuleTranslationState, | ||
_function_body_inputs: PrimaryMap<LocalFuncIndex, FunctionBodyData<'_>>, | ||
_memory_plans: PrimaryMap<MemoryIndex, MemoryPlan>, | ||
_table_plans: PrimaryMap<TableIndex, TablePlan>, | ||
) -> Result<Compilation, CompileError> { | ||
// Note to implementors: please use rayon paralell iterator to generate | ||
// the machine code in parallel. | ||
// Here's an example on how Cranelift is doing it: | ||
// https://github.com/wasmerio/wasmer-reborn/blob/master/lib/compiler-cranelift/src/compiler.rs#L202-L267 | ||
Err(CompileError::Codegen( | ||
"Singlepass compilation not supported yet".to_owned(), | ||
)) | ||
} | ||
|
||
fn compile_wasm_trampolines( | ||
&self, | ||
_signatures: &[FuncType], | ||
) -> Result<Vec<CompiledFunction>, CompileError> { | ||
// Note: do not implement this yet | ||
Err(CompileError::Codegen( | ||
"Singlepass trampoline compilation not supported yet".to_owned(), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Allow unused imports while developing | ||
#![allow(unused_imports, dead_code)] | ||
|
||
use crate::compiler::SinglepassCompiler; | ||
use wasmer_compiler::{Compiler, CompilerConfig, CpuFeature, Features, Target}; | ||
|
||
#[derive(Clone)] | ||
pub struct SinglepassConfig { | ||
/// Enable NaN canonicalization. | ||
/// | ||
/// NaN canonicalization is useful when trying to run WebAssembly | ||
/// deterministically across different architectures. | ||
pub enable_nan_canonicalization: bool, | ||
|
||
features: Features, | ||
target: Target, | ||
} | ||
|
||
impl SinglepassConfig { | ||
/// Creates a new configuration object with the default configuration | ||
/// specified. | ||
pub fn new() -> Self { | ||
Self { | ||
enable_nan_canonicalization: true, | ||
features: Default::default(), | ||
target: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl CompilerConfig for SinglepassConfig { | ||
/// Gets the WebAssembly features | ||
fn features(&self) -> &Features { | ||
&self.features | ||
} | ||
|
||
/// Gets the WebAssembly features, mutable | ||
fn features_mut(&mut self) -> &mut Features { | ||
&mut self.features | ||
} | ||
|
||
/// Gets the target that we will use for compiling | ||
/// the WebAssembly module | ||
fn target(&self) -> &Target { | ||
&self.target | ||
} | ||
|
||
/// Gets the target that we will use for compiling | ||
/// the WebAssembly module, mutable | ||
fn target_mut(&mut self) -> &mut Target { | ||
&mut self.target | ||
} | ||
|
||
/// Transform it into the compiler | ||
fn compiler(&self) -> Box<dyn Compiler> { | ||
Box::new(SinglepassCompiler::new(&self)) | ||
} | ||
} | ||
|
||
impl Default for SinglepassConfig { | ||
fn default() -> SinglepassConfig { | ||
SinglepassConfig::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//! A WebAssembly `Compiler` implementation using Singlepass. | ||
//! | ||
//! Singlepass is a super-fast assembly generator that generates | ||
//! assembly code in just one pass. This is useful for different applications | ||
//! including Blockchains and Edge computing where quick compilation | ||
//! times are a must, and JIT bombs should never happen. | ||
//! | ||
//! Compared to Cranelift and LLVM, Singlepass is much faster to compile. | ||
//! > Note: Singlepass currently depends on Rust nightly features. | ||
mod compiler; | ||
mod config; | ||
|
||
pub use crate::compiler::SinglepassCompiler; | ||
pub use crate::config::SinglepassConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ impl Wast { | |
store, | ||
import_object, | ||
instances: HashMap::new(), | ||
fail_fast: false, | ||
fail_fast: true, | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters