diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2025-04-16 15:59:03 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2025-04-16 15:59:03 +0200 |
| commit | 9c6c09994bb8605e23782f4267f6e187a492e028 (patch) | |
| tree | 5dee2f3d3f1f767d7bfc5b5ad2801aa056c19983 /lib | |
| parent | 1dcb601fb5332e41058de2bf753b0981d5d0228f (diff) | |
Add Fibonacci Test
We compile, link, and load a module. We are still erroring out, but we
are getting closer little by litte!
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/wamr/Makefile | 1 | ||||
| -rw-r--r-- | lib/wamr/core/shared/platform/stub/platform_internal.h | 9 | ||||
| -rw-r--r-- | lib/wamr/core/shared/platform/stub/stubs.c | 105 | ||||
| -rw-r--r-- | lib/wamr/test/main.c | 46 |
4 files changed, 152 insertions, 9 deletions
diff --git a/lib/wamr/Makefile b/lib/wamr/Makefile index 5946e8d..2d4a1ff 100644 --- a/lib/wamr/Makefile +++ b/lib/wamr/Makefile @@ -16,6 +16,7 @@ SRC = core/iwasm/common/arch/invokeNative_general.c \ core/shared/mem-alloc/ems/ems_hmu.c \ core/shared/mem-alloc/ems/ems_kfc.c \ core/shared/mem-alloc/mem_alloc.c \ + core/shared/platform/stub/stubs.c \ core/shared/utils/bh_assert.c \ core/shared/utils/bh_bitmap.c \ core/shared/utils/bh_common.c \ diff --git a/lib/wamr/core/shared/platform/stub/platform_internal.h b/lib/wamr/core/shared/platform/stub/platform_internal.h index 62e105e..4677c25 100644 --- a/lib/wamr/core/shared/platform/stub/platform_internal.h +++ b/lib/wamr/core/shared/platform/stub/platform_internal.h @@ -10,20 +10,17 @@ #include <stdlib.h> #include <string.h> -extern uint32_t os_getpagesize(); - typedef int os_dir_stream; typedef int os_file_handle; typedef int os_raw_file_handle; -static inline os_file_handle os_get_invalid_handle(void) { - return -1; -} - typedef int korp_cond; typedef int korp_mutex; typedef int korp_rwlock; typedef int korp_sem; typedef int korp_tid; +extern uint32_t os_getpagesize(void); +extern os_file_handle os_get_invalid_handle(void); + #endif diff --git a/lib/wamr/core/shared/platform/stub/stubs.c b/lib/wamr/core/shared/platform/stub/stubs.c new file mode 100644 index 0000000..59e560b --- /dev/null +++ b/lib/wamr/core/shared/platform/stub/stubs.c @@ -0,0 +1,105 @@ +#include "platform_api_extension.h" +#include "platform_api_vmcore.h" +#include "platform_internal.h" + +int bh_platform_init(void) { + return 0; +} + +void bh_platform_destroy(void) { + return; +} + +#define NOT_IMPLEMENTED(n) \ + do { \ + fprintf(stderr, "'%s' is not implemented\n", n); \ + abort(); \ + } while (0) + +void *os_malloc(unsigned int size) { + NOT_IMPLEMENTED("os_malloc"); +} + +void *os_realloc(void *ptr, unsigned int size) { + NOT_IMPLEMENTED("os_realloc"); +} + +void os_free(void *ptr) { + NOT_IMPLEMENTED("os_free"); +} + +int os_printf(const char *format, ...) { + NOT_IMPLEMENTED("os_printf"); +} + +int os_vprintf(const char *format, va_list ap) { + NOT_IMPLEMENTED("os_vprintf"); +} + +uint64_t os_time_get_boot_us(void) { + NOT_IMPLEMENTED("os_time_get_boot_us"); +} + +korp_tid os_self_thread(void) { + NOT_IMPLEMENTED("os_self_thread"); +} + +uint8_t *os_thread_get_stack_boundary(void) { + NOT_IMPLEMENTED("os_thread_get_stack_boundary"); +} + +int os_mutex_init(korp_mutex *mutex) { + return 0; + // TODO: NOT_IMPLEMENTED("os_mutex_init"); +} + +int os_mutex_destroy(korp_mutex *mutex) { + return 0; + // TODO: NOT_IMPLEMENTED("os_mutex_destroy"); +} + +int os_mutex_lock(korp_mutex *mutex) { + return 0; + // TODO: NOT_IMPLEMENTED("os_mutex_lock"); +} + +int os_mutex_unlock(korp_mutex *mutex) { + return 0; + // TODO: NOT_IMPLEMENTED("os_mutex_unlock"); +} + +void *os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { + NOT_IMPLEMENTED("os_mmap"); +} + +void os_munmap(void *addr, size_t size) { + NOT_IMPLEMENTED("os_munmap"); +} + +int os_mprotect(void *addr, size_t size, int prot) { + NOT_IMPLEMENTED("os_mprotect"); +} + +void *os_mremap(void *old_addr, size_t old_size, size_t new_size) { + NOT_IMPLEMENTED("os_mremap"); +} + +int os_cond_init(korp_cond *cond) { + NOT_IMPLEMENTED("os_cond_init"); +} + +int os_cond_destroy(korp_cond *cond) { + NOT_IMPLEMENTED("os_cond_destroy"); +} + +int os_dumps_proc_mem_info(char *out, unsigned int size) { + NOT_IMPLEMENTED("os_dumps_proc_mem_info"); +} + +os_file_handle os_get_invalid_handle(void) { + NOT_IMPLEMENTED("os_get_invalid_handle"); +} + +uint32_t os_getpagesize(void) { + NOT_IMPLEMENTED("os_getpagesize"); +} diff --git a/lib/wamr/test/main.c b/lib/wamr/test/main.c index 2ae4912..bfec8a0 100644 --- a/lib/wamr/test/main.c +++ b/lib/wamr/test/main.c @@ -4,11 +4,51 @@ #include "wasm_export.h" +#define P_CHECK(x, name) \ + if (!(x)) { \ + perror(name); \ + return EXIT_FAILURE; \ + } + +#define WAMR_CHECK(x, err) \ + if (!(x)) { \ + fprintf(stderr, "ERROR: %s\n", err); \ + return EXIT_FAILURE; \ + } + int main(int argc, char *argv[argc + 1]) { - FILE *f = fopen("fibonacci.wasm", "w"); - assert(f); + uint8_t wasm[1024]; + size_t wasmsz; + { + FILE *f = fopen("fibonacci.wasm", "r"); + P_CHECK(f, "fopen"); + wasmsz = fread(wasm, 1, sizeof wasm, f); + P_CHECK(wasmsz, "fread"); + P_CHECK(fclose(f) == 0, "fclose"); + } + + char err[1024]; + uint8_t heap[16 * 1024 * 1024]; + + struct RuntimeInitArgs init = {0}; + { + init.mem_alloc_type = Alloc_With_Pool; + init.mem_alloc_option.pool.heap_buf = heap; + init.mem_alloc_option.pool.heap_size = sizeof heap; + init.native_module_name = "fibonacci.wasm"; + init.native_symbols = NULL; + init.n_native_symbols = 0; + init.running_mode = Mode_Interp; + } + + wasm_runtime_full_init(&init); + + wasm_module_t module = wasm_runtime_load(wasm, sizeof wasm, err, sizeof err); + WAMR_CHECK(module, err); - wasm_runtime_init(); + wasm_module_inst_t instance = + wasm_runtime_instantiate(module, 8092, 8092, err, sizeof err); + WAMR_CHECK(instance, err); return EXIT_SUCCESS; } |
