From: Brendan Hansen Date: Sun, 17 Jul 2022 04:13:33 +0000 (-0500) Subject: added alternate backend, ovmwasm X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=25cef786641f437014ddf4c6edfbb60ba2c3b9fe;p=onyx.git added alternate backend, ovmwasm --- diff --git a/build.sh b/build.sh index 68bae2ff..b65fd189 100755 --- 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" diff --git a/core/container/array.onyx b/core/container/array.onyx index 16e8f984..e400b9d8 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -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)); } diff --git a/include/bh.h b/include/bh.h index c2f78011..2d941eba 100644 --- a/include/bh.h +++ b/include/bh.h @@ -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 index 00000000..704e28d0 Binary files /dev/null and b/lib/linux_x86_64/lib/libovmwasm.so differ diff --git a/src/onyx.c b/src/onyx.c index 6432a985..84889218 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -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; diff --git a/src/wasm_runtime.c b/src/wasm_runtime.c index 88ca522b..b3551ea8 100644 --- a/src/wasm_runtime.c +++ b/src/wasm_runtime.c @@ -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 #include @@ -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);