serde
This commit is contained in:
parent
87e06c1242
commit
8db8a02347
|
@ -26,6 +26,7 @@ indexmap = "2.2.2"
|
||||||
stacker = "0.1.15"
|
stacker = "0.1.15"
|
||||||
wasm-smith = { version = "0.202", optional = true }
|
wasm-smith = { version = "0.202", optional = true }
|
||||||
paste = "1.0.15"
|
paste = "1.0.15"
|
||||||
|
serde = { version = "1.0.204", features = ["derive"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub trait EntityRef: Clone + Copy + PartialEq + Eq + PartialOrd + Ord + Hash {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! declare_entity {
|
macro_rules! declare_entity {
|
||||||
($name:tt, $prefix:tt) => {
|
($name:tt, $prefix:tt) => {
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct $name(u32);
|
pub struct $name(u32);
|
||||||
|
|
||||||
impl $crate::entity::EntityRef for $name {
|
impl $crate::entity::EntityRef for $name {
|
||||||
|
@ -73,7 +73,7 @@ macro_rules! declare_entity {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct EntityVec<Idx: EntityRef, T: Clone + Debug>(Vec<T>, PhantomData<Idx>);
|
pub struct EntityVec<Idx: EntityRef, T: Clone + Debug>(Vec<T>, PhantomData<Idx>);
|
||||||
|
|
||||||
impl<Idx: EntityRef, T: Clone + Debug> std::default::Default for EntityVec<Idx, T> {
|
impl<Idx: EntityRef, T: Clone + Debug> std::default::Default for EntityVec<Idx, T> {
|
||||||
|
@ -151,7 +151,7 @@ impl<Idx: EntityRef, T: Clone + Debug> IndexMut<Idx> for EntityVec<Idx, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct PerEntity<Idx: EntityRef, T: Clone + Debug + Default>(Vec<T>, PhantomData<Idx>, T);
|
pub struct PerEntity<Idx: EntityRef, T: Clone + Debug + Default>(Vec<T>, PhantomData<Idx>, T);
|
||||||
|
|
||||||
impl<Idx: EntityRef, T: Clone + Debug + Default> Index<Idx> for PerEntity<Idx, T> {
|
impl<Idx: EntityRef, T: Clone + Debug + Default> Index<Idx> for PerEntity<Idx, T> {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::{declare_entity, entity::EntityRef};
|
use crate::{declare_entity, entity::EntityRef};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
I32,
|
I32,
|
||||||
I64,
|
I64,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
||||||
declare_entity!(SourceFile, "file");
|
declare_entity!(SourceFile, "file");
|
||||||
declare_entity!(SourceLoc, "loc");
|
declare_entity!(SourceLoc, "loc");
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Debug {
|
pub struct Debug {
|
||||||
pub source_files: EntityVec<SourceFile, String>,
|
pub source_files: EntityVec<SourceFile, String>,
|
||||||
source_file_dedup: HashMap<String, SourceFile>,
|
source_file_dedup: HashMap<String, SourceFile>,
|
||||||
|
@ -17,7 +17,7 @@ pub struct Debug {
|
||||||
source_loc_dedup: HashMap<SourceLocData, SourceLoc>,
|
source_loc_dedup: HashMap<SourceLocData, SourceLoc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct SourceLocData {
|
pub struct SourceLocData {
|
||||||
pub file: SourceFile,
|
pub file: SourceFile,
|
||||||
pub line: u32,
|
pub line: u32,
|
||||||
|
@ -46,7 +46,7 @@ impl Debug {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct DebugMap {
|
pub struct DebugMap {
|
||||||
/// Offset of code section relative to the Wasm file start.
|
/// Offset of code section relative to the Wasm file start.
|
||||||
pub code_offset: u32,
|
pub code_offset: u32,
|
||||||
|
|
|
@ -13,12 +13,12 @@ use std::collections::HashSet;
|
||||||
|
|
||||||
/// A declaration of a function: there is one `FuncDecl` per `Func`
|
/// A declaration of a function: there is one `FuncDecl` per `Func`
|
||||||
/// index.
|
/// index.
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum FuncDecl<'a> {
|
pub enum FuncDecl<'a> {
|
||||||
/// An imported function.
|
/// An imported function.
|
||||||
Import(Signature, String),
|
Import(Signature, String),
|
||||||
/// An un-expanded body that can be lazily expanded if needed.
|
/// An un-expanded body that can be lazily expanded if needed.
|
||||||
Lazy(Signature, String, wasmparser::FunctionBody<'a>),
|
#[serde(skip)]Lazy(Signature, String, wasmparser::FunctionBody<'a>),
|
||||||
/// A modified or new function body that requires compilation.
|
/// A modified or new function body that requires compilation.
|
||||||
Body(Signature, String, FunctionBody),
|
Body(Signature, String, FunctionBody),
|
||||||
/// A compiled function body (was IR, has been collapsed back to bytecode).
|
/// A compiled function body (was IR, has been collapsed back to bytecode).
|
||||||
|
@ -113,7 +113,7 @@ impl<'a> FuncDecl<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct FunctionBody {
|
pub struct FunctionBody {
|
||||||
/// How many parameters the function has. (Their types are the
|
/// How many parameters the function has. (Their types are the
|
||||||
/// first `n_params` values in `locals`.)
|
/// first `n_params` values in `locals`.)
|
||||||
|
@ -481,7 +481,7 @@ impl FunctionBody {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct BlockDef {
|
pub struct BlockDef {
|
||||||
/// Instructions in this block.
|
/// Instructions in this block.
|
||||||
pub insts: Vec<Value>,
|
pub insts: Vec<Value>,
|
||||||
|
@ -501,7 +501,7 @@ pub struct BlockDef {
|
||||||
pub desc: String,
|
pub desc: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct BlockTarget {
|
pub struct BlockTarget {
|
||||||
pub block: Block,
|
pub block: Block,
|
||||||
pub args: Vec<Value>,
|
pub args: Vec<Value>,
|
||||||
|
@ -518,7 +518,7 @@ impl std::fmt::Display for BlockTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum Terminator {
|
pub enum Terminator {
|
||||||
Br {
|
Br {
|
||||||
target: BlockTarget,
|
target: BlockTarget,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use indexmap::IndexMap;
|
||||||
|
|
||||||
pub use crate::frontend::FrontendOptions;
|
pub use crate::frontend::FrontendOptions;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Module<'a> {
|
pub struct Module<'a> {
|
||||||
pub orig_bytes: &'a [u8],
|
pub orig_bytes: &'a [u8],
|
||||||
pub funcs: EntityVec<Func, FuncDecl<'a>>,
|
pub funcs: EntityVec<Func, FuncDecl<'a>>,
|
||||||
|
@ -23,13 +23,13 @@ pub struct Module<'a> {
|
||||||
pub custom_sections: IndexMap<String, Vec<u8>>,
|
pub custom_sections: IndexMap<String, Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct SignatureData {
|
pub struct SignatureData {
|
||||||
pub params: Vec<Type>,
|
pub params: Vec<Type>,
|
||||||
pub returns: Vec<Type>,
|
pub returns: Vec<Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct MemoryData {
|
pub struct MemoryData {
|
||||||
pub initial_pages: usize,
|
pub initial_pages: usize,
|
||||||
pub maximum_pages: Option<usize>,
|
pub maximum_pages: Option<usize>,
|
||||||
|
@ -38,13 +38,13 @@ pub struct MemoryData {
|
||||||
pub shared: bool,
|
pub shared: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct MemorySegment {
|
pub struct MemorySegment {
|
||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct TableData {
|
pub struct TableData {
|
||||||
pub ty: Type,
|
pub ty: Type,
|
||||||
pub initial: u64,
|
pub initial: u64,
|
||||||
|
@ -52,7 +52,7 @@ pub struct TableData {
|
||||||
pub func_elements: Option<Vec<Func>>,
|
pub func_elements: Option<Vec<Func>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GlobalData {
|
pub struct GlobalData {
|
||||||
pub ty: Type,
|
pub ty: Type,
|
||||||
pub value: Option<u64>,
|
pub value: Option<u64>,
|
||||||
|
@ -81,14 +81,14 @@ impl From<wasmparser::FuncType> for SignatureData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Import {
|
pub struct Import {
|
||||||
pub module: String,
|
pub module: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub kind: ImportKind,
|
pub kind: ImportKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum ImportKind {
|
pub enum ImportKind {
|
||||||
Table(Table),
|
Table(Table),
|
||||||
Func(Func),
|
Func(Func),
|
||||||
|
@ -108,13 +108,13 @@ impl std::fmt::Display for ImportKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Export {
|
pub struct Export {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub kind: ExportKind,
|
pub kind: ExportKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum ExportKind {
|
pub enum ExportKind {
|
||||||
Table(Table),
|
Table(Table),
|
||||||
Func(Func),
|
Func(Func),
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::{Block, Type, Value};
|
||||||
use crate::pool::{ListPool, ListRef};
|
use crate::pool::{ListPool, ListRef};
|
||||||
use crate::Operator;
|
use crate::Operator;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum ValueDef {
|
pub enum ValueDef {
|
||||||
BlockParam(Block, u32, Type),
|
BlockParam(Block, u32, Type),
|
||||||
Operator(Operator, ListRef<Value>, ListRef<Type>),
|
Operator(Operator, ListRef<Value>, ListRef<Type>),
|
||||||
|
|
|
@ -5,7 +5,7 @@ use anyhow::Context;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
pub use wasmparser::{Ieee32, Ieee64};
|
pub use wasmparser::{Ieee32, Ieee64};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct MemoryArg {
|
pub struct MemoryArg {
|
||||||
pub align: u32,
|
pub align: u32,
|
||||||
pub offset: u64 ,
|
pub offset: u64 ,
|
||||||
|
@ -23,7 +23,7 @@ impl std::fmt::Display for MemoryArg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum Operator {
|
pub enum Operator {
|
||||||
Unreachable,
|
Unreachable,
|
||||||
Nop,
|
Nop,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::fmt::Debug;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ListPool<T: Clone + Debug> {
|
pub struct ListPool<T: Clone + Debug> {
|
||||||
pub storage: Vec<T>,
|
pub storage: Vec<T>,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ impl<T: Clone + Debug> Default for ListPool<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ListRef<T>(u32, u32, PhantomData<T>);
|
pub struct ListRef<T>(u32, u32, PhantomData<T>);
|
||||||
|
|
||||||
impl<T> Default for ListRef<T> {
|
impl<T> Default for ListRef<T> {
|
||||||
|
|
Loading…
Reference in a new issue