[interpreter] add configure flag and `--regression` flag
authorBernhard Urban <bernhard.urban@xamarin.com>
Mon, 9 Jan 2017 22:32:40 +0000 (23:32 +0100)
committerBernhard Urban <bernhard.urban@xamarin.com>
Mon, 9 Jan 2017 22:32:40 +0000 (23:32 +0100)
configure.ac
mono/mini/Makefile.am.in
mono/mini/driver.c
mono/mini/interpreter/interp.c
mono/mini/interpreter/interp.h
mono/mini/mini-runtime.c
mono/mini/mini.h

index b26682edb98aa097bc843e8ebecdc92604098e78..f1225676f35a807baa43c2c5160e042b7f316da5 100644 (file)
@@ -3528,6 +3528,15 @@ if test "x$have_deprecated" = "xyes"; then
    AC_DEFINE(HAVE_DEPRECATED, 1, [Support for the deprecated attribute])
 fi
 
+AC_ARG_WITH(interpreter, [  --with-interpreter=yes|no       Interpreter, default=no],[buildinterpreter=$with_interpreter],[buildinterpreter=no])
+if test "x$buildinterpreter" = "xyes"; then
+    AC_DEFINE(ENABLE_INTERPRETER, 1, [Enable interpreter in the runtime.])
+    AC_MSG_NOTICE([Enable interpreter in the runtime.])
+fi
+
+AM_CONDITIONAL([ENABLE_INTERPRETER], [test x$buildinterpreter != xno])
+
+
 dnl 
 dnl Simple Generational checks (sgen)
 dnl
@@ -4508,6 +4517,7 @@ echo "
        BigArrays:     $enable_big_arrays
        DTrace:        $enable_dtrace
        LLVM Back End: $enable_llvm (dynamically loaded: $enable_loadedllvm)
+       Interpreter:   $buildinterpreter
 
    Libraries:
        .NET 4.x:        $with_profile4_x
