Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the serialize + deserialize traits to structs used by ExecutionResult #190

Open
wants to merge 1 commit into
base: non-continuation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/specs/src/brtable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;

use serde::Serialize;
use serde::Deserialize;

#[derive(Serialize, Debug, Clone)]
pub struct BrTableEntry {
Expand All @@ -25,15 +26,15 @@ impl BrTable {
}
}

#[derive(Serialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ElemEntry {
pub table_idx: u32,
pub type_idx: u32,
pub offset: u32,
pub func_idx: u32,
}

#[derive(Debug, Default, Serialize, Clone)]
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct ElemTable(BTreeMap<(u32, u32), ElemEntry>);

impl ElemTable {
Expand Down
3 changes: 2 additions & 1 deletion crates/specs/src/configure_table.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use serde::Serialize;
use serde::Deserialize;

// A wasm page size is 64KB
pub const WASM_BYTES_PER_PAGE: u64 = 64 * 1024 as u64;

const WASM_32_MAXIMAL_PAGES_DEFAULT: u32 = 65536;

#[derive(Serialize, Debug, Clone, Copy)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct ConfigureTable {
pub init_memory_pages: u32,
pub maximal_memory_pages: u32,
Expand Down
5 changes: 3 additions & 2 deletions crates/specs/src/etable.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use serde::Serialize;
use serde::Deserialize;

use super::itable::InstructionTableEntry;
use crate::host_function::HostPlugin;
use crate::step::StepInfo;

#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct EventTableEntry {
pub eid: u32,
pub sp: u32,
Expand Down Expand Up @@ -38,7 +39,7 @@ impl Iterator for RestJops {
}
}

#[derive(Debug, Default, Clone, Serialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct EventTable(Vec<EventTableEntry>);

impl EventTable {
Expand Down
3 changes: 2 additions & 1 deletion crates/specs/src/external_host_call_table/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use serde::ser::SerializeStruct;
use serde::Serialize;
use serde::Deserialize;

use crate::host_function::Signature;
use crate::types::ValueType;

pub mod encode;
mod table;

#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)]
pub enum ExternalHostCallSignature {
Argument,
Return,
Expand Down
5 changes: 3 additions & 2 deletions crates/specs/src/host_function.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use serde::Serialize;
use serde::Deserialize;

use crate::external_host_call_table::ExternalHostCallSignature;
use crate::types::ValueType;

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Signature {
pub params: Vec<ValueType>,
pub return_type: Option<ValueType>,
Expand Down Expand Up @@ -38,7 +39,7 @@ impl HostFunctionDesc {
}
}

#[derive(Clone, Debug, Serialize, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Clone, Debug, Serialize, Deserialize, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum HostPlugin {
HostInput = 0,
Context,
Expand Down
5 changes: 3 additions & 2 deletions crates/specs/src/imtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::cmp::Ordering;
use crate::mtable::LocationType;
use crate::mtable::VarType;
use serde::Serialize;
use serde::Deserialize;

#[derive(Serialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct InitMemoryTableEntry {
pub ltype: LocationType,
pub is_mutable: bool,
Expand All @@ -15,7 +16,7 @@ pub struct InitMemoryTableEntry {
pub value: u64,
}

#[derive(Serialize, Default, Debug, Clone)]
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
pub struct InitMemoryTable {
entries: Vec<InitMemoryTableEntry>,
sorted_global_init_entries: Vec<InitMemoryTableEntry>,
Expand Down
24 changes: 13 additions & 11 deletions crates/specs/src/itable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::mtable::MemoryStoreSize;
use crate::types::ValueType;
use num_bigint::BigUint;
use serde::Serialize;
use serde::Deserialize;
use std::collections::HashSet;
use strum_macros::EnumIter;

Expand Down Expand Up @@ -106,14 +107,14 @@ impl OpcodeClassPlain {
}
}

#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum UnaryOp {
Ctz,
Clz,
Popcnt,
}

#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum BinOp {
Add,
Sub,
Expand All @@ -124,7 +125,7 @@ pub enum BinOp {
SignedRem,
}

#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum ShiftOp {
Shl,
UnsignedShr,
Expand All @@ -133,7 +134,7 @@ pub enum ShiftOp {
Rotr,
}

#[derive(Copy, Clone, Debug, Serialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)]
pub enum BitOp {
And = 0,
Or = 1,
Expand All @@ -150,7 +151,7 @@ impl BitOp {
}
}

#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum RelOp {
Eq,
Ne,
Expand All @@ -164,12 +165,12 @@ pub enum RelOp {
UnsignedLe,
}

#[derive(Copy, Clone, Debug, Serialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)]
pub enum TestOp {
Eqz,
}

#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum ConversionOp {
I32WrapI64,
I64ExtendI32s,
Expand All @@ -181,14 +182,14 @@ pub enum ConversionOp {
I64Extend32S,
}

#[derive(Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct BrTarget {
pub drop: u32,
pub keep: Vec<ValueType>,
pub dst_pc: u32,
}

#[derive(Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum Opcode {
LocalGet {
vtype: VarType,
Expand Down Expand Up @@ -585,7 +586,7 @@ impl Into<OpcodeClassPlain> for Opcode {
}
}

