summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c75
1 files changed, 74 insertions, 1 deletions
diff --git a/ruby.c b/ruby.c
index 358af620b8..925e4cd956 100644
--- a/ruby.c
+++ b/ruby.c
@@ -51,6 +51,8 @@
#include "ruby/util.h"
+#include "mjit.h"
+
#ifndef HAVE_STDLIB_H
char *getenv();
#endif
@@ -135,6 +137,7 @@ struct ruby_cmdline_options {
VALUE req_list;
unsigned int features;
unsigned int dump;
+ struct mjit_options mjit;
int safe_level;
int sflag, xflag;
unsigned int warning: 1;
@@ -193,7 +196,7 @@ static void
show_usage_line(const char *str, unsigned int namelen, unsigned int secondlen, int help)
{
const unsigned int w = 16;
- const int wrap = help && namelen + secondlen - 2 > w;
+ const int wrap = help && namelen + secondlen - 1 > w;
printf(" %.*s%-*.*s%-*s%s\n", namelen-1, str,
(wrap ? 0 : w - namelen + 1),
(help ? secondlen-1 : 0), str + namelen,
@@ -238,6 +241,8 @@ usage(const char *name, int help)
M("-w", "", "turn warnings on for your script"),
M("-W[level=2]", "", "set warning level; 0=silence, 1=medium, 2=verbose"),
M("-x[directory]", "", "strip off text before #!ruby line and perhaps cd to directory"),
+ M("--jit", "", "enable MJIT with default options (experimental)"),
+ M("--jit-[option]","", "enable MJIT with an option (experimental)"),
M("-h", "", "show this message, --help for more info"),
};
static const struct message help_msg[] = {
@@ -263,6 +268,16 @@ usage(const char *name, int help)
M("rubyopt", "", "RUBYOPT environment variable (default: enabled)"),
M("frozen-string-literal", "", "freeze all string literals (default: disabled)"),
};
+ static const struct message mjit_options[] = {
+ M("--jit-cc=cc", "", "C compiler to generate native code (gcc, clang)"),
+ M("--jit-warnings", "", "Enable printing MJIT warnings"),
+ M("--jit-debug", "", "Enable MJIT debugging (very slow)"),
+ M("--jit-wait", "", "Wait until JIT compilation is finished everytime (for testing)"),
+ M("--jit-save-temps", "", "Save MJIT temporary files in $TMP or /tmp (for testing)"),
+ M("--jit-verbose=num", "", "Print MJIT logs of level num or less to stderr (default: 0)"),
+ M("--jit-max-cache=num", "", "Max number of methods to be JIT-ed in a cache (default: 1000)"),
+ M("--jit-min-calls=num", "", "Number of calls to trigger JIT (for testing, default: 5)"),
+ };
int i;
const int num = numberof(usage_msg) - (help ? 1 : 0);
#define SHOW(m) show_usage_line((m).str, (m).namelen, (m).secondlen, help)
@@ -281,6 +296,9 @@ usage(const char *name, int help)
puts("Features:");
for (i = 0; i < numberof(features); ++i)
SHOW(features[i]);
+ puts("MJIT options (experimental):");
+ for (i = 0; i < numberof(mjit_options); ++i)
+ SHOW(mjit_options[i]);
}
#define rubylib_path_new rb_str_new
@@ -893,6 +911,55 @@ set_option_encoding_once(const char *type, VALUE *name, const char *e, long elen
#define set_source_encoding_once(opt, e, elen) \
set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen))
+static enum rb_mjit_cc
+parse_mjit_cc(const char *s)
+{
+ if (strcmp(s, "gcc") == 0) {
+ return MJIT_CC_GCC;
+ }
+ else if (strcmp(s, "clang") == 0) {
+ return MJIT_CC_CLANG;
+ }
+ else {
+ rb_raise(rb_eRuntimeError, "invalid C compiler `%s' (available C compilers: gcc, clang)", s);
+ }
+}
+
+static void
+setup_mjit_options(const char *s, struct mjit_options *mjit_opt)
+{
+ mjit_opt->on = 1;
+ if (*s == 0) return;
+ if (strncmp(s, "-cc=", 4) == 0) {
+ mjit_opt->cc = parse_mjit_cc(s + 4);
+ }
+ else if (strcmp(s, "-warnings") == 0) {
+ mjit_opt->warnings = 1;
+ }
+ else if (strcmp(s, "-debug") == 0) {
+ mjit_opt->debug = 1;
+ }
+ else if (strcmp(s, "-wait") == 0) {
+ mjit_opt->wait = 1;
+ }
+ else if (strcmp(s, "-save-temps") == 0) {
+ mjit_opt->save_temps = 1;
+ }
+ else if (strncmp(s, "-verbose=", 9) == 0) {
+ mjit_opt->verbose = atoi(s + 9);
+ }
+ else if (strncmp(s, "-max-cache=", 11) == 0) {
+ mjit_opt->max_cache_size = atoi(s + 11);
+ }
+ else if (strncmp(s, "-min-calls=", 11) == 0) {
+ mjit_opt->min_calls = atoi(s + 11);
+ }
+ else {
+ rb_raise(rb_eRuntimeError,
+ "invalid MJIT option `%s' (--help will show valid MJIT options)", s + 1);
+ }
+}
+
static long
proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
{
@@ -1245,6 +1312,9 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
opt->verbose = 1;
ruby_verbose = Qtrue;
}
+ else if (strncmp("jit", s, 3) == 0) {
+ setup_mjit_options(s + 3, &opt->mjit);
+ }
else if (strcmp("yydebug", s) == 0) {
if (envopt) goto noenvopt_long;
opt->dump |= DUMP_BIT(yydebug);
@@ -1481,6 +1551,9 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
opt->intern.enc.name = int_enc_name;
}
+ if (opt->mjit.on)
+ mjit_init(&opt->mjit);
+
if (opt->src.enc.name)
rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");