index 1ad86684ebd31c65ba8d638dcf7f9835e87146e4..34943ef9e6e175329ed08dd89951b61e11fd6932 100755 (executable)
@@ -47,6 +47,7 @@ RUNTIME_EXECUTABLE = $(if $(BOEHM),$(top_builddir)/mono/mini/mono-boehm,$(top_bu
 
 MINI_RUNTIME = MONO_PATH=$(CLASS) $(RUNTIME_EXECUTABLE)
 TOOLS_RUNTIME = MONO_PATH=$(mcs_topdir)/class/lib/build $(top_builddir)/runtime/mono-wrapper
+INTERPRETER_RUNTIME = $(MINI_RUNTIME) --interpreter
 RUNTIME_AOTCHECK = MONO_PATH="$(CLASS)$(PLATFORM_PATH_SEPARATOR)." $(RUNTIME_EXECUTABLE)
 
 MCS = CSC_SDK_PATH_DISABLED= $(TOOLS_RUNTIME) $(CSC) -unsafe -nowarn:0162 -nologo -noconfig -r:$(CLASS)/mscorlib.dll -r:$(CLASS)/System.dll -r:$(CLASS)/System.Core.dll
@@ -390,6 +391,17 @@ llvm_sources = \
 endif
 endif
 
+if ENABLE_INTERPRETER
+interpreter_sources =  \
+       interpreter/hacks.h             \
+       interpreter/interp.h    \
+       interpreter/interp.c    \
+       interpreter/mintops.h   \
+       interpreter/mintops.def \
+       interpreter/mintops.c   \
+       interpreter/transform.c
+endif
+
 if ENABLE_LLVM
 llvm_runtime_sources = \
        llvm-runtime.cpp
@@ -590,7 +602,7 @@ os_sources = $(darwin_sources) $(posix_sources)
 monobin_platform_ldflags=-framework CoreFoundation -framework Foundation
 endif
 
-libmini_la_SOURCES = $(common_sources) $(llvm_sources) $(llvm_runtime_sources) $(arch_sources) $(os_sources)
+libmini_la_SOURCES = $(common_sources) $(llvm_sources) $(llvm_runtime_sources) $(interpreter_sources) $(arch_sources) $(os_sources)
 libmini_la_CFLAGS = $(mono_CFLAGS)
 
 libmonoboehm_2_0_la_SOURCES =
@@ -714,6 +726,9 @@ rcheck-nunit: mono $(regtests)
 rcheck: mono $(regtests)
        $(MINI_RUNTIME) --regression $(regtests)
 
+richeck: mono basic.exe
+       $(INTERPRETER_RUNTIME) --regression basic.exe
+
 if ARM
 check-seq-points:
 else
index 02c2ca8681689e9dc23ad3a68a86466e7a5a1f8a..382246ff84bb7079ef90967c1f75fac7dffaa9f6 100644 (file)
@@ -58,6 +58,7 @@
 #include "mini.h"
 #include "jit.h"
 #include "aot-compiler.h"
+#include "interpreter/interp.h"
 
 #include <string.h>
 #include <ctype.h>
@@ -1919,6 +1920,11 @@ mono_main (int argc, char* argv[])
 #endif
                } else if (strcmp (argv [i], "--nollvm") == 0){
                        mono_use_llvm = FALSE;
+#ifdef ENABLE_INTERPRETER
+               } else if (strcmp (argv [i], "--interpreter") == 0) {
+                       mono_use_interpreter = TRUE;
+#endif
+
 #ifdef __native_client__
                } else if (strcmp (argv [i], "--nacl-mono-path") == 0){
                        nacl_mono_path = g_strdup(argv[++i]);
@@ -2048,6 +2054,11 @@ mono_main (int argc, char* argv[])
        }
 
        mono_set_defaults (mini_verbose, opt);
+#if ENABLE_INTERPRETER
+       if (mono_use_interpreter)
+               domain = mono_interp_init (argv [i]);
+       else
+#endif
        domain = mini_init (argv [i], forced_version);
 
        mono_gc_set_stack_end (&domain);
@@ -2071,6 +2082,17 @@ mono_main (int argc, char* argv[])
        case DO_SINGLE_METHOD_REGRESSION:
                mono_do_single_method_regression = TRUE;
        case DO_REGRESSION:
+#ifdef ENABLE_INTERPRETER
+               if (mono_use_interpreter) {
+                       if (interp_regression_list (2, argc -i, argv + i)) {
+                               g_print ("Regression ERRORS!\n");
+                               // mini_cleanup (domain);
+                               return 1;
+                       }
+                       // mini_cleanup (domain);
+                       return 0;
+               }
+#endif
                if (mini_regression_list (mini_verbose, argc -i, argv + i)) {
                        g_print ("Regression ERRORS!\n");
                        mini_cleanup (domain);
@@ -2103,6 +2125,10 @@ mono_main (int argc, char* argv[])
                aname = argv [i];
                break;
        default:
+#ifdef ENABLE_INTERPRETER
+               if (mono_use_interpreter)
+                       g_error ("not yet");
+#endif
                if (argc - i < 1) {
                        mini_usage ();
                        mini_cleanup (domain);
index b522b93df32c0a83a90be88c9fe90eb48ad158fc..33166b8459cd9fada6d1d427cca0bb4b23e4c899 100644 (file)
@@ -85,7 +85,7 @@ enum {
 static gint *abort_requested;
 
 /* If true, then we output the opcodes as we interpret them */
-static int global_tracing = 0;
+static int global_tracing = 1;
 static int global_no_pointers = 0;
 
 int mono_interp_traceopt = 0;
@@ -3612,6 +3612,7 @@ array_constructed:
                MINT_IN_CASE(MINT_MONO_FREE)
                        ++ip;
                        --sp;
+                       g_error ("that doesn't seem right");
                        g_free (sp->data.p);
                        MINT_IN_BREAK;
                MINT_IN_CASE(MINT_MONO_RETOBJ)
@@ -4490,8 +4491,6 @@ mono_interp_init(const char *file)
        MonoRuntimeExceptionHandlingCallbacks ecallbacks;
        MonoError error;
 
-       g_set_prgname (file);
-       
        g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
        g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);
 
@@ -4545,7 +4544,6 @@ mono_interp_init(const char *file)
        mono_error_cleanup (&error); /* FIXME: don't swallow the error */
 
        mono_thread_attach (domain);
-       fprintf (stderr, "INTERPRETER: INIT DONE\n");
        return domain;
 }
 
@@ -4596,6 +4594,7 @@ interp_regression_step (MonoImage *image, int verbose, int *total_run, int *tota
                        } else {
                                result = *(gint32 *) mono_object_unbox (result_obj);
                                expected = atoi (method->name + 5);  // FIXME: oh no.
+                               run++;
 
                                if (result != expected) {
                                        failed++;
@@ -4647,7 +4646,7 @@ interp_regression (MonoImage *image, int verbose, int *total_run)
        return total;
 }
 
-static int
+int
 interp_regression_list (int verbose, int count, char *images [])
 {
        int i, total, total_run, run;
@@ -4671,105 +4670,3 @@ interp_regression_list (int verbose, int count, char *images [])
        return total;
 }
 
-enum {
-       DO_EXEC,
-       DO_REGRESSION
-};
-
-int 
-mono_main (int argc, char *argv [])
-{
-       MonoDomain *domain;
-       int retval = 0, i;
-       char *file, *config_file = NULL;
-       int enable_debugging = FALSE;
-       MainThreadArgs main_args;
-       const char *error;
-       int action = DO_EXEC;
-
-       setlocale (LC_ALL, "");
-       if (argc < 2)
-               usage ();
-
-       for (i = 1; i < argc && argv [i][0] == '-'; i++){
-               if (strcmp (argv [i], "--trace") == 0)
-                       global_tracing = 1;
-               if (strcmp (argv [i], "--noptr") == 0)
-                       global_no_pointers = 1;
-               if (strcmp (argv [i], "--regression") == 0)
-                       action = DO_REGRESSION;
-               if (strcmp (argv [i], "--traceops") == 0)
-                       global_tracing = 2;
-               if (strcmp (argv [i], "--traceopt") == 0)
-                       ++mono_interp_traceopt;
-               if (strcmp (argv [i], "--dieonex") == 0) {
-                       die_on_exception = 1;
-                       enable_debugging = 1;
-               }
-               if (strcmp (argv [i], "--print-vtable") == 0)
-                       mono_print_vtable = TRUE;
-               if (strcmp (argv [i], "--profile") == 0)
-                       mono_profiler_load (NULL);
-               if (strcmp (argv [i], "--config") == 0)
-                       config_file = argv [++i];
-               if (strcmp (argv [i], "--help") == 0)
-                       usage ();
-#if DEBUG_INTERP
-               if (strcmp (argv [i], "--debug") == 0) {
-                       MonoMethodDesc *desc = mono_method_desc_new (argv [++i], FALSE);
-                       if (!desc)
-                               g_error ("Invalid method name '%s'", argv [i]);
-                       db_methods = g_list_append (db_methods, desc);
-               }
-               if (strcmp (argv [i], "--nested") == 0)
-                       nested_trace = 1;
-#endif
-       }
-       
-       file = argv [i];
-
-       if (!file)
-               usage ();
-
-       mono_set_rootdir ();
-       domain = mono_interp_init (file);
-       mono_config_parse (config_file);
-
-       error = mono_check_corlib_version ();
-       if (error) {
-               fprintf (stderr, "Corlib not in sync with this runtime: %s\n", error);
-               fprintf (stderr, "Download a newer corlib at http://www.go-mono.com/daily.\n");
-               exit (1);
-       }
-
-       main_args.domain=domain;
-       main_args.file=file;
-       main_args.argc=argc-i;
-       main_args.argv=argv+i;
-       main_args.enable_debugging=enable_debugging;
-
-       switch (action) {
-       case DO_REGRESSION:
-               if (interp_regression_list (2, argc -i, argv + i)) {
-                       g_print ("Regression ERRORS!\n");
-                       // mini_cleanup (domain);
-                       return 1;
-               }
-               // mini_cleanup (domain);
-               return 0;
-       }
-       
-       mono_runtime_exec_managed_code (domain, main_thread_handler, &main_args);
-
-       quit_function (domain, NULL);
-
-       /* Get the return value from System.Environment.ExitCode */
-       retval=mono_environment_exitcode_get ();
-
-#if COUNT_OPS
-       for (i = 0; i < 512; i++)
-               if (opcode_counts[i] != 0)
-                       printf("%s %d\n", mono_interp_opname[i], opcode_counts[i]);
-#endif
-       return retval;
-}
index 1a65f4f9c342b58c249c888e5c99d729d756252a..5301aae0686279848b50b07442ed141417cb5563 100644 (file)
@@ -117,6 +117,9 @@ mono_interp_transform_method (RuntimeMethod *runtime_method, ThreadContext *cont
 MonoDelegate*
 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn);
 
+int
+interp_regression_list (int verbose, int count, char *images []);
+
 void
 mono_interp_transform_init (void);
 
@@ -124,6 +127,9 @@ static void inline stackval_from_data (MonoType *type, stackval *result, char *d
 static void inline stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke);
 void ves_exec_method (MonoInvocation *frame);
 
+MonoDomain *
+mono_interp_init(const char *file);
+
 /*
  * defined in an arch specific file.
  */
index 706a777bcc55bdac29c51e73782797bf0af5d4e4..99c052cee5fdc2d01769f1c2f155e08444b6e2d1 100644 (file)
@@ -110,6 +110,8 @@ int mini_verbose = 0;
  */
 gboolean mono_use_llvm = FALSE;
 
+gboolean mono_use_interpreter = FALSE;
+
 #define mono_jit_lock() mono_os_mutex_lock (&jit_mutex)
 #define mono_jit_unlock() mono_os_mutex_unlock (&jit_mutex)
 static mono_mutex_t jit_mutex;
index 643d6c748d21909d0cc5524bbc2c96099c744321..e15a86a57c56f7a86b0ff89f3c5c79efbef95e9e 100644 (file)
@@ -562,6 +562,7 @@ extern const char *mono_build_date;
 extern gboolean mono_do_signal_chaining;
 extern gboolean mono_do_crash_chaining;
 extern MONO_API gboolean mono_use_llvm;
+extern MONO_API gboolean mono_use_interpreter;
 extern gboolean mono_do_single_method_regression;
 extern guint32 mono_single_method_regression_opt;
 extern MonoMethod *mono_current_single_method;