1use enum_iterator::IntoEnumIterator;
2use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
3#[cfg(feature = "enable-serde")]
4use serde::{Deserialize, Serialize};
5use std::fmt;
6
7#[derive(
11    Copy,
12    Clone,
13    Debug,
14    PartialEq,
15    Eq,
16    Hash,
17    IntoEnumIterator,
18    RkyvSerialize,
19    RkyvDeserialize,
20    Archive,
21)]
22#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
23#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))]
24#[rkyv(derive(Debug, Hash, PartialEq, Eq), compare(PartialEq))]
25#[repr(u16)]
26pub enum LibCall {
27    CeilF32,
29
30    CeilF64,
32
33    FloorF32,
35
36    FloorF64,
38
39    NearestF32,
41
42    NearestF64,
44
45    TruncF32,
47
48    TruncF64,
50
51    Memory32Size,
53
54    ImportedMemory32Size,
56
57    TableCopy,
59
60    TableInit,
62
63    TableFill,
65
66    TableSize,
68
69    ImportedTableSize,
71
72    TableGet,
74
75    ImportedTableGet,
77
78    TableSet,
80
81    ImportedTableSet,
83
84    TableGrow,
86
87    ImportedTableGrow,
89
90    FuncRef,
92
93    ElemDrop,
95
96    Memory32Copy,
98
99    ImportedMemory32Copy,
101
102    Memory32Fill,
104
105    ImportedMemory32Fill,
107
108    Memory32Init,
110
111    DataDrop,
113
114    RaiseTrap,
116
117    Probestack,
120
121    Memory32AtomicWait32,
123
124    ImportedMemory32AtomicWait32,
126
127    Memory32AtomicWait64,
129
130    ImportedMemory32AtomicWait64,
132
133    Memory32AtomicNotify,
135
136    ImportedMemory32AtomicNotify,
138
139    Throw,
141
142    AllocException,
144    ReadExnRef,
146    LibunwindExceptionIntoExnRef,
148
149    EHPersonality,
151    EHPersonality2,
153
154    DebugUsize,
156    DebugStr,
158}
159
160impl LibCall {
161    pub fn to_function_name(&self) -> &str {
163        match self {
164            Self::CeilF32 => "wasmer_vm_f32_ceil",
165            Self::CeilF64 => "wasmer_vm_f64_ceil",
166            Self::FloorF32 => "wasmer_vm_f32_floor",
167            Self::FloorF64 => "wasmer_vm_f64_floor",
168            Self::NearestF32 => "wasmer_vm_f32_nearest",
169            Self::NearestF64 => "wasmer_vm_f64_nearest",
170            Self::TruncF32 => "wasmer_vm_f32_trunc",
171            Self::TruncF64 => "wasmer_vm_f64_trunc",
172            Self::Memory32Size => "wasmer_vm_memory32_size",
173            Self::ImportedMemory32Size => "wasmer_vm_imported_memory32_size",
174            Self::TableCopy => "wasmer_vm_table_copy",
175            Self::TableInit => "wasmer_vm_table_init",
176            Self::TableFill => "wasmer_vm_table_fill",
177            Self::TableSize => "wasmer_vm_table_size",
178            Self::ImportedTableSize => "wasmer_vm_imported_table_size",
179            Self::TableGet => "wasmer_vm_table_get",
180            Self::ImportedTableGet => "wasmer_vm_imported_table_get",
181            Self::TableSet => "wasmer_vm_table_set",
182            Self::ImportedTableSet => "wasmer_vm_imported_table_set",
183            Self::TableGrow => "wasmer_vm_table_grow",
184            Self::ImportedTableGrow => "wasmer_vm_imported_table_grow",
185            Self::FuncRef => "wasmer_vm_func_ref",
186            Self::ElemDrop => "wasmer_vm_elem_drop",
187            Self::Memory32Copy => "wasmer_vm_memory32_copy",
188            Self::ImportedMemory32Copy => "wasmer_vm_imported_memory32_copy",
189            Self::Memory32Fill => "wasmer_vm_memory32_fill",
190            Self::ImportedMemory32Fill => "wasmer_vm_imported_memory32_fill",
191            Self::Memory32Init => "wasmer_vm_memory32_init",
192            Self::DataDrop => "wasmer_vm_data_drop",
193            Self::RaiseTrap => "wasmer_vm_raise_trap",
194            #[cfg(target_vendor = "apple")]
197            Self::Probestack => "_wasmer_vm_probestack",
198            #[cfg(not(target_vendor = "apple"))]
199            Self::Probestack => "wasmer_vm_probestack",
200            Self::Memory32AtomicWait32 => "wasmer_vm_memory32_atomic_wait32",
201            Self::ImportedMemory32AtomicWait32 => "wasmer_vm_imported_memory32_atomic_wait32",
202            Self::Memory32AtomicWait64 => "wasmer_vm_memory32_atomic_wait64",
203            Self::ImportedMemory32AtomicWait64 => "wasmer_vm_imported_memory32_atomic_wait64",
204            Self::Memory32AtomicNotify => "wasmer_vm_memory32_atomic_notify",
205            Self::ImportedMemory32AtomicNotify => "wasmer_vm_imported_memory32_atomic_notify",
206            Self::Throw => "wasmer_vm_throw",
207            Self::EHPersonality => "wasmer_eh_personality",
208            Self::EHPersonality2 => "wasmer_eh_personality2",
209            Self::AllocException => "wasmer_vm_alloc_exception",
210            Self::ReadExnRef => "wasmer_vm_read_exnref",
211            Self::LibunwindExceptionIntoExnRef => "wasmer_vm_exception_into_exnref",
212            Self::DebugUsize => "wasmer_vm_dbg_usize",
213            Self::DebugStr => "wasmer_vm_dbg_str",
214        }
215    }
216}
217
218impl fmt::Display for LibCall {
219    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
220        fmt::Debug::fmt(self, f)
221    }
222}