mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 06:08:29 +00:00
Merge pull request #32 from Hywan/fix-compiler-no-default-features
fix(compiler) Fix features
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
//! Data structures to provide transformation of the source
|
||||
// addresses of a WebAssembly module into the native code.
|
||||
|
||||
use crate::lib::std::vec::Vec;
|
||||
use crate::sourceloc::SourceLoc;
|
||||
use crate::std::vec::Vec;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Single source location to generated address mapping.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct InstructionAddressMap {
|
||||
/// Original source location.
|
||||
pub srcloc: SourceLoc,
|
||||
@@ -19,7 +21,8 @@ pub struct InstructionAddressMap {
|
||||
}
|
||||
|
||||
/// Function and its instructions addresses mappings.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct FunctionAddressMap {
|
||||
/// Instructions maps.
|
||||
/// The array is sorted by the InstructionAddressMap::code_offset field.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::std::string::String;
|
||||
use crate::lib::std::string::String;
|
||||
use thiserror::Error;
|
||||
|
||||
// Compilation Errors
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
//! * `jit`: to generate a JIT
|
||||
//! * `obj`: to generate a native object
|
||||
|
||||
use crate::lib::std::vec::Vec;
|
||||
use crate::section::{CustomSection, SectionBody, SectionIndex};
|
||||
use crate::std::vec::Vec;
|
||||
use crate::trap::TrapInformation;
|
||||
use crate::{CompiledFunctionUnwindInfo, FunctionAddressMap, JumpTableOffsets, Relocation};
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use wasm_common::entity::PrimaryMap;
|
||||
@@ -18,7 +19,8 @@ use wasm_common::LocalFunctionIndex;
|
||||
///
|
||||
/// This structure is only used for reconstructing
|
||||
/// the frame information after a `Trap`.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct CompiledFunctionFrameInfo {
|
||||
/// The traps (in the function body)
|
||||
pub traps: Vec<TrapInformation>,
|
||||
@@ -28,10 +30,11 @@ pub struct CompiledFunctionFrameInfo {
|
||||
}
|
||||
|
||||
/// The function body.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FunctionBody {
|
||||
/// The function body bytes.
|
||||
#[serde(with = "serde_bytes")]
|
||||
#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))]
|
||||
pub body: Vec<u8>,
|
||||
|
||||
/// The function unwind info
|
||||
@@ -43,7 +46,8 @@ pub struct FunctionBody {
|
||||
/// This structure only have the compiled information data
|
||||
/// (function bytecode body, relocations, traps, jump tables
|
||||
/// and unwind information).
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct CompiledFunction {
|
||||
/// The function body.
|
||||
pub body: FunctionBody,
|
||||
@@ -65,7 +69,8 @@ pub type Functions = PrimaryMap<LocalFunctionIndex, CompiledFunction>;
|
||||
pub type CustomSections = PrimaryMap<SectionIndex, CustomSection>;
|
||||
|
||||
/// The result of compiling a WebAssembly module's functions.
|
||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Compilation {
|
||||
/// Compiled code for the function bodies.
|
||||
functions: Functions,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
//! Source: https://en.wikipedia.org/wiki/Branch_table
|
||||
|
||||
use super::CodeOffset;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasm_common::entity::{entity_impl, SecondaryMap};
|
||||
|
||||
@@ -12,8 +13,10 @@ use wasm_common::entity::{entity_impl, SecondaryMap};
|
||||
///
|
||||
/// `JumpTable`s are used for indirect branching and are specialized for dense,
|
||||
/// 0-based jump offsets.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct JumpTable(u32);
|
||||
|
||||
entity_impl!(JumpTable, "jt");
|
||||
|
||||
impl JumpTable {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
|
||||
#![warn(unused_import_braces)]
|
||||
#![cfg_attr(feature = "std", deny(unstable_features))]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
|
||||
#![cfg_attr(
|
||||
@@ -23,19 +24,32 @@
|
||||
clippy::use_self
|
||||
)
|
||||
)]
|
||||
#![no_std]
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[macro_use]
|
||||
extern crate alloc as std;
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
#[cfg(all(feature = "std", feature = "core"))]
|
||||
compile_error!(
|
||||
"The `std` and `core` features are both enabled, which is an error. Please enable only once."
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use hashbrown::HashMap;
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::HashMap;
|
||||
#[cfg(all(not(feature = "std"), not(feature = "core")))]
|
||||
compile_error!("Both the `std` and `core` features are disabled. Please enable one of them.");
|
||||
|
||||
#[cfg(feature = "core")]
|
||||
extern crate alloc;
|
||||
|
||||
mod lib {
|
||||
#[cfg(feature = "core")]
|
||||
pub mod std {
|
||||
#[macro_use]
|
||||
pub use alloc::{boxed, string, vec};
|
||||
pub use core::fmt;
|
||||
pub use hashbrown as collections;
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod std {
|
||||
pub use std::{boxed, collections, fmt, string, vec};
|
||||
}
|
||||
}
|
||||
|
||||
mod address_map;
|
||||
#[cfg(feature = "translator")]
|
||||
|
||||
@@ -9,17 +9,19 @@
|
||||
//! the generated machine code, so a given frontend (JIT or native) can
|
||||
//! do the corresponding work to run it.
|
||||
|
||||
use crate::lib::std::fmt;
|
||||
use crate::lib::std::vec::Vec;
|
||||
use crate::section::SectionIndex;
|
||||
use crate::std::vec::Vec;
|
||||
use crate::{Addend, CodeOffset, JumpTable};
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use wasm_common::entity::PrimaryMap;
|
||||
use wasm_common::LocalFunctionIndex;
|
||||
use wasmer_runtime::libcalls::LibCall;
|
||||
|
||||
/// Relocation kinds for every ISA.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum RelocationKind {
|
||||
/// absolute 4-byte
|
||||
Abs4,
|
||||
@@ -73,7 +75,8 @@ impl fmt::Display for RelocationKind {
|
||||
}
|
||||
|
||||
/// A record of a relocation to perform.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Relocation {
|
||||
/// The relocation kind.
|
||||
pub kind: RelocationKind,
|
||||
@@ -86,7 +89,8 @@ pub struct Relocation {
|
||||
}
|
||||
|
||||
/// Destination function. Can be either user function or some special one, like `memory.grow`.
|
||||
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum RelocationTarget {
|
||||
/// A relocation to a function defined locally in the wasm (not an imported one).
|
||||
LocalFunc(LocalFunctionIndex),
|
||||
|
||||
@@ -5,20 +5,24 @@
|
||||
//! to emit a custom relocation: `RelocationTarget::CustomSection`, so
|
||||
//! it can be patched later by the engine (native or JIT).
|
||||
|
||||
use crate::std::vec::Vec;
|
||||
use crate::lib::std::vec::Vec;
|
||||
use crate::Relocation;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasm_common::entity::entity_impl;
|
||||
|
||||
/// Index type of a Section defined inside a WebAssembly `Compilation`.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
pub struct SectionIndex(u32);
|
||||
|
||||
entity_impl!(SectionIndex);
|
||||
|
||||
/// Custom section Protection.
|
||||
///
|
||||
/// Determines how a custom section may be used.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum CustomSectionProtection {
|
||||
/// A custom section with read permissions,
|
||||
Read,
|
||||
@@ -31,7 +35,8 @@ pub enum CustomSectionProtection {
|
||||
///
|
||||
/// This is used so compilers can store arbitrary information
|
||||
/// in the emitted module.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct CustomSection {
|
||||
/// Memory protection that applies to this section.
|
||||
pub protection: CustomSectionProtection,
|
||||
@@ -49,8 +54,9 @@ pub struct CustomSection {
|
||||
}
|
||||
|
||||
/// The bytes in the section.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct SectionBody(#[serde(with = "serde_bytes")] Vec<u8>);
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct SectionBody(#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))] Vec<u8>);
|
||||
|
||||
impl SectionBody {
|
||||
/// Create a new section body with the given contents.
|
||||
|
||||
@@ -4,16 +4,22 @@
|
||||
//! relative to the WebAssembly module. This is used mainly for debugging
|
||||
//! and tracing errors.
|
||||
|
||||
use core::fmt;
|
||||
use crate::lib::std::fmt;
|
||||
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A source location.
|
||||
///
|
||||
/// The default source location uses the all-ones bit pattern `!0`. It is used for instructions
|
||||
/// that can't be given a real source location.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
#[cfg_attr(
|
||||
feature = "enable-serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(transparent)
|
||||
)]
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct SourceLoc(u32);
|
||||
|
||||
impl SourceLoc {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use crate::sourceloc::SourceLoc;
|
||||
use crate::CodeOffset;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasmer_runtime::TrapCode;
|
||||
|
||||
/// Information about trap.
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TrapInformation {
|
||||
/// The offset of the trapping instruction in native code. It is relative to the beginning of the function.
|
||||
pub code_offset: CodeOffset,
|
||||
|
||||
@@ -5,16 +5,19 @@
|
||||
//! function called that one, and so forth.
|
||||
//!
|
||||
//! More info: https://en.wikipedia.org/wiki/Call_stack
|
||||
use crate::std::vec::Vec;
|
||||
use crate::lib::std::vec::Vec;
|
||||
use crate::{Addend, CodeOffset};
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Relocation Entry data
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FDERelocEntry(pub i64, pub usize, pub u8);
|
||||
|
||||
/// Relocation entry for unwind info.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FunctionTableReloc {
|
||||
/// Entry offest in the code block.
|
||||
pub offset: CodeOffset,
|
||||
@@ -29,7 +32,8 @@ pub struct FunctionTableReloc {
|
||||
/// > fields.
|
||||
///
|
||||
/// [unwind info]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum CompiledFunctionUnwindInfo {
|
||||
/// Windows UNWIND_INFO.
|
||||
Windows(Vec<u8>),
|
||||
|
||||
Reference in New Issue
Block a user