include + update old linux targets/host.c

This commit is contained in:
2026-03-05 19:16:03 +01:00
parent 6ab17c98e9
commit e6237cc06e
10 changed files with 241 additions and 125 deletions

View File

@ -8,7 +8,8 @@
#include "__WASM_ARRAY_FILE__"
#define STACK_SIZE (4 * 1024)
#define HEAP_SIZE (4 * 1024)
#define HEAP_SIZE STACK_SIZE
#define RUNTIME_POOL_SIZE 4 * STACK_SIZE
// TODO: Set this up so the lsp actually finds the includes...
@ -20,10 +21,11 @@ MAIN() {
wasm_exec_env_t exec_env;
/* initialize the wasm runtime */
static char global_heap_buf[HEAP_SIZE];
RuntimeInitArgs init_args;
static char global_heap_buf[RUNTIME_POOL_SIZE];
static RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
// init_args.mem_alloc_type = Alloc_With_System_Allocator;
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
@ -36,10 +38,20 @@ MAIN() {
module = wasm_runtime_load(__WASM_ARRAY__, __WASM_ARRAY_LEN__, error_buf,
sizeof(error_buf));
if (!module) {
// printf("Load failed: %s\n", error_buf);
return;
}
/* create an instance of the WASM module (WASM linear memory is ready) */
module_inst = wasm_runtime_instantiate(module, STACK_SIZE, HEAP_SIZE,
error_buf, sizeof(error_buf));
if (!module_inst) {
// printf("Inst failed: %s\n", error_buf);
return;
}
/* lookup a WASM function by its name, the function signature can NULL here */
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
@ -53,11 +65,11 @@ MAIN() {
MARKER(start_trace);
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
/* function wasn't called correctly */
POSIX_PRINTF("Failed to call function 'wasm_module'!\n");
// printf("Failed to call function 'wasm_module'!\n");
}
MARKER(stop_trace);
POSIX_PRINTF("Sum: %d\n!", args[0]);
// printf("Sum: %d\n", args[0]);
/* the return value is stored in args[0] */
if (args[0] == 100) {
@ -70,4 +82,6 @@ MAIN() {
wasm_runtime_deinstantiate(module_inst);
wasm_runtime_unload(module);
wasm_runtime_destroy();
return;
}