Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce an option "--dump=insns_without_opt" for debugging purposes #4784

Merged
merged 2 commits into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions iseq.c
Expand Up @@ -844,11 +844,11 @@ rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath
}

rb_iseq_t *
rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent)
rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt)
{
return rb_iseq_new_with_opt(ast, rb_fstring_lit("<main>"),
path, realpath, INT2FIX(0),
parent, 0, ISEQ_TYPE_MAIN, &COMPILE_OPTION_DEFAULT);
parent, 0, ISEQ_TYPE_MAIN, opt ? &COMPILE_OPTION_DEFAULT : &COMPILE_OPTION_FALSE);
}

rb_iseq_t *
Expand Down
9 changes: 6 additions & 3 deletions ruby.c
Expand Up @@ -140,13 +140,15 @@ enum feature_flag_bits {
X(parsetree_with_comment) \
SEP \
X(insns) \
SEP \
X(insns_without_opt) \
/* END OF DUMPS */
enum dump_flag_bits {
dump_version_v,
EACH_DUMPS(DEFINE_DUMP, COMMA),
dump_exit_bits = (DUMP_BIT(yydebug) | DUMP_BIT(syntax) |
DUMP_BIT(parsetree) | DUMP_BIT(parsetree_with_comment) |
DUMP_BIT(insns))
DUMP_BIT(insns) | DUMP_BIT(insns_without_opt))
};

typedef struct ruby_cmdline_options ruby_cmdline_options_t;
Expand Down Expand Up @@ -316,6 +318,7 @@ usage(const char *name, int help, int highlight, int columns)
};
static const struct message dumps[] = {
M("insns", "", "instruction sequences"),
M("insns_without_opt", "", "instruction sequences compiled with no optimization"),
M("yydebug", "", "yydebug of yacc parser generator"),
M("parsetree", "", "AST"),
M("parsetree_with_comment", "", "AST with comments"),
Expand Down Expand Up @@ -2038,11 +2041,11 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
GetBindingPtr(rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING")),
toplevel_binding);
const struct rb_block *base_block = toplevel_context(toplevel_binding);
iseq = rb_iseq_new_main(&ast->body, opt->script_name, path, vm_block_iseq(base_block));
iseq = rb_iseq_new_main(&ast->body, opt->script_name, path, vm_block_iseq(base_block), !(dump & DUMP_BIT(insns_without_opt)));
rb_ast_dispose(ast);
}

if (dump & DUMP_BIT(insns)) {
if (dump & (DUMP_BIT(insns) | DUMP_BIT(insns_without_opt))) {
rb_io_write(rb_stdout, rb_iseq_disasm((const rb_iseq_t *)iseq));
rb_io_flush(rb_stdout);
dump &= ~DUMP_BIT(insns);
Expand Down
2 changes: 1 addition & 1 deletion vm_core.h
Expand Up @@ -1058,7 +1058,7 @@ RUBY_SYMBOL_EXPORT_BEGIN
/* node -> iseq */
rb_iseq_t *rb_iseq_new (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type);
rb_iseq_t *rb_iseq_new_top (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent);
rb_iseq_t *rb_iseq_new_main (const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent);
rb_iseq_t *rb_iseq_new_main (const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt);
rb_iseq_t *rb_iseq_new_eval (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, int isolated_depth);
rb_iseq_t *rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, int isolated_depth,
enum iseq_type, const rb_compile_option_t*);
Expand Down