summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-04 12:31:05 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-04 12:31:05 +0000
commit23dc0dbc4ad3354a9df899c0105c57bf42e2d243 (patch)
tree9fdcd41591a161885d19cdd96949d743fdc69102 /iseq.c
parentb1ad79774de9789a2dd60c19c907356fa823ebd9 (diff)
* vm.c (VM_COLLECT_USAGE_DETAILS): make new VM usage analysis
hooks (old macro name is COLLECT_USAGE_ANALYSIS). This feature is only for VM developers. (I'm not sure I can use `VM developers' (the plural form) in this sentence). If VM_COLLECT_USAGE_DETAILS is not 0, VM enables the following usage collection features: (1) insntruction: collect intruction usages. (2) operand: collect operand usages. (3) register: collect register usages. The results are stored in RubyVM::USAGE_ANALYSIS_INSN for (1, 2), RubyVM::USAGE_ANALYSIS_INSN_BIGRAM for (1) and RubyVM::USAGE_ANALYSIS_REGS for (3). You can stop collecting usages with RubyVM::USAGE_ANALYSIS_INSN_STOP(), RubyVM::USAGE_ANALYSIS_OPERAND_STOP(), RubyVM::USAGE_ANALYSIS_REGISTER_STOP() for (1), (2), (3) respectively. You can also change the hook functions by setting C level global variables `ruby_vm_collect_usage_func_(insn|operand|register)' for (1), (2), (3) respectively. See codes for more details. * tool/instruction.rb: fix macro names. * iseq.c (insn_operand_intern): make it export (used in vm.c). fix to skip several processes if not needed (pointer is 0). * vm_dump.c: move codes for collection features to vm.c. * vm_exec.h: rename macro and function names. * vm_insnhelper.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/iseq.c b/iseq.c
index e34537e871..a6f39bc1f7 100644
--- a/iseq.c
+++ b/iseq.c
@@ -963,7 +963,7 @@ id_to_name(ID id, VALUE default_value)
return str;
}
-static VALUE
+VALUE
insn_operand_intern(rb_iseq_t *iseq,
VALUE insn, int op_no, VALUE op,
int len, size_t pos, VALUE *pnop, VALUE child)
@@ -991,13 +991,18 @@ insn_operand_intern(rb_iseq_t *iseq,
}
case TS_DINDEX:{
if (insn == BIN(getdynamic) || insn == BIN(setdynamic)) {
- rb_iseq_t *diseq = iseq;
- VALUE level = *pnop, i;
+ if (pnop) {
+ rb_iseq_t *diseq = iseq;
+ VALUE level = *pnop, i;
- for (i = 0; i < level; i++) {
- diseq = diseq->parent_iseq;
+ for (i = 0; i < level; i++) {
+ diseq = diseq->parent_iseq;
+ }
+ ret = id_to_name(diseq->local_table[diseq->local_size - op], INT2FIX('*'));
+ }
+ else {
+ ret = rb_sprintf("%"PRIuVALUE, op);
}
- ret = id_to_name(diseq->local_table[diseq->local_size - op], INT2FIX('*'));
}
else {
ret = rb_inspect(INT2FIX(op));
@@ -1011,7 +1016,9 @@ insn_operand_intern(rb_iseq_t *iseq,
op = obj_resurrect(op);
ret = rb_inspect(op);
if (CLASS_OF(op) == rb_cISeq) {
- rb_ary_push(child, op);
+ if (child) {
+ rb_ary_push(child, op);
+ }
}
break;
@@ -1049,7 +1056,7 @@ insn_operand_intern(rb_iseq_t *iseq,
break;
default:
- rb_bug("rb_iseq_disasm: unknown operand type: %c", type);
+ rb_bug("insn_operand_intern: unknown operand type: %c", type);
}
return ret;
}