added alternate backend, ovmwasm
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 17 Jul 2022 04:13:33 +0000 (23:13 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 17 Jul 2022 04:13:33 +0000 (23:13 -0500)
build.sh
core/container/array.onyx
include/bh.h
lib/linux_x86_64/lib/libovmwasm.so [new file with mode: 0755]
src/onyx.c
src/wasm_runtime.c

index 68bae2ff80a5bf024b2ea06f572bd98c9b803a46..b65fd1895603caa4922ab57f2e5ac39277b7a929 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -16,11 +16,12 @@ CC='gcc'
 # The architecture of your system. If your not sure, leave this alone.
 ARCH="$(uname -m)"
 
-RUNTIME_LIBRARY="wasmer"
+RUNTIME_LIBRARY="ovmwasm"
+# RUNTIME_LIBRARY="wasmer"
 
-# Comment this line if you do not want the Wamser libraries installed,
+# Comment this line if you do not want the above library installed,
 # and do not with to have the Onyx runtime.
-ENABLE_BUNDLING_WASMER=1
+ENABLE_BUNDLING_WASM_RUNTIME=1
 
 # Where the Wasmer library files can be found.
 # They are bundled with the project, but if a different version is available, these can be changed.
@@ -44,20 +45,23 @@ sudo cp -r ./core/ "$CORE_DIR"
 
 C_FILES="onyx astnodes builtins checker clone doc entities errors lex parser symres types utils wasm_emit"
 LIBS=
-INCLUDES=
+INCLUDES="-I./include"
 
 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'
 
+TARGET="./bin/onyx"
 if [ "$1" = "debug" ]; then
-    FLAGS="$WARNINGS -g3 -I./include"
-    TARGET="./bin/onyx-debug"
+    FLAGS="$WARNINGS -g3"
 else
-    FLAGS="$WARNINGS -O3 -I./include"
-    TARGET='./bin/onyx'
+    FLAGS="$WARNINGS -O3"
+fi
+
+if [ "$RUNTIME_LIBRARY" = "ovmwasm" ]; then
+    FLAGS="$FLAGS -DUSE_OVM_DEBUGGER"
 fi
 
 
-if [ ! -z "$ENABLE_BUNDLING_WASMER" ]; then
+if [ ! -z "$ENABLE_BUNDLING_WASM_RUNTIME" ]; then
     C_FILES="$C_FILES wasm_runtime"
     FLAGS="$FLAGS -DENABLE_RUN_WITH_WASMER"
     LIBS="$LIBS -L$CORE_DIR/lib -l$RUNTIME_LIBRARY -Wl,-rpath=$CORE_DIR/lib:./ -lpthread -ldl -lm"
@@ -69,8 +73,6 @@ if [ ! -z "$ENABLE_BUNDLING_WASMER" ]; then
         sudo mkdir -p "$CORE_DIR/lib"
         sudo mkdir -p "$CORE_DIR/include"
 
-        # sudo cp "$WASMER_LIBRARY_DIR/libiwasm.so" "$CORE_DIR/lib/libiwasm.so"
-        # sudo cp "$WASMER_LIBRARY_DIR/libwasmer.so" "$CORE_DIR/lib/libwasmer.so"
         sudo cp "$WASMER_LIBRARY_DIR/lib$RUNTIME_LIBRARY.so" "$CORE_DIR/lib/lib$RUNTIME_LIBRARY.so"
 
         sudo cp "include/onyx_library.h" "$CORE_DIR/include/onyx_library.h"
@@ -102,7 +104,7 @@ echo "Installing onyx executable"
 sudo mkdir -p "$BIN_DIR"
 sudo cp ./bin/onyx "$BIN_DIR/onyx"
 
-if [ ! -z "$ENABLE_BUNDLING_WASMER" ]; then
+if [ ! -z "$ENABLE_BUNDLING_WASM_RUNTIME" ]; then
     C_FILES="onyxrun wasm_runtime"
     TARGET="./bin/onyx-run"
 
index 16e8f984232444fa6c1ada0f5ab7af5e7f87a587..e400b9d8973e48ea37fdc31ee265f25fce8be39f 100644 (file)
@@ -213,10 +213,12 @@ filter :: macro (arr: ^[..] $T, body: Code) {
 }
 
 greatest :: macro (arr: [] $T) -> (i32, T) {
+    fold_idx_elem :: fold_idx_elem
     return fold_idx_elem(arr, #(*A > *B));
 }
 
 least :: macro (arr: [] $T) -> (i32, T) {
+    fold_idx_elem :: fold_idx_elem
     return fold_idx_elem(arr, #(*A < *B));
 }
 
index c2f78011ddb15841a1371efd9b75404f9b03eeea..2d941eba9fcf86d27fc260bbe0fb30bb8716f09a 100644 (file)
@@ -180,7 +180,7 @@ u64 uleb128_to_uint(u8* bytes, i32 *byte_walker);
 
 #define bh_align(x, a) if ((x) % (a) != 0) (x) += (a) - ((x) % (a));
 
-#define bh_pointer_add(ptr, amm)        ((void *)((u8 *) ptr + amm))
+#define bh_pointer_add(ptr, amm)        ((void *)((u8 *) (ptr) + (amm)))
 #define BH_BIT(x)                        (1 << (x))
 #define BH_MASK_SET(var, set, mask)     ((set) ? ((var) |= (mask)) : ((var) &= ~(mask)))
 
diff --git a/lib/linux_x86_64/lib/libovmwasm.so b/lib/linux_x86_64/lib/libovmwasm.so
new file mode 100755 (executable)
index 0000000..704e28d
Binary files /dev/null and b/lib/linux_x86_64/lib/libovmwasm.so differ
index 6432a985d62c7f2beba6e613714bb44fd841ac39..8488921866883d1c361502f94628c621e7c79046 100644 (file)
@@ -682,10 +682,13 @@ static CompilerProgress onyx_flush_module() {
         onyx_wasm_module_write_to_file(data_module, data_file);
         onyx_wasm_module_write_to_file(context.wasm_module, output_file);
 
+        bh_file_close(&data_file);
     } else {
         onyx_wasm_module_write_to_file(context.wasm_module, output_file);
     }
 
+    bh_file_close(&output_file);
+
     if (context.options->documentation_file != NULL) {
         OnyxDocumentation docs = onyx_docs_generate();
         docs.format = Doc_Format_Human;
index 88ca522ba3a6eb34cf1e75669f8ec461832782b7..b3551ea81e95605818390d85496d407dd72e2bad 100644 (file)
@@ -2,9 +2,12 @@
 #include "utils.h"
 #include "astnodes.h"
 #include "wasm.h"
-#include "wasmer.h"
 #include "onyx_library.h"
 
+#ifndef USE_OVM_DEBUGGER
+    #include "wasmer.h"
+#endif
+
 #ifdef _BH_LINUX
     #include <pthread.h>
     #include <signal.h>
@@ -228,22 +231,23 @@ b32 onyx_run_wasm(bh_buffer wasm_bytes, int argc, char *argv[]) {
     bh_arr_new(bh_heap_allocator(), linkable_functions, 4);
     onyx_lookup_and_load_custom_libraries(wasm_bytes);
 
-    wasmer_features_t* features = NULL;
     wasm_trap_t* run_trap = NULL;
 
     wasm_config = wasm_config_new();
     if (!wasm_config) goto error_handling;
 
+#ifndef USE_OVM_DEBUGGER
     // Prefer the LLVM compile because it is faster. This should be configurable from the command line and/or a top-level directive.
     if (wasmer_is_compiler_available(LLVM)) {
         wasm_config_set_compiler(wasm_config, LLVM);
     }
 
-    features = wasmer_features_new();
+    wasmer_features_t* features = wasmer_features_new();
     wasmer_features_simd(features, 1);
     wasmer_features_threads(features, 1);
     wasmer_features_bulk_memory(features, 1);
     wasm_config_set_features(wasm_config, features);
+#endif
 
     wasm_engine = wasm_engine_new_with_config(wasm_config);
     if (!wasm_engine) goto error_handling;
@@ -262,8 +266,6 @@ b32 onyx_run_wasm(bh_buffer wasm_bytes, int argc, char *argv[]) {
     wasm_module_imports(wasm_module, &module_imports);
 
     wasm_imports = (wasm_extern_vec_t) WASM_EMPTY_VEC;
-    // wasm_imports.data = malloc(module_imports.size * 64);
-    // wasm_imports.size = module_imports.size;
     wasm_extern_vec_new_uninitialized(&wasm_imports, module_imports.size); // @Free
 
     fori (i, 0, (i32) module_imports.size) {
@@ -351,6 +353,7 @@ b32 onyx_run_wasm(bh_buffer wasm_bytes, int argc, char *argv[]) {
     wasm_val_vec_t args;
     wasm_val_vec_t results;
     wasm_val_vec_new_uninitialized(&args, 0);
+    wasm_val_vec_new_uninitialized(&results, 1);
 
     run_trap = wasm_func_call(start_func, &args, &results);
 
@@ -362,10 +365,13 @@ b32 onyx_run_wasm(bh_buffer wasm_bytes, int argc, char *argv[]) {
 
 error_handling:
     bh_printf("An error occured trying to run the WASM module...\n");
+
+#ifndef USE_OVM_DEBUGGER
     i32 len = wasmer_last_error_length();
     char *buf = alloca(len + 1);
     wasmer_last_error_message(buf, len);
     bh_printf("%b\n", buf, len);
+#endif
 
 cleanup:
     if (wasm_instance) wasm_instance_delete(wasm_instance);