zingen/
result.rs

1//! Codegen results
2
3/// Codegen error
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    /// Any error
7    #[error("{0}")]
8    Anyhow(#[from] anyhow::Error),
9    /// Failed to parse function ABI.
10    #[error(transparent)]
11    Abi(#[from] zabi::result::Error),
12    /// Failed to parse WASM with binary reader.
13    #[error(transparent)]
14    BinaryReader(#[from] wasmparser::BinaryReaderError),
15    /// Failed to push more data to the buffer.
16    #[error("Buffer overflow: {0}, the limit of the binary buffer is 0x6000.")]
17    BufferOverflow(usize),
18    /// Failed to pop control stack frame.
19    #[error("Control stack underflow")]
20    ControlStackUnderflow,
21    /// Data not found in data section.
22    #[error("Data not found in data setction, offset {0}, size {1}")]
23    DataNotFound(i32, usize),
24    /// Failed to register program counter to function index.
25    #[error("Function {0} already exists in jump table")]
26    DuplicateFunc(u32),
27    /// Failed to merge jump table.
28    #[error("Program counter {0} already exists in jump table")]
29    DuplicateJump(u16),
30    /// Failed to find ext function index in jump table.
31    #[error("External function not found in jump table")]
32    ExtFuncNotFound,
33    /// Failed to find function index in jump table.
34    #[error("Function {0} not found in jump table")]
35    FuncNotFound(u32),
36    /// Failed to find function index in jump table.
37    #[error("Function {0} not imported")]
38    FuncNotImported(String),
39    /// Failed to find host function in compiler.
40    #[error("Host function {0}::{1} not found in compiler")]
41    HostFuncNotFound(String, String),
42    /// Failed to find imported function by index in jump table.
43    #[error("Imported Function {0} not found in jump table")]
44    ImportedFuncNotFound(u32),
45    /// Failed to mark else block for if block.
46    #[error("Invalid else block for if block at {0}")]
47    InvalidElseBlock(u16),
48    /// Failed parse function signature.
49    #[error("Invalid function signature")]
50    InvalidFunctionSignature,
51    /// Failed to get local with given index.
52    #[error("Invalid local index {0}")]
53    InvalidLocalIndex(usize),
54    /// Failed to get the offset of the given memory pointer.
55    #[error("Invalid memory pointer {0}")]
56    InvalidMP(u8),
57    /// Failed to construct program counter for jump.
58    #[error("Invalid program counter {0}")]
59    InvalidPC(usize),
60    /// Failed to get data from the provided offset.
61    #[error("Invalid data offset {0}")]
62    InvalidDataOffset(i32),
63    /// Failed to get data from the provided offset.
64    #[error("Invalid data size {0}")]
65    InvalidDataSize(usize),
66    /// Failed to get frame info of the given depth.
67    #[error("Invalid contract stack frame depth {0}")]
68    InvalidDepth(usize),
69    /// Failed to parse function selector.
70    #[error("Invalid function selector")]
71    InvalidSelector,
72    /// Failed to patch jump destination.
73    #[error("Invalid frame label")]
74    LabelMismatch,
75    /// Failed to define local variable since the index is out of range.
76    #[error("Local index in function is out of range")]
77    LocalIndexOutOfRange,
78    /// Failed to get local variables.
79    #[error("Local variable {0} is not on stack")]
80    LocalNotOnStack(usize),
81    /// Failed to index data on memory.
82    #[error("Memory index is out of range")]
83    MemoryOutOfBounds,
84    /// Failed to find function selectors.0
85    #[error("Function selector is not found.")]
86    SelectorNotFound,
87    /// Failed to index data on stack.
88    #[error("Stack index is out of range {0}, max is 255 (0x400)")]
89    StackIndexOutOfRange(u16),
90    /// Failed to increment stack pointer.
91    #[error("Stack overflow, max is 1024 stack items, but add {1} to {0}")]
92    StackOverflow(u16, u16),
93    /// Failed to decrement stack pointer.
94    #[error("Stack underflow, current stack items {0}, expect at least {1}")]
95    StackUnderflow(u16, u16),
96    /// Failed to pop stack.
97    #[error("Stack not balanced, current stack items {0}")]
98    StackNotBalanced(u16),
99    /// Failed to queue host functions.
100    #[error("Unsupported host function {0:?}")]
101    UnsupportedHostFunc(crate::wasm::HostFunc),
102}
103
104/// Codegen result
105pub type Result<T> = std::result::Result<T, Error>;