dfwasm_compiler/
lib.rs

1/*
2WASM State:
3- Compile Time:
4    - Functions:
5        - Defined functions are indexed
6        - Signatures known from Type section
7        - Imported functions also occupy indices
8    - Table(s)
9        - Initial Size and Type (only funcref atm)
10        - Maximum Size if specified
11        - Static Elements using (elem)
12    - Memories
13        - Initial and optional max size (in 64KiB pages)
14        - Export status
15        - Whether shared
16        - Contents are not static, but the type of memory is
17    - Globals
18        - Types, mutability
19        - Initial values (whether it be static or import/global)
20    - Imports
21        - Module and field names
22        - Type of import
23        - Type signatures of memory/table/global
24        - Index of memory/table/global
25    - Exports
26        - Name (not module name)
27        - Type of export (func/memory/global/table)
28        - Indices
29- At Execution:
30    - Imports
31        - Resolved into actual references: i.e. functions, memories, tables, or globals
32    - Execution Stack / Frame Stack
33        - StackFrame[]
34        - Locals stack
35            - Map<localIndex, Value>
36        - Operand stack
37            - Value[]
38    - Memories
39        - Map<memoryIndex, Map<address, Value>>
40        - Size of memory (can grow via `memory.grow`)
41    - Global(s) State
42        - Map<globalIndex, Value>
43        - Mutable globals are mutable, immutable variables are constant
44    - Table(s) State
45        - Map<tableIndex, Value[]>
46        - Can be modified at runtime
47*/
48use thiserror::Error;
49use wasmparser::BinaryReaderError;
50
51mod compiler;
52mod df_helper;
53mod operators;
54mod sections;
55
56type DFWasmResult<T> = std::result::Result<T, DFWasmError>;
57
58#[derive(Error, Debug)]
59pub enum DFWasmError {
60    #[error("error: {0}")]
61    ReadError(#[from] BinaryReaderError),
62
63    #[error("error: unsupported WASM version {0}")]
64    UnsupportedVersion(u16),
65    #[error("error: WASM components are not supported")]
66    UnsupportedComponents,
67    #[error("error: WASM tags are not supported")]
68    UnsupportedTags,
69    #[error("error: unsupported const expr")]
70    UnsupportedConstExpr,
71
72    #[error("error: unsupported operator {op} at location {location}")]
73    UnsupportedOperator { op: String, location: usize },
74
75    #[error("error: tables have a maximum size of 10000")]
76    MaximumTableSize,
77    #[error("error: multiple memories are not supported")]
78    MultipleMemories,
79    #[error("error: multiple start methods are not supported")]
80    MultipleStartMethods,
81
82    #[error("error: found unknown section with id {0}")]
83    UnknownSection(u8),
84    #[error("error: unknown payload")]
85    UnknownPayload,
86
87    #[error("error: {0} are not yet implemented")]
88    NotYetImplemented(&'static str),
89}
90
91pub use compiler::{DFWasmCompiler, DFWasmCompilerOptions};