#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct InstructionTableEntry {
pub fid: u32,
pub iid: u32,
Expand All @@ -605,7 +606,8 @@ impl InstructionTableEntry {
bn
}
}
#[derive(Default, Serialize, Debug, Clone)]

#[derive(Default, Serialize, Deserialize, Debug, Clone)]
pub struct InstructionTable(Vec<InstructionTableEntry>);

impl InstructionTable {
Expand Down
7 changes: 4 additions & 3 deletions crates/specs/src/jtable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::itable::InstructionTableEntry;
use serde::Serialize;
use serde::Deserialize;

#[derive(Default, Serialize, Debug, Clone)]
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
pub struct StaticFrameEntry {
pub enable: bool,
pub frame_id: u32,
Expand All @@ -11,7 +12,7 @@ pub struct StaticFrameEntry {
pub iid: u32,
}

#[derive(Debug, Serialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct JumpTableEntry {
// caller eid (unique)
pub eid: u32,
Expand All @@ -26,7 +27,7 @@ impl JumpTableEntry {
}
}

#[derive(Clone, Debug, Default, Serialize)]
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct JumpTable(Vec<JumpTableEntry>);

impl JumpTable {
Expand Down
7 changes: 4 additions & 3 deletions crates/specs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use jtable::JumpTable;
use jtable::StaticFrameEntry;
use mtable::MTable;
use serde::Serialize;
use serde::Deserialize;

#[macro_use]
extern crate lazy_static;
Expand All @@ -32,7 +33,7 @@ pub mod mtable;
pub mod step;
pub mod types;

#[derive(Default, Serialize, Debug, Clone)]
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
pub struct CompilationTable {
pub itable: InstructionTable,
pub imtable: InitMemoryTable,
Expand All @@ -42,14 +43,14 @@ pub struct CompilationTable {
pub fid_of_entry: u32,
}

#[derive(Default, Serialize, Clone)]
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct ExecutionTable {
pub etable: EventTable,
pub mtable: MTable,
pub jtable: JumpTable,
}

#[derive(Default, Clone)]
#[derive(Default, Clone, Serialize, Deserialize)]
pub struct Tables {
pub compilation_tables: CompilationTable,
pub execution_tables: ExecutionTable,
Expand Down
15 changes: 8 additions & 7 deletions crates/specs/src/mtable.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use std::collections::HashSet;

use serde::Serialize;
use serde::Deserialize;
use strum_macros::EnumIter;

use crate::imtable::InitMemoryTable;

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Hash)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash)]
pub enum LocationType {
Stack = 1,
Heap = 2,
Global = 3,
}

#[derive(Clone, Copy, Debug, PartialEq, Serialize, Hash, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Hash, Eq)]
pub enum AccessType {
Read = 1,
Write = 2,
Expand All @@ -25,7 +26,7 @@ impl AccessType {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Hash, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Deserialize, Hash, PartialOrd, Ord)]
pub enum VarType {
I64 = 0,
I32 = 1,
Expand All @@ -40,7 +41,7 @@ impl VarType {
}
}

#[derive(Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Hash, Eq, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Deserialize, Hash, Eq, PartialOrd, Ord)]
pub enum MemoryReadSize {
U8 = 1,
S8,
Expand All @@ -51,7 +52,7 @@ pub enum MemoryReadSize {
I64,
}

#[derive(Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Hash, Eq, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Deserialize, Hash, Eq, PartialOrd, Ord)]
pub enum MemoryStoreSize {
Byte8 = 1,
Byte16,
Expand Down Expand Up @@ -113,7 +114,7 @@ impl MemoryReadSize {
}
}

#[derive(Clone, Debug, Serialize, Hash, Eq, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
pub struct MemoryTableEntry {
pub eid: u32,
/*
Expand Down Expand Up @@ -141,7 +142,7 @@ impl MemoryTableEntry {
}
}

#[derive(Default, Debug, Serialize, Clone)]
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
pub struct MTable(Vec<MemoryTableEntry>);

impl MTable {
Expand Down
3 changes: 2 additions & 1 deletion crates/specs/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use crate::mtable::MemoryStoreSize;
use crate::mtable::VarType;
use crate::types::ValueType;
use serde::Serialize;
use serde::Deserialize;

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum StepInfo {
Br {
dst_pc: u32,
Expand Down
3 changes: 2 additions & 1 deletion crates/specs/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use serde::Serialize;
use serde::Deserialize;

use crate::external_host_call_table::ExternalHostCallSignature;
use crate::host_function::HostPlugin;
use crate::mtable::VarType;

#[derive(Clone, Copy, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum ValueType {
I32,
I64,
Expand Down
4 changes: 3 additions & 1 deletion crates/zkwasm/src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;
use serde::Deserialize;
use serde::Serialize;

use specs::etable::EventTableEntry;
use specs::external_host_call_table::ExternalHostCallSignature;
Expand All @@ -23,7 +25,7 @@ pub struct CompiledImage<I, T> {
pub tracer: Rc<RefCell<T>>,
}

#[derive(Clone)]
#[derive(Clone, Serialize, Deserialize)]
pub struct ExecutionResult<R> {
pub tables: Tables,
pub result: Option<R>,
Expand Down