|
11 | 11 | extern "C" { |
12 | 12 | #endif |
13 | 13 |
|
14 | | -bool fizzy_validate(const uint8_t* wasm_binary, size_t wasm_binary_size); |
15 | | - |
| 14 | +/// The opaque data type representing a module. |
16 | 15 | struct fizzy_module; |
17 | 16 |
|
18 | | -struct fizzy_module* fizzy_parse(const uint8_t* wasm_binary, size_t wasm_binary_size); |
19 | | - |
20 | | -void fizzy_free_module(struct fizzy_module*); |
| 17 | +/// The opaque data type representing an instance (instantiated module). |
| 18 | +struct fizzy_instance; |
21 | 19 |
|
| 20 | +/// The data type representing numeric values. |
| 21 | +/// |
| 22 | +/// i64 member is used to represent values of both i32 and i64 type. |
22 | 23 | union fizzy_value |
23 | 24 | { |
24 | 25 | uint64_t i64; |
25 | 26 | float f32; |
26 | 27 | double f64; |
27 | 28 | }; |
28 | 29 |
|
| 30 | +/// Result of execution of a function. |
29 | 31 | typedef struct fizzy_execution_result |
30 | 32 | { |
| 33 | + /// Whether execution ended with a trap. |
31 | 34 | bool trapped; |
| 35 | + /// Whether function returned a value. Valid only if trapped == false |
32 | 36 | bool has_value; |
| 37 | + /// Value returned from a function. Valid only if has_value == true |
33 | 38 | union fizzy_value value; |
34 | 39 | } fizzy_execution_result; |
35 | 40 |
|
36 | | -struct fizzy_instance; |
37 | 41 |
|
| 42 | +/// Pointer to external function. |
| 43 | +/// |
| 44 | +/// @param context Opaque pointer to execution context. |
| 45 | +/// @param instance Pointer to module instance. |
| 46 | +/// @param args Pointer to the argument array. |
| 47 | +/// @param args_size Size of the argument array. |
| 48 | +/// @param depth Call stack depth. |
38 | 49 | typedef struct fizzy_execution_result (*fizzy_external_fn)(void* context, |
39 | | - struct fizzy_instance* instance, const union fizzy_value* args, uint32_t cargs_size, int depth); |
| 50 | + struct fizzy_instance* instance, const union fizzy_value* args, uint32_t args_size, int depth); |
40 | 51 |
|
| 52 | +/// External function. |
41 | 53 | typedef struct fizzy_external_function |
42 | 54 | { |
43 | 55 | // TODO function type |
| 56 | + |
| 57 | + /// Pointer to function. |
44 | 58 | fizzy_external_fn function; |
| 59 | + /// Opaque pointer to execution context, that will be passed to function. |
45 | 60 | void* context; |
46 | 61 | } fizzy_external_function; |
47 | 62 |
|
48 | | -// Takes ownership of module. |
| 63 | +/// Validate binary module. |
| 64 | +bool fizzy_validate(const uint8_t* wasm_binary, size_t wasm_binary_size); |
| 65 | + |
| 66 | +/// Parse binary module. |
| 67 | +struct fizzy_module* fizzy_parse(const uint8_t* wasm_binary, size_t wasm_binary_size); |
| 68 | + |
| 69 | +/// Free resources associated with the module. |
| 70 | +void fizzy_free_module(struct fizzy_module* module); |
| 71 | + |
| 72 | +/// Instantiate a module. |
| 73 | +/// Takes ownership of module. |
| 74 | +/// |
| 75 | +/// @param module Pointer to module. |
| 76 | +/// @param imported_functions Pointer to the imported function array. |
| 77 | +/// @param imported_functions_size Size of the imported function array. |
49 | 78 | struct fizzy_instance* fizzy_instantiate(struct fizzy_module* module, |
50 | 79 | const struct fizzy_external_function* imported_functions, uint32_t imported_functions_size); |
51 | 80 |
|
52 | | -void fizzy_free_instance(struct fizzy_instance*); |
| 81 | +/// Free resources associated with the instance. |
| 82 | +void fizzy_free_instance(struct fizzy_instance* instance); |
53 | 83 |
|
| 84 | +/// Execute module function. |
| 85 | +/// |
| 86 | +/// @param instance Pointer to module instance. |
| 87 | +/// @param args Pointer to the argument array. |
| 88 | +/// @param args_size Size of the argument array. |
| 89 | +/// @param depth Call stack depth. |
54 | 90 | fizzy_execution_result fizzy_execute(struct fizzy_instance* instance, uint32_t func_idx, |
55 | 91 | const union fizzy_value* args, uint32_t args_size, int depth); |
56 | 92 |
|
|
0 commit comments