bugfixes; most test cases pass
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 7 Jul 2022 03:20:47 +0000 (22:20 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 7 Jul 2022 03:20:47 +0000 (22:20 -0500)
build.sh
include/bh.h
src/vm/code_builder.c
src/vm/vm.c
src/wasm.c
src/wasm/module_parsing.c.incl

index 160e4565e3a07b4bdb49c758614569f3f8208fcd..e4095d852c2eba224e201e6293ee036675a9d936 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -2,7 +2,7 @@
 
 CC="gcc"
 WARNINGS='-Wimplicit -Wmisleading-indentation -Wparentheses -Wsequence-point -Wreturn-type -Wshift-negative-value -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wmaybe-uninitialized -Wsign-compare -Wstrict-overflow -Wduplicated-branches -Wduplicated-cond -Wtrigraphs -Waddress -Wlogical-op'
-FLAGS="-g3"
+FLAGS="-O3"
 LIBS="-pthread"
 INCLUDES="-I include"
 TARGET="libonyx_embedder.so"
index 55c940894bb0fbe798432a99de7924b1098ba6be..9ce04ef37ffbcfde9fe5c8cfbb7adde3708a1df9 100644 (file)
@@ -4,7 +4,11 @@
 #ifdef BH_STATIC
     #define BH_DEF static
 #else
-    #define BH_DEF
+    #ifdef BH_INTERNAL
+        #define BH_DEF __attribute__((visibility("hidden")))
+    #else
+        #define BH_DEF
+    #endif
 #endif
 
 // NOTE: For lseek64
@@ -1396,15 +1400,16 @@ BH_DEF i64 leb128_to_int(u8* bytes, i32 *byte_count) {
     u64 size = 64;
 
     u8 byte;
-    while (1) {
+    do {
         byte = bytes[(*byte_count)++];
         res |= (byte & 0x7f) << shift;
-        if ((byte & 0x80) == 0) break;
         shift += 7;
-    }
+    } while ((byte & 0x80) != 0);
 
     if ((shift < size) && (byte & 0x40) != 0) {
-        return res | ((~(u64) 0x0) << shift);
+        i64 zero_shifted = ~ 0x0;
+        zero_shifted = zero_shifted << shift;
+        return res | zero_shifted;
     }
     
     return res;
index 4f60d2c08cc3ad421306140524be1ca899e940cb..41dd1af0336a55dc57700a26facc62acfb3413a7 100644 (file)
@@ -14,7 +14,7 @@
 static inline int NEXT_VALUE(ovm_code_builder_t *b) {
 #if defined(BUILDER_DEBUG)
     b->highest_value_number += 1;
-    return b->highest_value_number;
+    return b->highest_value_number - 1;
 
 #else
     if (bh_arr_length(b->execution_stack) == 0) {
index 30fde47c5673dffb8cbaa63c49233f060bf12216..6ce7cef9972fc7dd08805fd3484472e0f476b8bc 100644 (file)
@@ -917,6 +917,7 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t
 
             case OVMI_MOV:
                 VAL(instr.r) = VAL(instr.a);
+                // printf("$%d = %lx\n", instr.r, VAL(instr.r).u64);
                 break;
 
 #define OVM_LOAD(type_, stype) \
@@ -1022,6 +1023,7 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t
             i32 fidx = func_idx; \
             ovm_func_t *func = &program->funcs[fidx]; \
             i32 extra_params = bh_arr_length(state->params) - func->param_count; \
+            assert(extra_params >= 0); \
             if (func->kind == OVM_FUNC_INTERNAL) { \
                 ovm__func_setup_stack_frame(engine, state, program, fidx, instr.r); \
  \
index 5a06b09e23adbd4e81faad9afbbaadd11b539150..83fed313fe731618264228cd15b420661d89cb5c 100644 (file)
@@ -1,5 +1,6 @@
 #define BH_DEFINE
 #define BH_NO_TABLE
+#define BH_INTERNAL
 #define STB_DS_IMPLEMENTATION
 #include "bh.h"
 #include "stb_ds.h"
index 2b095480c4f49277c12f18a6a65002d6d005f897..7ee0fce3801cbd57ea2154443a26b8687b6dc3f2 100644 (file)
@@ -697,7 +697,7 @@ static void parse_instruction(build_context *ctx) {
         }
 
         case 0x42: {
-            unsigned long long value = uleb128_to_uint(ctx->binary.data, &ctx->offset);
+            long long value = leb128_to_int(ctx->binary.data, &ctx->offset);
             ovm_code_builder_add_imm(&ctx->builder, OVM_TYPE_I64, &value);
             break;
         }