mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
fix(compiler) Fix compilation errors when serde is absent.
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
|
||||
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.
|
||||
|
||||
@@ -9,6 +9,7 @@ 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 {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
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;
|
||||
@@ -19,7 +20,8 @@ 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,
|
||||
@@ -74,7 +76,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,
|
||||
@@ -87,7 +90,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),
|
||||
|
||||
@@ -7,18 +7,22 @@
|
||||
|
||||
use crate::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,7 +54,8 @@ pub struct CustomSection {
|
||||
}
|
||||
|
||||
/// The bytes in the section.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct SectionBody(#[serde(with = "serde_bytes")] Vec<u8>);
|
||||
|
||||
impl SectionBody {
|
||||
|
||||
@@ -5,14 +5,19 @@
|
||||
//! and tracing errors.
|
||||
|
||||
use core::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)]
|
||||
pub struct SourceLoc(u32);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
//! More info: https://en.wikipedia.org/wiki/Call_stack
|
||||
use crate::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