ruby-changes:4510
From: ko1@a...
Date: Mon, 14 Apr 2008 14:34:19 +0900 (JST)
Subject: [ruby-changes:4510] nobu - Ruby:r16003 (trunk): * compile.c, compile.h (compile_debug): made runtime option.
nobu 2008-04-14 14:34:04 +0900 (Mon, 14 Apr 2008) New Revision: 16003 Modified files: trunk/ChangeLog trunk/compile.c trunk/compile.h trunk/debug.c trunk/debug.h trunk/iseq.c trunk/vm_core.h Log: * compile.c, compile.h (compile_debug): made runtime option. * debug.c (ruby_debug_print_indent): returns if debug_level exceeds the threashold. * debug.c (ruby_debug_printf): printf to stderr. * iseq.c (make_compile_option, make_compile_option_value): added debug_level option. * vm_core.h (rb_compile_option_t): added debug_level. * vm_core.h (struct iseq_compile_data): added node_level. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/debug.h?r1=16003&r2=16002&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/compile.c?r1=16003&r2=16002&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16003&r2=16002&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/vm_core.h?r1=16003&r2=16002&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/iseq.c?r1=16003&r2=16002&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/debug.c?r1=16003&r2=16002&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/compile.h?r1=16003&r2=16002&diff_format=u Index: debug.c =================================================================== --- debug.c (revision 16002) +++ debug.c (revision 16003) @@ -67,15 +67,26 @@ const VALUE RUBY_FL_USER20 = FL_USER20; -void +int ruby_debug_print_indent(int level, int debug_level, int indent_level) { if (level < debug_level) { fprintf(stderr, "%*s", indent_level, ""); fflush(stderr); + return Qtrue; } + return Qfalse; } +void +ruby_debug_printf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); +} + VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj) { Index: debug.h =================================================================== --- debug.h (revision 16002) +++ debug.h (revision 16003) @@ -25,7 +25,7 @@ VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE v); ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id); NODE *ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node); -void ruby_debug_print_indent(int level, int debug_level, int indent_level); +int ruby_debug_print_indent(int level, int debug_level, int indent_level); void ruby_debug_breakpoint(void); void ruby_debug_gc_check_func(void); Index: ChangeLog =================================================================== --- ChangeLog (revision 16002) +++ ChangeLog (revision 16003) @@ -1,3 +1,19 @@ +Mon Apr 14 14:33:59 2008 Nobuyoshi Nakada <nobu@r...> + + * compile.c, compile.h (compile_debug): made runtime option. + + * debug.c (ruby_debug_print_indent): returns if debug_level exceeds + the threashold. + + * debug.c (ruby_debug_printf): printf to stderr. + + * iseq.c (make_compile_option, make_compile_option_value): added + debug_level option. + + * vm_core.h (rb_compile_option_t): added debug_level. + + * vm_core.h (struct iseq_compile_data): added node_level. + Mon Apr 14 12:52:25 2008 Nobuyoshi Nakada <nobu@r...> * gc.c (Init_stack): use ruby_init_stack. [ruby-dev:34350] Index: vm_core.h =================================================================== --- vm_core.h (revision 16002) +++ vm_core.h (revision 16003) @@ -139,6 +139,7 @@ int instructions_unification; int stack_caching; int trace_instruction; + int debug_level; } rb_compile_option_t; struct iseq_compile_data { @@ -161,6 +162,7 @@ struct iseq_compile_data_storage *storage_current; int last_line; int flip_cnt; + int node_level; const rb_compile_option_t *option; }; Index: iseq.c =================================================================== --- iseq.c (revision 16002) +++ iseq.c (revision 16003) @@ -241,6 +241,10 @@ if (flag == Qtrue) { o->mem = 1; } \ else if (flag == Qfalse) { o->mem = 0; } \ } +#define SET_COMPILE_OPTION_NUM(o, h, mem) \ + { VALUE num = rb_hash_aref(opt, ID2SYM(rb_intern(#mem))); \ + if (!NIL_P(num)) o->mem = NUM2INT(num); \ + } SET_COMPILE_OPTION(option, opt, inline_const_cache); SET_COMPILE_OPTION(option, opt, peephole_optimization); SET_COMPILE_OPTION(option, opt, tailcall_optimization); @@ -249,7 +253,9 @@ SET_COMPILE_OPTION(option, opt, instructions_unification); SET_COMPILE_OPTION(option, opt, stack_caching); SET_COMPILE_OPTION(option, opt, trace_instruction); + SET_COMPILE_OPTION_NUM(option, opt, debug_level); #undef SET_COMPILE_OPTION +#undef SET_COMPILE_OPTION_NUM } else { rb_raise(rb_eTypeError, "Compile option must be Hash/true/false/nil"); @@ -262,6 +268,8 @@ VALUE opt = rb_hash_new(); #define SET_COMPILE_OPTION(o, h, mem) \ rb_hash_aset(h, ID2SYM(rb_intern(#mem)), o->mem ? Qtrue : Qfalse) +#define SET_COMPILE_OPTION_NUM(o, h, mem) \ + rb_hash_aset(h, ID2SYM(rb_intern(#mem)), INT2NUM(o->mem)) { SET_COMPILE_OPTION(option, opt, inline_const_cache); SET_COMPILE_OPTION(option, opt, peephole_optimization); @@ -270,8 +278,10 @@ SET_COMPILE_OPTION(option, opt, operands_unification); SET_COMPILE_OPTION(option, opt, instructions_unification); SET_COMPILE_OPTION(option, opt, stack_caching); + SET_COMPILE_OPTION_NUM(option, opt, debug_level); } #undef SET_COMPILE_OPTION +#undef SET_COMPILE_OPTION_NUM return opt; } Index: compile.c =================================================================== --- compile.c (revision 16002) +++ compile.c (revision 16003) @@ -92,18 +92,28 @@ #endif /* for debug */ -#if CPDEBUG > 0 -static long gl_node_level = 0; -static void debug_list(LINK_ANCHOR *anchor); +#if CPDEBUG < 0 +#define ISEQ_ARG iseq, +#define ISEQ_ARG_DECLARE rb_iseq_t *iseq, +#else +#define ISEQ_ARG +#define ISEQ_ARG_DECLARE #endif +#if CPDEBUG +#define gl_node_level iseq->compile_data->node_level +#if 0 +static void debug_list(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor); +#endif +#endif + static void dump_disasm_list(LINK_ELEMENT *elem); static int insn_data_length(INSN *iobj); static int insn_data_line_no(INSN *iobj); static int calc_sp_depth(int depth, INSN *iobj); -static void ADD_ELEM(LINK_ANCHOR *anchor, LINK_ELEMENT *elem); +static void ADD_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor, LINK_ELEMENT *elem); static INSN *new_insn_body(rb_iseq_t *iseq, int line_no, int insn_id, int argc, ...); static LABEL *new_label_body(rb_iseq_t *iseq, int line); @@ -123,6 +133,57 @@ static int iseq_set_exception_table(rb_iseq_t *iseq); static int iseq_set_optargs_table(rb_iseq_t *iseq); +/* + * To make Array to LinkedList, use link_anchor + */ + +static void +verify_list(ISEQ_ARG_DECLARE char *info, LINK_ANCHOR *anchor) +{ +#if CPDEBUG + int flag = 0; + LINK_ELEMENT *list, *plist; + + if (!compile_debug) return; + + list = anchor->anchor.next; + plist = &anchor->anchor; + while (list) { + if (plist != list->prev) { + flag += 1; + } + plist = list; + list = list->next; + } + + if (anchor->last != plist && anchor->last != 0) { + flag |= 0x70000; + } + + if (flag != 0) { + rb_bug("list verify error: %08x (%s)", flag, info); + } +#endif +} +#if CPDEBUG < 0 +#define verify_list(info, anchor) verify_list(iseq, info, anchor) +#endif + +/* + * elem1, elem2 => elem1, elem2, elem + */ +static void +ADD_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor, LINK_ELEMENT *elem) +{ + elem->prev = anchor->last; + anchor->last->next = elem; + anchor->last = elem; + verify_list("add", anchor); +} +#if CPDEBUG < 0 +#define ADD_ELEM(anchor, elem) ADD_ELEM(iseq, anchor, elem) +#endif + static int iseq_add_mark_object(rb_iseq_t *iseq, VALUE v) { @@ -310,47 +371,6 @@ } /* - * To make Array to LinkedList, use link_anchor - */ - -static void -verify_list(char *info, LINK_ANCHOR *anchor) -{ -#if CPDEBUG > 0 - int flag = 0; - LINK_ELEMENT *list = anchor->anchor.next, *plist = &anchor->anchor; - - while (list) { - if (plist != list->prev) { - flag += 1; - } - plist = list; - list = list->next; - } - - if (anchor->last != plist && anchor->last != 0) { - flag |= 0x70000; - } - - if (flag != 0) { - rb_bug("list verify error: %08x (%s)", flag, info); - } -#endif -} - -/* - * elem1, elem2 => elem1, elem2, elem - */ -static void -ADD_ELEM(LINK_ANCHOR *anchor, LINK_ELEMENT *elem) -{ - elem->prev = anchor->last; - anchor->last->next = elem; - anchor->last = elem; - verify_list("add", anchor); -} - -/* * elem1, elemX => elem1, elem2, elemX */ static void @@ -420,7 +440,7 @@ #endif static LINK_ELEMENT * -POP_ELEMENT(LINK_ANCHOR *anchor) +POP_ELEMENT(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor) { LINK_ELEMENT *elem = anchor->last; anchor->last = anchor->last->prev; @@ -428,6 +448,9 @@ verify_list("pop", anchor); return elem; } +#if CPDEBUG < 0 +#define POP_ELEMENT(anchor) POP_ELEMENT(iseq, anchor) +#endif #if 0 /* unused */ static LINK_ELEMENT * @@ -474,7 +497,7 @@ * anc2: e4, e5 (broken) */ static void -APPEND_LIST(LINK_ANCHOR *anc1, LINK_ANCHOR *anc2) +APPEND_LIST(ISEQ_ARG_DECLARE LINK_ANCHOR *anc1, LINK_ANCHOR *anc2) { if (anc2->anchor.next) { anc1->last->next = anc2->anchor.next; @@ -483,6 +506,9 @@ } verify_list("append", anc1); } +#if CPDEBUG < 0 +#define APPEND_LIST(anc1, anc2) APPEND_LIST(iseq, anc1, anc2) +#endif /* * anc1: e1, e2, e3 @@ -492,7 +518,7 @@ * anc2: e4, e5 (broken) */ static void -INSERT_LIST(LINK_ANCHOR *anc1, LINK_ANCHOR *anc2) +INSERT_LIST(ISEQ_ARG_DECLARE LINK_ANCHOR *anc1, LINK_ANCHOR *anc2) { if (anc2->anchor.next) { LINK_ELEMENT *first = anc1->anchor.next; @@ -509,6 +535,9 @@ verify_list("append", anc1); } +#if CPDEBUG < 0 +#define INSERT_LIST(anc1, anc2) INSERT_LIST(iseq, anc1, anc2) +#endif #if 0 /* unused */ /* @@ -519,7 +548,7 @@ * anc2: e1, e2, e3 */ static void -SWAP_LIST(LINK_ANCHOR *anc1, LINK_ANCHOR *anc2) +SWAP_LIST(ISEQ_ARG_DECLARE LINK_ANCHOR *anc1, LINK_ANCHOR *anc2) { LINK_ANCHOR tmp = *anc2; @@ -530,9 +559,12 @@ verify_list("swap1", anc1); verify_list("swap2", anc2); } +#if CPDEBUG < 0 +#define SWAP_LIST(anc1, anc2) SWAP_LIST(iseq, anc1, anc2) +#endif static LINK_ANCHOR * -REVERSE_LIST(LINK_ANCHOR *anc) +REVERSE_LIST(ISEQ_ARG_DECLARE LINK_ANCHOR *anc) { LINK_ELEMENT *first, *last, *elem, *e; first = &anc->anchor; @@ -561,11 +593,14 @@ verify_list("reverse", anc); return anc; } +#if CPDEBUG < 0 +#define REVERSE_LIST(anc) REVERSE_LIST(iseq, anc) #endif +#endif -#if CPDEBUG > 0 +#if CPDEBUG && 0 static void -debug_list(LINK_ANCHOR *anchor) +debug_list(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor) { LINK_ELEMENT *list = FIRST_ELEMENT(anchor); printf("----\n"); @@ -581,7 +616,10 @@ dump_disasm_list(anchor->anchor.next); verify_list("debug list", anchor); } +#if CPDEBUG < 0 +#define debug_list(anc) debug_list(iseq, anc) #endif +#endif static LABEL * new_label_body(rb_iseq_t *iseq, int line) @@ -678,32 +716,32 @@ { /* debugs("[compile step 2] (iseq_array_to_linkedlist)\n"); */ - if (CPDEBUG > 5) + if (compile_debug > 5) dump_disasm_list(FIRST_ELEMENT(anchor)); debugs("[compile step 3.1 (iseq_optimize)]\n"); iseq_optimize(iseq, anchor); - if (CPDEBUG > 5) + if (compile_debug > 5) dump_disasm_list(FIRST_ELEMENT(anchor)); if (iseq->compile_data->option->instructions_unification) { debugs("[compile step 3.2 (iseq_insns_unification)]\n"); iseq_insns_unification(iseq, anchor); - if (CPDEBUG > 5) + if (compile_debug > 5) dump_disasm_list(FIRST_ELEMENT(anchor)); } if (iseq->compile_data->option->stack_caching) { debugs("[compile step 3.3 (iseq_set_sequence_stackcaching)]\n"); iseq_set_sequence_stackcaching(iseq, anchor); - if (CPDEBUG > 5) + if (compile_debug > 5) dump_disasm_list(FIRST_ELEMENT(anchor)); } debugs("[compile step 4.1 (iseq_set_sequence)]\n"); iseq_set_sequence(iseq, anchor); - if (CPDEBUG > 5) + if (compile_debug > 5) dump_disasm_list(FIRST_ELEMENT(anchor)); debugs("[compile step 4.2 (iseq_set_exception_table)]\n"); @@ -715,7 +753,7 @@ debugs("[compile step 5 (iseq_translate_threaded_code)] \n"); iseq_translate_threaded_code(iseq); - if (CPDEBUG > 1) { + if (compile_debug > 1) { VALUE str = ruby_iseq_disasm(iseq->self); printf("%s\n", StringValueCStr(str)); fflush(stdout); Index: compile.h =================================================================== --- compile.h (revision 16002) +++ compile.h (revision 16003) @@ -15,6 +15,7 @@ /* */ /** * debug function(macro) interface depend on CPDEBUG + * if it is less than 0, runtime option is in effect. * * debug level: * 0: no debug output @@ -29,39 +30,44 @@ #define CPDEBUG 0 #endif -#if 0 -#undef CPDEBUG -#define CPDEBUG 2 +#if CPDEBUG >= 0 +#define compile_debug CPDEBUG +#else +#define compile_debug iseq->compile_data->option->debug_level #endif NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4)); -#if CPDEBUG > 0 +#if CPDEBUG -#define debugp(header, value) \ - (ruby_debug_print_indent(0, CPDEBUG, gl_node_level * 2), \ - ruby_debug_print_value(0, CPDEBUG, header, value)) +#define compile_debug_print_indent(level) \ + ruby_debug_print_indent(level, compile_debug, gl_node_level * 2) -#define debugi(header, id) \ - (ruby_debug_print_indent(0, CPDEBUG, gl_node_level * 2), \ - ruby_debug_print_id(0, CPDEBUG, header, id)) +#define debugp(header, value) (void) \ + (compile_debug_print_indent(1) && \ + ruby_debug_print_value(1, compile_debug, header, value)) -#define debugp_param(header, value) \ - (ruby_debug_print_indent(1, CPDEBUG, gl_node_level * 2), \ - ruby_debug_print_value(1, CPDEBUG, header, value)) +#define debugi(header, id) (void) \ + (compile_debug_print_indent(1) && \ + ruby_debug_print_id(1, compile_debug, header, id)) -#define debugp_verbose(header, value) \ - (ruby_debug_print_indent(2, CPDEBUG, gl_node_level * 2), \ - ruby_debug_print_value(2, CPDEBUG, header, value)) +#define debugp_param(header, value) (void) \ + (compile_debug_print_indent(1) && \ + ruby_debug_print_value(1, compile_debug, header, value)) -#define debugp_verbose_node(header, value) \ - (ruby_debug_print_indent(10, CPDEBUG, gl_node_level * 2), \ - ruby_debug_print_value(10, CPDEBUG, header, value)) +#define debugp_verbose(header, value) (void) \ + (compile_debug_print_indent(2) && \ + ruby_debug_print_value(2, compile_debug, header, value)) -#define debug_node_start(node) \ - (ruby_debug_print_indent(-1, CPDEBUG, gl_node_level*2), \ - ruby_debug_print_node(1, CPDEBUG, "", (NODE *)node), gl_node_level++) \ +#define debugp_verbose_node(header, value) (void) \ + (compile_debug_print_indent(10) && \ + ruby_debug_print_value(10, compile_debug, header, value)) +#define debug_node_start(node) ((void) \ + (compile_debug_print_indent(1) && \ + (ruby_debug_print_node(1, CPDEBUG, "", (NODE *)node), gl_node_level)), \ + gl_node_level++) + #define debug_node_end() gl_node_level --; #else @@ -83,13 +89,14 @@ #define debugp_verbose(header, value) r_value(value) #define debugp_verbose_node(header, value) r_value(value) #define debugp_param(header, value) r_value(value) -#define debug_node_start(node) -#define debug_node_end() +#define debug_node_start(node) ((void)0) +#define debug_node_end() ((void)0) #endif -#if CPDEBUG > 1 -#define debugs ruby_debug_print_indent(-1, CPDEBUG, gl_node_level*2), printf -#define debug_compile(msg, v) (ruby_debug_print_indent(-1, CPDEBUG, gl_node_level*2), printf("%s", msg), (v)) +#if CPDEBUG > 1 || CPDEBUG < 0 +PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2); +#define debugs if (compile_debug_print_indent(1)) ruby_debug_printf +#define debug_compile(msg, v) ((void)(compile_debug_print_indent(1) && fputs(msg, stderr)), (v)) #else #define debugs if(0)printf #define debug_compile(msg, v) (v) @@ -201,7 +208,7 @@ #define COMPILE_ERROR(strs) \ { \ VALUE tmp = GET_THREAD()->errinfo; \ - if(CPDEBUG)rb_bug strs; \ + if (compile_debug) rb_compile_bug strs; \ GET_THREAD()->errinfo = iseq->compile_data->err_info; \ rb_compile_error strs; \ iseq->compile_data->err_info = GET_THREAD()->errinfo; \ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/