|
4 | 4 |
|
5 | 5 | #include <fizzy/fizzy.h> |
6 | 6 |
|
7 | | -bool dummy(void); |
| 7 | +bool validate(const uint8_t* binary, size_t size); |
| 8 | +bool parse(const uint8_t* binary, size_t size); |
| 9 | +bool instantiate(const uint8_t* binary, size_t size); |
| 10 | +struct FizzyExecutionResult dummy_host_func(void* context, struct FizzyInstance* instance, |
| 11 | + const union FizzyValue* args, size_t args_size, int depth); |
| 12 | +bool instantiate_with_host_func(const uint8_t* binary, size_t size); |
| 13 | +bool execute(const uint8_t* binary, size_t size); |
8 | 14 |
|
9 | | -bool dummy() |
| 15 | +bool validate(const uint8_t* binary, size_t size) |
10 | 16 | { |
11 | | - return fizzy_validate(NULL, 0); |
| 17 | + return fizzy_validate(binary, size); |
| 18 | +} |
| 19 | + |
| 20 | +bool parse(const uint8_t* binary, size_t size) |
| 21 | +{ |
| 22 | + struct FizzyModule* module = fizzy_parse(binary, size); |
| 23 | + if (!module) |
| 24 | + return false; |
| 25 | + |
| 26 | + fizzy_free_module(module); |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +bool instantiate(const uint8_t* binary, size_t size) |
| 31 | +{ |
| 32 | + struct FizzyModule* module = fizzy_parse(binary, size); |
| 33 | + if (!module) |
| 34 | + return false; |
| 35 | + |
| 36 | + struct FizzyInstance* instance = fizzy_instantiate(module, NULL, 0); |
| 37 | + if (!instance) |
| 38 | + return false; |
| 39 | + |
| 40 | + fizzy_free_instance(instance); |
| 41 | + return true; |
| 42 | +} |
| 43 | + |
| 44 | +struct FizzyExecutionResult dummy_host_func(void* context, struct FizzyInstance* instance, |
| 45 | + const union FizzyValue* args, size_t args_size, int depth) |
| 46 | +{ |
| 47 | + (void)context; |
| 48 | + (void)instance; |
| 49 | + (void)args; |
| 50 | + (void)args_size; |
| 51 | + (void)depth; |
| 52 | + struct FizzyExecutionResult res = {true, false, {0}}; |
| 53 | + return res; |
| 54 | +} |
| 55 | + |
| 56 | +bool instantiate_with_host_func(const uint8_t* binary, size_t size) |
| 57 | +{ |
| 58 | + struct FizzyModule* module = fizzy_parse(binary, size); |
| 59 | + if (!module) |
| 60 | + return false; |
| 61 | + |
| 62 | + FizzyExternalFunction host_funcs[] = {{dummy_host_func, NULL}}; |
| 63 | + |
| 64 | + struct FizzyInstance* instance = fizzy_instantiate(module, host_funcs, 1); |
| 65 | + if (!instance) |
| 66 | + return false; |
| 67 | + |
| 68 | + fizzy_free_instance(instance); |
| 69 | + return true; |
| 70 | +} |
| 71 | + |
| 72 | +bool execute(const uint8_t* binary, size_t size) |
| 73 | +{ |
| 74 | + struct FizzyModule* module = fizzy_parse(binary, size); |
| 75 | + if (!module) |
| 76 | + return false; |
| 77 | + |
| 78 | + struct FizzyInstance* instance = fizzy_instantiate(module, NULL, 0); |
| 79 | + if (!instance) |
| 80 | + return false; |
| 81 | + |
| 82 | + fizzy_execute(instance, 0, NULL, 0); |
| 83 | + |
| 84 | + union FizzyValue args[] = {{1}, {2}}; |
| 85 | + fizzy_execute(instance, 1, args, 0); |
| 86 | + |
| 87 | + fizzy_free_instance(instance); |
| 88 | + return true; |
12 | 89 | } |
0 commit comments