class RubyVM::YJIT::Block

Public Instance Methods

address() click to toggle source

Get the address of the code associated with a YJIT::Block

static VALUE
block_address(VALUE self)
{
    block_t * block;
    TypedData_Get_Struct(self, block_t, &yjit_block_type, block);
    return LONG2NUM((intptr_t)block->start_addr);
}
code() click to toggle source

Get the machine code for YJIT::Block as a binary string

static VALUE
block_code(VALUE self)
{
    block_t * block;
    TypedData_Get_Struct(self, block_t, &yjit_block_type, block);

    return (VALUE)rb_str_new(
        (const char*)block->start_addr,
        block->end_addr - block->start_addr
    );
}
id → unique_id click to toggle source

Returns a unique integer ID for the block. For example:

blocks = blocks_for(iseq)
blocks.group_by(&:id)
static VALUE
block_id(VALUE self)
{
    block_t * block;
    TypedData_Get_Struct(self, block_t, &yjit_block_type, block);
    return PTR2NUM(block);
}
iseq_end_index() click to toggle source

Get the end index in the Instruction Sequence that corresponds to this YJIT::Block

static VALUE
iseq_end_index(VALUE self)
{
    block_t * block;
    TypedData_Get_Struct(self, block_t, &yjit_block_type, block);

    return INT2NUM(block->end_idx);
}
iseq_start_index() click to toggle source

Get the start index in the Instruction Sequence that corresponds to this YJIT::Block

static VALUE
iseq_start_index(VALUE self)
{
    block_t * block;
    TypedData_Get_Struct(self, block_t, &yjit_block_type, block);

    return INT2NUM(block->blockid.idx);
}
outgoing_ids → list click to toggle source

Returns a list of outgoing ids for the current block. This list can be used in conjunction with Block#id to construct a graph of block objects.

static VALUE
outgoing_ids(VALUE self)
{
    block_t * block;
    TypedData_Get_Struct(self, block_t, &yjit_block_type, block);

    VALUE ids = rb_ary_new();

    rb_darray_for(block->outgoing, branch_idx) {
        branch_t *out_branch = rb_darray_get(block->outgoing, branch_idx);

        for (size_t succ_idx = 0; succ_idx < 2; succ_idx++) {
            block_t *succ = out_branch->blocks[succ_idx];

            if (succ == NULL)
                continue;

            rb_ary_push(ids, PTR2NUM(succ));
        }

    }

    return ids;
}