Created
August 6, 2009 23:06
-
-
Save mark-moseley/163613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int | |
rb_iseq_translate_threaded_code(rb_iseq_t *iseq) | |
{ | |
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE | |
extern const void **rb_vm_get_insns_address_table(void); | |
#if OPT_DIRECT_THREADED_CODE | |
const void * const *table = rb_vm_get_insns_address_table(); | |
#else | |
const void * const *table = rb_vm_get_insns_address_table(); | |
#endif | |
unsigned long i; | |
iseq->iseq_encoded = ALLOC_N(VALUE, iseq->iseq_size); | |
MEMCPY(iseq->iseq_encoded, iseq->iseq, VALUE, iseq->iseq_size); | |
for (i = 0; i < iseq->iseq_size; /* */ ) { | |
int insn = (int)iseq->iseq_encoded[i]; | |
int len = insn_len(insn); | |
iseq->iseq_encoded[i] = (VALUE)table[insn]; | |
i += len; | |
} | |
#else | |
iseq->iseq_encoded = iseq->iseq; | |
#endif | |
/* new benchmarking code starts here */ | |
iseq->iseq_flag = ALLOC_N(char, iseq->iseq_size); | |
MEMZERO(iseq->iseq_flag, char, iseq->iseq_size); | |
iseq->iseq_flag[0] = RUBY_EVENT_CALL; /* questionable */ | |
{ | |
unsigned long pos = 0; | |
int prev_line = 0; | |
while (pos < iseq->iseq_size) | |
{ | |
int insn = iseq->iseq[pos]; | |
int line = find_line_no(iseq, pos); | |
if (insn == BIN(leave)) | |
iseq->iseq_flag[pos] |= RUBY_EVENT_RETURN; | |
if (line != prev_line) | |
{ | |
iseq->iseq_flag[pos] |= RUBY_EVENT_LINE; | |
prev_line = line; | |
} | |
pos += insn_len(insn); | |
} | |
} | |
return COMPILE_OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment