mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 05:48:45 +00:00
Merge pull request #184 from wasmerio/fix-compiler-no-std
fix(compiler) Make it work without `std`
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
use crate::lib::std::string::String;
|
use crate::lib::std::string::String;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
// Compilation Errors
|
// Compilation Errors
|
||||||
|
//
|
||||||
|
// If `std` feature is enable, we can't use `thiserror` until
|
||||||
|
// https://github.com/dtolnay/thiserror/pull/64 is merged.
|
||||||
|
|
||||||
/// The WebAssembly.CompileError object indicates an error during
|
/// The WebAssembly.CompileError object indicates an error during
|
||||||
/// WebAssembly decoding or validation.
|
/// WebAssembly decoding or validation.
|
||||||
@@ -9,26 +13,27 @@ use thiserror::Error;
|
|||||||
/// This is based on the [Wasm Compile Error][compile-error] API.
|
/// This is based on the [Wasm Compile Error][compile-error] API.
|
||||||
///
|
///
|
||||||
/// [compiler-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError
|
/// [compiler-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError
|
||||||
#[derive(Error, Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "std", derive(Error))]
|
||||||
pub enum CompileError {
|
pub enum CompileError {
|
||||||
/// A Wasm translation error occured.
|
/// A Wasm translation error occured.
|
||||||
#[error("WebAssembly translation error: {0}")]
|
#[cfg_attr(feature = "std", error("WebAssembly translation error: {0}"))]
|
||||||
Wasm(#[from] WasmError),
|
Wasm(#[cfg_attr(feature = "std", from)] WasmError),
|
||||||
|
|
||||||
/// A compilation error occured.
|
/// A compilation error occured.
|
||||||
#[error("Compilation error: {0}")]
|
#[cfg_attr(feature = "std", error("Compilation error: {0}"))]
|
||||||
Codegen(String),
|
Codegen(String),
|
||||||
|
|
||||||
/// The module did not pass validation.
|
/// The module did not pass validation.
|
||||||
#[error("Validation error: {0}")]
|
#[cfg_attr(feature = "std", error("Validation error: {0}"))]
|
||||||
Validate(String),
|
Validate(String),
|
||||||
|
|
||||||
/// The compiler doesn't support a Wasm feature
|
/// The compiler doesn't support a Wasm feature
|
||||||
#[error("Feature {0} is not yet supported")]
|
#[cfg_attr(feature = "std", error("Feature {0} is not yet supported"))]
|
||||||
UnsupportedFeature(String),
|
UnsupportedFeature(String),
|
||||||
|
|
||||||
/// Insufficient resources available for execution.
|
/// Insufficient resources available for execution.
|
||||||
#[error("Insufficient resources: {0}")]
|
#[cfg_attr(feature = "std", error("Insufficient resources: {0}"))]
|
||||||
Resource(String),
|
Resource(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,13 +41,17 @@ pub enum CompileError {
|
|||||||
///
|
///
|
||||||
/// When a WebAssembly function can't be translated, one of these error codes will be returned
|
/// When a WebAssembly function can't be translated, one of these error codes will be returned
|
||||||
/// to describe the failure.
|
/// to describe the failure.
|
||||||
#[derive(Error, Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "std", derive(Error))]
|
||||||
pub enum WasmError {
|
pub enum WasmError {
|
||||||
/// The input WebAssembly code is invalid.
|
/// The input WebAssembly code is invalid.
|
||||||
///
|
///
|
||||||
/// This error code is used by a WebAssembly translator when it encounters invalid WebAssembly
|
/// This error code is used by a WebAssembly translator when it encounters invalid WebAssembly
|
||||||
/// code. This should never happen for validated WebAssembly code.
|
/// code. This should never happen for validated WebAssembly code.
|
||||||
#[error("Invalid input WebAssembly code at offset {offset}: {message}")]
|
#[cfg_attr(
|
||||||
|
feature = "std",
|
||||||
|
error("Invalid input WebAssembly code at offset {offset}: {message}")
|
||||||
|
)]
|
||||||
InvalidWebAssembly {
|
InvalidWebAssembly {
|
||||||
/// A string describing the validation error.
|
/// A string describing the validation error.
|
||||||
message: String,
|
message: String,
|
||||||
@@ -53,17 +62,27 @@ pub enum WasmError {
|
|||||||
/// A feature used by the WebAssembly code is not supported by the embedding environment.
|
/// A feature used by the WebAssembly code is not supported by the embedding environment.
|
||||||
///
|
///
|
||||||
/// Embedding environments may have their own limitations and feature restrictions.
|
/// Embedding environments may have their own limitations and feature restrictions.
|
||||||
#[error("Unsupported feature: {0}")]
|
#[cfg_attr(feature = "std", error("Unsupported feature: {0}"))]
|
||||||
Unsupported(String),
|
Unsupported(String),
|
||||||
|
|
||||||
/// An implementation limit was exceeded.
|
/// An implementation limit was exceeded.
|
||||||
#[error("Implementation limit exceeded")]
|
#[cfg_attr(feature = "std", error("Implementation limit exceeded"))]
|
||||||
ImplLimitExceeded,
|
ImplLimitExceeded,
|
||||||
|
|
||||||
/// A generic error.
|
/// A generic error.
|
||||||
#[error("{0}")]
|
#[cfg_attr(feature = "std", error("{0}"))]
|
||||||
Generic(String),
|
Generic(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The error that can happen while parsing a `str`
|
||||||
|
/// to retrieve a [`CpuFeature`].
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "std", derive(Error))]
|
||||||
|
pub enum ParseCpuFeatureError {
|
||||||
|
/// The provided string feature doesn't exist
|
||||||
|
#[cfg_attr(feature = "std", error("CpuFeature {0} not recognized"))]
|
||||||
|
Missing(String),
|
||||||
|
}
|
||||||
|
|
||||||
/// A convenient alias for a `Result` that uses `WasmError` as the error type.
|
/// A convenient alias for a `Result` that uses `WasmError` as the error type.
|
||||||
pub type WasmResult<T> = Result<T, WasmError>;
|
pub type WasmResult<T> = Result<T, WasmError>;
|
||||||
|
|||||||
@@ -38,15 +38,14 @@ extern crate alloc;
|
|||||||
mod lib {
|
mod lib {
|
||||||
#[cfg(feature = "core")]
|
#[cfg(feature = "core")]
|
||||||
pub mod std {
|
pub mod std {
|
||||||
#[macro_use]
|
pub use alloc::{borrow, boxed, str, string, sync, vec};
|
||||||
pub use alloc::{borrow, boxed, string, vec, sync};
|
|
||||||
pub use core::fmt;
|
pub use core::fmt;
|
||||||
pub use hashbrown as collections;
|
pub use hashbrown as collections;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub mod std {
|
pub mod std {
|
||||||
pub use std::{borrow, boxed, collections, fmt, string, sync, vec};
|
pub use std::{borrow, boxed, collections, fmt, str, string, sync, vec};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +69,7 @@ mod sourceloc;
|
|||||||
pub use crate::address_map::{FunctionAddressMap, InstructionAddressMap};
|
pub use crate::address_map::{FunctionAddressMap, InstructionAddressMap};
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
pub use crate::compiler::{Compiler, CompilerConfig};
|
pub use crate::compiler::{Compiler, CompilerConfig};
|
||||||
pub use crate::error::{CompileError, WasmError, WasmResult};
|
pub use crate::error::{CompileError, ParseCpuFeatureError, WasmError, WasmResult};
|
||||||
pub use crate::function::{
|
pub use crate::function::{
|
||||||
Compilation, CompiledFunction, CompiledFunctionFrameInfo, CustomSections, Dwarf, FunctionBody,
|
Compilation, CompiledFunction, CompiledFunctionFrameInfo, CustomSections, Dwarf, FunctionBody,
|
||||||
Functions,
|
Functions,
|
||||||
@@ -82,7 +81,7 @@ pub use crate::section::{CustomSection, CustomSectionProtection, SectionBody, Se
|
|||||||
pub use crate::sourceloc::SourceLoc;
|
pub use crate::sourceloc::SourceLoc;
|
||||||
pub use crate::target::{
|
pub use crate::target::{
|
||||||
Architecture, BinaryFormat, CallingConvention, CpuFeature, Endianness, OperatingSystem,
|
Architecture, BinaryFormat, CallingConvention, CpuFeature, Endianness, OperatingSystem,
|
||||||
ParseCpuFeatureError, PointerWidth, Target, Triple,
|
PointerWidth, Target, Triple,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
pub use crate::translator::{
|
pub use crate::translator::{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use crate::lib::std::sync::Arc;
|
||||||
#[cfg(feature = "enable-serde")]
|
#[cfg(feature = "enable-serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
|
||||||
use wasm_common::entity::PrimaryMap;
|
use wasm_common::entity::PrimaryMap;
|
||||||
use wasm_common::{Features, MemoryIndex, TableIndex};
|
use wasm_common::{Features, MemoryIndex, TableIndex};
|
||||||
use wasmer_vm::{MemoryStyle, ModuleInfo, TableStyle};
|
use wasmer_vm::{MemoryStyle, ModuleInfo, TableStyle};
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
//! Target configuration
|
//! Target configuration
|
||||||
|
use crate::error::ParseCpuFeatureError;
|
||||||
|
use crate::lib::std::str::FromStr;
|
||||||
|
use crate::lib::std::string::{String, ToString};
|
||||||
use enumset::{EnumSet, EnumSetType};
|
use enumset::{EnumSet, EnumSetType};
|
||||||
use std::str::FromStr;
|
|
||||||
use std::string::ToString;
|
|
||||||
pub use target_lexicon::{
|
pub use target_lexicon::{
|
||||||
Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth,
|
Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth,
|
||||||
Triple,
|
Triple,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
use raw_cpuid::CpuId;
|
use raw_cpuid::CpuId;
|
||||||
@@ -112,15 +112,6 @@ impl CpuFeature {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The error that can happen while parsing a `str`
|
|
||||||
/// to retrieve a [`CpuFeature`].
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
pub enum ParseCpuFeatureError {
|
|
||||||
/// The provided string feature doesn't exist
|
|
||||||
#[error("CpuFeature {0} not recognized")]
|
|
||||||
Missing(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
// This options should map exactly the GCC options indicated
|
// This options should map exactly the GCC options indicated
|
||||||
// here by architectures:
|
// here by architectures:
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user