1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

iseq.c: operand lvar

* iseq.c (rb_insn_operand_intern): show local variable operand
  name in unified instructions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-11-09 23:08:01 +00:00
parent 6820727a90
commit 324b6d306d
2 changed files with 45 additions and 10 deletions

31
iseq.c
View file

@ -1289,6 +1289,22 @@ id_to_name(ID id, VALUE default_value)
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 *iseq,
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));
}

View file

@ -52,3 +52,27 @@ insn_operands_unification(INSN *insnobj)
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;
}