diff options
author | Zoltan Varga <vargaz@gmail.com> | 2018-10-09 18:32:20 +0300 |
---|---|---|
committer | Ludovic Henry <luhenry@microsoft.com> | 2018-10-09 18:32:20 +0300 |
commit | 65e207ba7c809ef1d477e883e9ab41a76a68ef9d (patch) | |
tree | d177e2a6c71c629d2576ae1263879a72b1131320 | |
parent | a618a1a9ea7964a6c6aaf1922962770d2061d534 (diff) |
[wasm] AOT work. (#10989)
* [llvm] Fix the icall signature of a few llvm EH icalls.
* [wasm] Disable com/remoting in the linker.
* [wasm] Enable direct icalls.
* [wasm] Generate the configuration into a config.js file instead of rewriting the runtime.js file.
* [wasm] Enable icall symbol map in the cross compiler, compile the device runtime with -fexceptions.
* [wasm] Rename runtime-tests.g.js -> runtime-tests.js.
* [wasm] Add mono_wasm_assembly_get_entry_point () function to obtain the entry point of an assembly.
* [wasm] Add profiler support to the packager.
* [wasm] Add support for running a normal .net executable to the test runner.
-rw-r--r-- | mono/mini/mini-runtime.c | 4 | ||||
-rw-r--r-- | sdks/builds/wasm.mk | 5 | ||||
-rw-r--r-- | sdks/wasm/Makefile | 12 | ||||
-rw-r--r-- | sdks/wasm/driver.c | 30 | ||||
-rw-r--r-- | sdks/wasm/packager.cs | 62 | ||||
-rw-r--r-- | sdks/wasm/runtime-tests.js (renamed from sdks/wasm/runtime-tests.g.js) | 69 | ||||
-rw-r--r-- | sdks/wasm/runtime.js (renamed from sdks/wasm/runtime.g.js) | 0 |
7 files changed, 134 insertions, 48 deletions
diff --git a/mono/mini/mini-runtime.c b/mono/mini/mini-runtime.c index a863f426e84..15e43cd0349 100644 --- a/mono/mini/mini-runtime.c +++ b/mono/mini/mini-runtime.c @@ -4567,7 +4567,7 @@ register_icalls (void) register_icall (mono_llvm_throw_exception, "mono_llvm_throw_exception", "void object", TRUE); register_icall (mono_llvm_rethrow_exception, "mono_llvm_rethrow_exception", "void object", TRUE); register_icall (mono_llvm_resume_exception, "mono_llvm_resume_exception", "void", TRUE); - register_icall (mono_llvm_match_exception, "mono_llvm_match_exception", "int ptr int int", TRUE); + register_icall (mono_llvm_match_exception, "mono_llvm_match_exception", "int ptr int int ptr object", TRUE); register_icall (mono_llvm_clear_exception, "mono_llvm_clear_exception", NULL, TRUE); register_icall (mono_llvm_load_exception, "mono_llvm_load_exception", "object", TRUE); register_icall (mono_llvm_throw_corlib_exception, "mono_llvm_throw_corlib_exception", "void int", TRUE); @@ -4746,7 +4746,7 @@ register_icalls (void) register_icall (mono_array_new_3, "mono_array_new_3", "object ptr int int int", FALSE); register_icall (mono_array_new_4, "mono_array_new_4", "object ptr int int int int", FALSE); register_icall (mono_get_native_calli_wrapper, "mono_get_native_calli_wrapper", "ptr ptr ptr ptr", FALSE); - register_icall (mono_resume_unwind, "mono_resume_unwind", "void", TRUE); + register_icall (mono_resume_unwind, "mono_resume_unwind", "void ptr", TRUE); register_icall (mono_gsharedvt_constrained_call, "mono_gsharedvt_constrained_call", "object ptr ptr ptr ptr ptr", FALSE); register_icall (mono_gsharedvt_value_copy, "mono_gsharedvt_value_copy", "void ptr ptr ptr", TRUE); diff --git a/sdks/builds/wasm.mk b/sdks/builds/wasm.mk index ad772b80881..f6eeaea77f8 100644 --- a/sdks/builds/wasm.mk +++ b/sdks/builds/wasm.mk @@ -36,6 +36,7 @@ WASM_RUNTIME_CONFIGURE_FLAGS = \ --disable-icall-tables \ --with-bitcode=yes \ $(if $(ENABLE_CXX),--enable-cxx) + CFLAGS="-fexceptions" .stamp-wasm-runtime-toolchain: touch $@ @@ -147,7 +148,9 @@ _wasm-$(1)_CONFIGURE_FLAGS= \ --disable-support-build \ --enable-maintainer-mode \ --enable-minimal=appdomains,com,remoting \ - --with-tls=pthread + --with-tls=pthread \ + --enable-icall-symbol-map \ + --with-cross-offsets=wasm-offsets.h .stamp-wasm-$(1)-$$(CONFIGURATION)-configure: | $$(if $$(IGNORE_PROVISION_MXE),,provision-mxe) diff --git a/sdks/wasm/Makefile b/sdks/wasm/Makefile index c492bf672c5..08220418830 100644 --- a/sdks/wasm/Makefile +++ b/sdks/wasm/Makefile @@ -130,20 +130,20 @@ Mono.Cecil.dll: Makefile packager.exe: packager.cs Mono.Cecil.dll $(OPTIONS_CS) csc /debug:portable /out:$@ /r:Mono.Cecil.dll packager.cs $(OPTIONS_CS) -.stamp-build-debug-sample: $(DRIVER_CONF)/.stamp-build packager.exe WebAssembly.Bindings.dll WebAssembly.Net.Http.dll sample.dll debug.html runtime.g.js +.stamp-build-debug-sample: $(DRIVER_CONF)/.stamp-build packager.exe WebAssembly.Bindings.dll WebAssembly.Net.Http.dll sample.dll debug.html runtime.js mono packager.exe -debug -out=debug_sample sample.dll cp debug.html debug_sample touch $@ TEST_ASSEMBLIES = $(WASM_BCL_DIR)/nunitlite.dll $(WASM_BCL_DIR)/tests/wasm_corlib_test.dll $(WASM_BCL_DIR)/tests/wasm_System_test.dll $(WASM_BCL_DIR)/tests/wasm_System.Core_test.dll -.stamp-build-test-suite: $(DRIVER_CONF)/.stamp-build packager.exe WebAssembly.Bindings.dll binding_tests.dll WebAssembly.Net.Http.dll mini_tests.dll main.exe runtime-tests.g.js - mono --debug packager.exe --template=runtime-tests.g.js --appdir=bin/test-suite --builddir=obj/test-suite binding_tests.dll WebAssembly.Net.Http.dll mini_tests.dll main.exe $(TEST_ASSEMBLIES) +.stamp-build-test-suite: $(DRIVER_CONF)/.stamp-build packager.exe WebAssembly.Bindings.dll binding_tests.dll WebAssembly.Net.Http.dll mini_tests.dll main.exe runtime-tests.js + mono --debug packager.exe --template=runtime-tests.js --appdir=bin/test-suite --builddir=obj/test-suite binding_tests.dll WebAssembly.Net.Http.dll mini_tests.dll main.exe $(TEST_ASSEMBLIES) ninja -v -C obj/test-suite touch $@ -aot-sample: $(DRIVER_CONF)/.stamp-build packager.exe mini_tests.dll main.exe runtime.g.js - mono packager.exe --emscripten-sdkdir=$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$(PWD)/../out -appdir=bin/aot-sample --nobinding --builddir=obj/aot-sample --aot --template=runtime-tests.g.js mini_tests.dll +aot-sample: $(DRIVER_CONF)/.stamp-build packager.exe mini_tests.dll main.exe runtime.js + mono packager.exe --emscripten-sdkdir=$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$(PWD)/../out -appdir=bin/aot-sample --nobinding --builddir=obj/aot-sample --aot --template=runtime-tests.js mini_tests.dll ninja -v -C obj/aot-sample do-aot-sample: aot-sample @@ -221,7 +221,7 @@ package: build build-dbg-proxy build-framework-nuget cp server.py tmp/ cp Mono.Cecil.dll tmp/ cp packager.exe tmp/ - cp runtime.g.js tmp/ + cp runtime.js tmp/ cp Mono.WebAssembly.DebuggerProxy/bin/Debug/netstandard2.0/Mono.WebAssembly.DebuggerProxy.dll tmp/ cp Mono.WebAssembly.DebuggerProxy/bin/Debug/netstandard2.0/Mono.WebAssembly.DebuggerProxy.pdb tmp/ mkdir tmp/dbg-proxy diff --git a/sdks/wasm/driver.c b/sdks/wasm/driver.c index a56689ac6d6..3b957380daf 100644 --- a/sdks/wasm/driver.c +++ b/sdks/wasm/driver.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> - +#include <stdint.h> typedef enum { /* Disables AOT mode */ @@ -126,7 +126,12 @@ MonoAssembly* mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoAssemblyName* mono_assembly_name_new (const char *name); void mono_assembly_name_free (MonoAssemblyName *aname); + const char* mono_image_get_name (MonoImage *image); +uint32_t mono_image_get_entry_point (MonoImage *image); + +MonoMethod* mono_get_method (MonoImage *image, uint32_t token, MonoClass *klass); + MonoString* mono_string_new (MonoDomain *domain, const char *text); void mono_add_internal_call (const char *name, const void* method); MonoString * mono_string_from_utf16 (char *data); @@ -134,6 +139,7 @@ MonoString* mono_string_new (MonoDomain *domain, const char *text); void mono_wasm_enable_debugging (void); MonoArray* mono_array_new (MonoDomain *domain, MonoClass *eclass, int n); MonoClass* mono_get_object_class (void); +MonoClass* mono_get_string_class (void); int mono_class_is_delegate (MonoClass* klass); const char* mono_class_get_name (MonoClass *klass); const char* mono_class_get_namespace (MonoClass *klass); @@ -280,7 +286,6 @@ mono_wasm_load_runtime (const char *managed_path, int enable_debugging) mono_method_builder_ilgen_init (); mono_sgen_mono_ilgen_init (); #endif - mono_icall_table_init (); if (assembly_count) { MonoBundledAssembly **bundle_array = (MonoBundledAssembly **)calloc (1, sizeof (MonoBundledAssembly*) * (assembly_count + 1)); @@ -356,6 +361,20 @@ mono_wasm_invoke_method (MonoMethod *method, MonoObject *this_arg, void *params[ return res; } +EMSCRIPTEN_KEEPALIVE MonoMethod* +mono_wasm_assembly_get_entry_point (MonoAssembly *assembly) +{ + MonoImage *image; + MonoMethod *method; + + image = mono_assembly_get_image (assembly); + uint32_t entry = mono_image_get_entry_point (image); + if (!entry) + return NULL; + + return mono_get_method (image, entry, NULL); +} + EMSCRIPTEN_KEEPALIVE char * mono_wasm_string_get_utf8 (MonoString *str) { @@ -368,7 +387,6 @@ mono_wasm_string_from_js (const char *str) return mono_string_new (root_domain, str); } - static int class_is_task (MonoClass *klass) { @@ -539,6 +557,12 @@ mono_wasm_obj_array_set (MonoArray *array, int idx, MonoObject *obj) mono_array_setref (array, idx, obj); } +EMSCRIPTEN_KEEPALIVE MonoArray* +mono_wasm_string_array_new (int size) +{ + return mono_array_new (root_domain, mono_get_string_class (), size); +} + // Int8Array | int8_t | byte or SByte (signed byte) // Uint8Array | uint8_t | byte or Byte (unsigned byte) // Uint8ClampedArray| uint8_t | byte or Byte (unsigned byte) diff --git a/sdks/wasm/packager.cs b/sdks/wasm/packager.cs index 69d8208f589..11bdf888d5e 100644 --- a/sdks/wasm/packager.cs +++ b/sdks/wasm/packager.cs @@ -35,8 +35,9 @@ class Driver { Console.WriteLine ("\t--mono-sdkdir=x Set the mono sdk directory to 'x'"); Console.WriteLine ("\t--deploy=x Set the deploy prefix to 'x' (default to 'managed')"); Console.WriteLine ("\t--vfs=x Set the VFS prefix to 'x' (default to 'managed')"); - Console.WriteLine ("\t--template=x Set the template name to 'x' (default to 'runtime.g.js')"); + Console.WriteLine ("\t--template=x Set the template name to 'x' (default to 'runtime.js')"); Console.WriteLine ("\t--asset=x Add specified asset 'x' to list of assets to be copied"); + Console.WriteLine ("\t--profile=x Enable the 'x' mono profiler."); Console.WriteLine ("foo.dll Include foo.dll as one of the root assemblies"); } @@ -135,13 +136,13 @@ class Driver { } } - void GenDriver (string builddir, List<string> assembly_names) { + void GenDriver (string builddir, List<string> assembly_names, List<string> profilers) { var symbols = new List<string> (); foreach (var img in assembly_names) { symbols.Add (String.Format ("mono_aot_module_{0}_info", img.Replace ('.', '_').Replace ('-', '_'))); } - var w = File.CreateText (Path.Combine (builddir, "driver-gen.c")); + var w = File.CreateText (Path.Combine (builddir, "driver-gen.c.in")); foreach (var symbol in symbols) { w.WriteLine ($"extern void *{symbol};"); @@ -153,6 +154,11 @@ class Driver { w.WriteLine ($"\tmono_aot_register_module ({symbol});"); w.WriteLine ("}"); + foreach (var profiler in profilers) { + w.WriteLine ($"void mono_profiler_init_{profiler} (const char *desc);"); + w.WriteLine ("EMSCRIPTEN_KEEPALIVE void mono_wasm_load_profiler_" + profiler + " (const char *desc) { mono_profiler_init_" + profiler + " (desc); }"); + } + w.Close (); } @@ -175,8 +181,9 @@ class Driver { var enable_aot = false; var print_usage = false; var emit_ninja = false; - var runtimeTemplate = "runtime.g.js"; + var runtimeTemplate = "runtime.js"; var assets = new List<string> (); + var profilers = new List<string> (); var p = new OptionSet () { { "debug", s => enable_debug = true }, @@ -193,6 +200,7 @@ class Driver { { "aot", s => enable_aot = true }, { "template=", s => runtimeTemplate = s }, { "asset=", s => assets.Add(s) }, + { "profile=", s => profilers.Add (s) }, { "help", s => print_usage = true }, }; @@ -261,22 +269,18 @@ class Driver { var dontlink_assemblies = new Dictionary<string, bool> (); dontlink_assemblies [BINDINGS_ASM_NAME] = true; - var template = File.ReadAllText (Path.Combine (tool_prefix, runtimeTemplate)); - - var file_list_str = string.Join (",", file_list.Select (f => $"\"{Path.GetFileName (f)}\"")); - template = template.Replace ("@FILE_LIST@", file_list_str); - template = template.Replace ("@VFS_PREFIX@", vfs_prefix); - template = template.Replace ("@DEPLOY_PREFIX@", deploy_prefix); - template = template.Replace ("@ENABLE_DEBUGGING@", enable_debug ? "1" : "0"); - if (add_binding) - template = template.Replace ("@BINDINGS_LOADING@", $"Module.mono_bindings_init (\"[{BINDINGS_ASM_NAME}]{BINDINGS_RUNTIME_CLASS_NAME}\");"); - else - template = template.Replace ("@BINDINGS_LOADING@", ""); - var runtime_js = Path.Combine (emit_ninja ? builddir : out_prefix, "runtime.js"); - Debug ($"create {runtime_js}"); File.Delete (runtime_js); - File.WriteAllText (runtime_js, template); + File.Copy (runtimeTemplate, runtime_js); + + var file_list_str = string.Join (",", file_list.Select (f => $"\"{Path.GetFileName (f)}\"")); + var config = String.Format ("config = {{\n \tvfs_prefix: \"{0}\",\n \tdeploy_prefix: \"{1}\",\n \tenable_debugging: {2},\n \tfile_list: [ {3} ],\n", vfs_prefix, deploy_prefix, enable_debug ? "1" : "0", file_list_str); + if (add_binding || true) + config += "\tadd_bindings: function() { " + $"Module.mono_bindings_init (\"[{BINDINGS_ASM_NAME}]{BINDINGS_RUNTIME_CLASS_NAME}\");" + " }\n"; + config += "}\n"; + var config_js = Path.Combine (emit_ninja ? builddir : out_prefix, "config.js"); + File.Delete (config_js); + File.WriteAllText (config_js, config); string runtime_dir = Path.Combine (tool_prefix, use_release_runtime ? "release" : "debug"); if (!emit_ninja) { @@ -310,9 +314,17 @@ class Driver { Console.WriteLine ("The --emscripten-sdkdir argument is required when using AOT."); Environment.Exit (1); } - GenDriver (builddir, assembly_names); + GenDriver (builddir, assembly_names, profilers); } + string profiler_libs = ""; + string profiler_aot_args = ""; + foreach (var profiler in profilers) { + profiler_libs += $"$mono_sdkdir/wasm-runtime/lib/libmono-profiler-{profiler}-static.a "; + if (profiler_aot_args != "") + profiler_aot_args += " "; + profiler_aot_args += $"--profile={profiler}"; + } runtime_dir = Path.GetFullPath (runtime_dir); sdkdir = Path.GetFullPath (sdkdir); @@ -332,11 +344,11 @@ class Driver { ninja.WriteLine ("cross = $mono_sdkdir/wasm-cross/bin/wasm32-mono-sgen"); ninja.WriteLine ("emcc = source $emscripten_sdkdir/emsdk_env.sh && emcc"); // -s ASSERTIONS=2 is very slow - ninja.WriteLine ("emcc_flags = -Os -g -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=1 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s \"BINARYEN_TRAP_MODE=\'clamp\'\" -s TOTAL_MEMORY=134217728 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s \"EXTRA_EXPORTED_RUNTIME_METHODS=[\'ccall\', \'FS_createPath\', \'FS_createDataFile\', \'cwrap\', \'setValue\', \'getValue\', \'UTF8ToString\']\""); + ninja.WriteLine ("emcc_flags = -Os -g -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=1 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s \"BINARYEN_TRAP_MODE=\'clamp\'\" -s TOTAL_MEMORY=134217728 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s \"EXTRA_EXPORTED_RUNTIME_METHODS=[\'ccall\', \'FS_createPath\', \'FS_createDataFile\', \'cwrap\', \'setValue\', \'getValue\', \'UTF8ToString\']\""); // Rules ninja.WriteLine ("rule aot"); - ninja.WriteLine ($" command = MONO_PATH=$mono_path $cross --debug --aot=llvmonly,asmonly,no-opt,static,llvm-outfile=$outfile $src_file"); + ninja.WriteLine ($" command = MONO_PATH=$mono_path $cross --debug {profiler_aot_args} --aot=llvmonly,asmonly,no-opt,static,direct-icalls,llvm-outfile=$outfile $src_file"); ninja.WriteLine (" description = [AOT] $src_file -> $outfile"); ninja.WriteLine ("rule mkdir"); ninja.WriteLine (" command = mkdir -p $out"); @@ -351,18 +363,20 @@ class Driver { ninja.WriteLine (" description = [EMCC-LINK] $in -> $out"); ninja.WriteLine ("rule linker"); - ninja.WriteLine (" command = mono $bcl_dir/monolinker.exe -out $builddir/linker-out -l none $linker_args; for f in $out; do if test ! -f $$f; then echo > empty.cs; csc /out:$$f /target:library empty.cs; fi; done"); + ninja.WriteLine (" command = mono $bcl_dir/monolinker.exe -out $builddir/linker-out -l none --exclude-feature com --exclude-feature remoting $linker_args; for f in $out; do if test ! -f $$f; then echo > empty.cs; csc /out:$$f /target:library empty.cs; fi; done"); ninja.WriteLine (" description = [IL-LINK]"); // Targets ninja.WriteLine ("build $appdir: mkdir"); ninja.WriteLine ("build $appdir/$deploy_prefix: mkdir"); ninja.WriteLine ("build $appdir/runtime.js: cpifdiff $builddir/runtime.js"); + ninja.WriteLine ("build $appdir/config.js: cpifdiff $builddir/config.js"); if (enable_aot) { var source_file = Path.GetFullPath (Path.Combine (tool_prefix, "driver.c")); ninja.WriteLine ($"build $builddir/driver.c: cpifdiff {source_file}"); + ninja.WriteLine ($"build $builddir/driver-gen.c: cpifdiff $builddir/driver-gen.c.in"); - ninja.WriteLine ("build $builddir/driver.o: emcc $builddir/driver.c"); + ninja.WriteLine ("build $builddir/driver.o: emcc $builddir/driver.c | $builddir/driver-gen.c"); ninja.WriteLine (" flags = -DENABLE_AOT=1"); } else { @@ -411,7 +425,7 @@ class Driver { } } if (enable_aot) { - ninja.WriteLine ($"build $appdir/mono.js: emcc-link $builddir/driver.o $mono_sdkdir/wasm-runtime/lib/libmonosgen-2.0.a $mono_sdkdir/wasm-runtime/lib/libmono-icall-table.a {ofiles} | $tool_prefix/library_mono.js $tool_prefix/binding_support.js $tool_prefix/dotnet_support.js"); + ninja.WriteLine ($"build $appdir/mono.js: emcc-link $builddir/driver.o {ofiles} {profiler_libs} $mono_sdkdir/wasm-runtime/lib/libmonosgen-2.0.a | $tool_prefix/library_mono.js $tool_prefix/binding_support.js $tool_prefix/dotnet_support.js"); } if (enable_linker) { string linker_args = ""; diff --git a/sdks/wasm/runtime-tests.g.js b/sdks/wasm/runtime-tests.js index 36722a2a3b8..04c643808ff 100644 --- a/sdks/wasm/runtime-tests.g.js +++ b/sdks/wasm/runtime-tests.js @@ -55,6 +55,7 @@ function inspect_object (o){ return r; } +load ("config.js"); var Module = { print: function(x) { print ("WASM: " + x) }, @@ -62,12 +63,12 @@ var Module = { onRuntimeInitialized: function () { MONO.mono_load_runtime_and_bcl ( - "@VFS_PREFIX@", - "@DEPLOY_PREFIX@", - @ENABLE_DEBUGGING@, - [ @FILE_LIST@ ], + config.vfs_prefix, + config.deploy_prefix, + config.enable_debugging, + config.file_list, function () { - @BINDINGS_LOADING@ + config.add_bindings (); App.init (); }, function (asset ) @@ -97,8 +98,14 @@ load ("mono.js"); var assembly_load = Module.cwrap ('mono_wasm_assembly_load', 'number', ['string']) var find_class = Module.cwrap ('mono_wasm_assembly_find_class', 'number', ['number', 'string', 'string']) var find_method = Module.cwrap ('mono_wasm_assembly_find_method', 'number', ['number', 'string', 'number']) -const IGNORE_PARAM_COUNT = -1; +var runtime_invoke = Module.cwrap ('mono_wasm_invoke_method', 'number', ['number', 'number', 'number', 'number']); +var string_from_js = Module.cwrap ('mono_wasm_string_from_js', 'number', ['string']); +var assembly_get_entry_point = Module.cwrap ('mono_wasm_assembly_get_entry_point', 'number', ['number']); +var string_get_utf8 = Module.cwrap ('mono_wasm_string_get_utf8', 'string', ['number']); +var string_array_new = Module.cwrap ('mono_wasm_string_array_new', 'number', ['number']); +var obj_array_set = Module.cwrap ('mono_wasm_obj_array_set', 'void', ['number', 'number', 'number']); +const IGNORE_PARAM_COUNT = -1; var App = { init: function () { @@ -106,26 +113,64 @@ var App = { Module.print("Initializing....."); Module.print("Arguments: " + testArguments); - if (testArguments[0] == "--regression") { + var args = testArguments; + + if (args [0].startsWith ("--profile=")) { + var arg = args [0].substring ("--profile=".length); + + var init = Module.cwrap ('mono_wasm_load_profiler_' + arg, 'void', ['string']) + + init (""); + + args = args.slice (1); + } + + if (args[0] == "--regression") { var exec_regresion = Module.cwrap ('mono_wasm_exec_regression', 'number', ['number', 'string']) var res = 0; - while(true) { try { - res = exec_regresion (10, testArguments[1]); + res = exec_regresion (10, args[1]); Module.print ("REGRESSION RESULT: " + res); - break; } catch (e) { Module.print ("ABORT: " + e); res = 1; } - } + if (res) fail_exec ("REGRESSION TEST FAILED"); return; } - + + if (args[0] == "--run") { + // Run an exe + if (args.length == 1) + fail_exec ("Error: Missing main executable argument."); + main_assembly = assembly_load (args[1]); + if (main_assembly == 0) + fail_exec ("Error: Unable to load main executable '" + args[1] + "'"); + main_method = assembly_get_entry_point (main_assembly); + if (main_method == 0) + fail_exec ("Error: Main (string[]) method not found."); + + var app_args = string_array_new (args.length - 2); + for (var i = 2; i < args.length; ++i) { + obj_array_set (app_args, i - 2, string_from_js (args [i])); + } + + var invoke_args = Module._malloc (4); + Module.setValue (invoke_args, app_args, "i32"); + var eh_throw = Module._malloc (4); + Module.setValue (eh_throw, 0, "i32"); + var res = runtime_invoke (main_method, 0, invoke_args, eh_throw); + var eh_res = Module.getValue (eh_throw, "i32"); + if (eh_res == 1) { + print ("Exception:" + string_get_utf8 (res)); + } + return; + } + Module.print("Initializing Binding Test Suite support....."); //binding test suite support code diff --git a/sdks/wasm/runtime.g.js b/sdks/wasm/runtime.js index 26689776806..26689776806 100644 --- a/sdks/wasm/runtime.g.js +++ b/sdks/wasm/runtime.js |