ruby-changes:48617
From: nobu <ko1@a...>
Date: Fri, 10 Nov 2017 08:08:06 +0900 (JST)
Subject: [ruby-changes:48617] nobu:r60732 (trunk): iseq.c: operand lvar
nobu 2017-11-10 08:08:01 +0900 (Fri, 10 Nov 2017) New Revision: 60732 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60732 Log: iseq.c: operand lvar * iseq.c (rb_insn_operand_intern): show local variable operand name in unified instructions. Modified files: trunk/iseq.c trunk/template/optinsn.inc.tmpl Index: template/optinsn.inc.tmpl =================================================================== --- template/optinsn.inc.tmpl (revision 60731) +++ template/optinsn.inc.tmpl (revision 60732) @@ -52,3 +52,27 @@ insn_operands_unification(INSN *insnobj) https://github.com/ruby/ruby/blob/trunk/template/optinsn.inc.tmpl#L52 return insnobj; } +int +rb_insn_unified_local_var_level(VALUE insn) +{ +#ifdef OPT_OPERANDS_UNIFICATION + /* optimize rule */ + switch (insn) { +% opt_insns_map.each do |originsn, optinsns| +% optinsns.each {|opti| + case BIN(<%=opti.name%>): +% opti.defopes.each {|opinfo| +% next if opinfo[1] == '*' + return <%=opinfo[1]%>; +% break +% } +% } +% end + + default: + /* do nothing */; + break; + } +#endif + return -1; +} Index: iseq.c =================================================================== --- iseq.c (revision 60731) +++ iseq.c (revision 60732) @@ -1289,6 +1289,22 @@ id_to_name(ID id, VALUE default_value) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1289 return str; } +static VALUE +local_var_name(const rb_iseq_t *diseq, VALUE level, VALUE op) +{ + VALUE i; + ID lid; + + for (i = 0; i < level; i++) { + diseq = diseq->body->parent_iseq; + } + lid = diseq->body->local_table[diseq->body->local_table_size + + VM_ENV_DATA_SIZE - 1 - op]; + return id_to_name(lid, INT2FIX('*')); +} + +int rb_insn_unified_local_var_level(VALUE); + VALUE rb_insn_operand_intern(const rb_iseq_t *iseq, VALUE insn, int op_no, VALUE op, @@ -1308,23 +1324,18 @@ rb_insn_operand_intern(const rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.c#L1324 break; case TS_LINDEX:{ + int level; if (insn == BIN(getlocal) || insn == BIN(setlocal)) { if (pnop) { - const rb_iseq_t *diseq = iseq; - VALUE level = *pnop, i; - ID lid; - - for (i = 0; i < level; i++) { - diseq = diseq->body->parent_iseq; - } - lid = diseq->body->local_table[diseq->body->local_table_size + - VM_ENV_DATA_SIZE - 1 - op]; - ret = id_to_name(lid, INT2FIX('*')); + ret = local_var_name(iseq, *pnop, op); } else { ret = rb_sprintf("%"PRIuVALUE, op); } } + else if ((level = rb_insn_unified_local_var_level(insn)) >= 0) { + ret = local_var_name(iseq, (VALUE)level, op); + } else { ret = rb_inspect(INT2FIX(op)); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/