Skip to content

Commit

Permalink
Add WASM_RT_OPTIMIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Sep 6, 2024
1 parent bd6243d commit 820f8b4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ WASM ?= test/$(APP).wasm

include $(MPY_DIR)/py/dynruntime.mk

#-DWASM_RT_OPTIMIZE -Ofast
CFLAGS += -Os -Iruntime -I$(BUILD) -Wno-unused-value -Wno-unused-function \
-Wno-unused-variable -Wno-unused-but-set-variable

Expand Down
12 changes: 6 additions & 6 deletions runtime/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ size_t strlen(const char *str) {
}

int strncmp(const char *_l, const char *_r, size_t n) {
const unsigned char *l=(void *)_l, *r=(void *)_r;
if (!n--) return 0;
for (; *l && *r && n && *l == *r ; l++, r++, n--);
return *l - *r;
const unsigned char *l=(void *)_l, *r=(void *)_r;
if (!n--) return 0;
for (; *l && *r && n && *l == *r ; l++, r++, n--);
return *l - *r;
}

void abort() {
Expand All @@ -61,10 +61,10 @@ void abort() {

#if defined(__ARM_EABI__)
int __aeabi_idiv0(int ret) {
return ret;
return ret;
}

long long __aeabi_ldiv0(long long ret) {
return ret;
return ret;
}
#endif
4 changes: 4 additions & 0 deletions runtime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ void os_print_last_error(const char* msg) {
}

void wasm_rt_trap_handler(wasm_rt_trap_t code) {
#if WASM_RT_OPTIMIZE
mp_printf(&mp_plat_print, "Trap: %d\n", code);
#else
mp_printf(&mp_plat_print, "Trap: %s\n", wasm_rt_strerror(code));
#endif
abort();
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/wasm-rt-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void wasm_rt_free_thread(void) {
#include "wasm-rt-impl-tableops.inc"
#undef WASM_RT_TABLE_OPS_EXTERNREF

#if !WASM_RT_OPTIMIZE
const char* wasm_rt_strerror(wasm_rt_trap_t trap) {
switch (trap) {
case WASM_RT_TRAP_NONE:
Expand Down Expand Up @@ -291,3 +292,4 @@ const char* wasm_rt_strerror(wasm_rt_trap_t trap) {
}
return "invalid trap code";
}
#endif
6 changes: 5 additions & 1 deletion runtime/wasm-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ extern "C" {
#define WASM_RT_THREAD_LOCAL
#endif

#ifndef WASM_RT_OPTIMIZE
#define WASM_RT_OPTIMIZE 0
#endif

/**
* If enabled, perform additional sanity checks in the generated wasm2c code and
* wasm2c runtime. This is useful to enable on debug builds.
Expand Down Expand Up @@ -206,7 +210,7 @@ extern "C" {
* Wasm's specification, and may compromise security. Use with caution.
*/
#ifndef WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION
#define WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 0
#define WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION WASM_RT_OPTIMIZE
#endif

/**
Expand Down

0 comments on commit 820f8b4

Please sign in to comment.