* ruby.c (proc_options, process_options): --dump option.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0343750b62
commit
8afd39ad09
@ -1,3 +1,7 @@
|
|||||||
|
Tue May 20 12:13:50 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ruby.c (proc_options, process_options): --dump option.
|
||||||
|
|
||||||
Tue May 20 11:36:06 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue May 20 11:36:06 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* include/ruby/ruby.h (PRI[diouxX]VALUE): printf format for VALUE.
|
* include/ruby/ruby.h (PRI[diouxX]VALUE): printf format for VALUE.
|
||||||
|
27
ruby.c
27
ruby.c
@ -72,6 +72,11 @@ enum disable_flag_bits {
|
|||||||
disable_rubyopt,
|
disable_rubyopt,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define DUMP_BIT(bit) (1U << dump_##bit)
|
||||||
|
enum dump_flag_bits {
|
||||||
|
dump_insns,
|
||||||
|
};
|
||||||
|
|
||||||
struct cmdline_options {
|
struct cmdline_options {
|
||||||
int sflag, xflag;
|
int sflag, xflag;
|
||||||
int do_loop, do_print;
|
int do_loop, do_print;
|
||||||
@ -83,6 +88,7 @@ struct cmdline_options {
|
|||||||
unsigned int disable;
|
unsigned int disable;
|
||||||
int verbose;
|
int verbose;
|
||||||
int yydebug;
|
int yydebug;
|
||||||
|
unsigned int dump;
|
||||||
char *script;
|
char *script;
|
||||||
VALUE script_name;
|
VALUE script_name;
|
||||||
VALUE e_script;
|
VALUE e_script;
|
||||||
@ -587,6 +593,14 @@ disable_option(const char *str, int len, void *arg)
|
|||||||
rb_warn("unknown argument for --disable: `%.*s'", len, str);
|
rb_warn("unknown argument for --disable: `%.*s'", len, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_option(const char *str, int len, void *arg)
|
||||||
|
{
|
||||||
|
#define SET_WHEN_DUMP(bit) SET_WHEN(#bit, DUMP_BIT(bit), str, len)
|
||||||
|
SET_WHEN_DUMP(insns);
|
||||||
|
rb_warn("don't know how to dump `%.*s', (insns)", len, str);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
proc_options(int argc, char **argv, struct cmdline_options *opt)
|
proc_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
{
|
{
|
||||||
@ -874,6 +888,10 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
|
|||||||
}
|
}
|
||||||
else if (strcmp("yydebug", s) == 0)
|
else if (strcmp("yydebug", s) == 0)
|
||||||
opt->yydebug = 1;
|
opt->yydebug = 1;
|
||||||
|
else if (strncmp("dump", s, n = 4) == 0 && (!s[n] || s[n] == '=')) {
|
||||||
|
if (!(s += n + 1)[-1] && (!--argc || !(s = *++argv)) && *s != '-') break;
|
||||||
|
ruby_each_words(s, dump_option, &opt->dump);
|
||||||
|
}
|
||||||
else if (strcmp("help", s) == 0) {
|
else if (strcmp("help", s) == 0) {
|
||||||
usage(origarg.argv[0]);
|
usage(origarg.argv[0]);
|
||||||
rb_exit(EXIT_SUCCESS);
|
rb_exit(EXIT_SUCCESS);
|
||||||
@ -949,6 +967,7 @@ process_options(VALUE arg)
|
|||||||
char **argv = argp->argv;
|
char **argv = argp->argv;
|
||||||
NODE *tree = 0;
|
NODE *tree = 0;
|
||||||
VALUE parser;
|
VALUE parser;
|
||||||
|
VALUE iseq;
|
||||||
rb_encoding *enc, *lenc;
|
rb_encoding *enc, *lenc;
|
||||||
const char *s;
|
const char *s;
|
||||||
char fbuf[MAXPATHLEN];
|
char fbuf[MAXPATHLEN];
|
||||||
@ -1121,8 +1140,14 @@ process_options(VALUE arg)
|
|||||||
tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
|
tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rb_iseq_new(tree, rb_str_new2("<main>"),
|
iseq = rb_iseq_new(tree, rb_str_new2("<main>"),
|
||||||
opt->script_name, Qfalse, ISEQ_TYPE_TOP);
|
opt->script_name, Qfalse, ISEQ_TYPE_TOP);
|
||||||
|
if (opt->dump & DUMP_BIT(insns)) {
|
||||||
|
rb_io_write(rb_stdout, ruby_iseq_disasm(iseq));
|
||||||
|
rb_io_flush(rb_stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return iseq;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user