Added comments. Fixed compiler warning.
This commit is contained in:
parent
11512a80fc
commit
d528cf4fd5
@ -1,6 +1,12 @@
|
|||||||
begin
|
begin
|
||||||
require "crabstone"
|
require "crabstone"
|
||||||
require "stringio"
|
require "stringio"
|
||||||
|
rescue LoadError => e
|
||||||
|
puts "Please install crabstone, which is needed by the disassembler:"
|
||||||
|
puts " $ brew install capstone"
|
||||||
|
puts " $ gem install capstone"
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
|
||||||
module UJIT
|
module UJIT
|
||||||
def self.disasm(iseq)
|
def self.disasm(iseq)
|
||||||
@ -27,8 +33,3 @@ module UJIT
|
|||||||
io.string
|
io.string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue
|
|
||||||
puts "Please install crabstone like this:"
|
|
||||||
puts " $ brew install capstone"
|
|
||||||
puts " $ gem install capstone"
|
|
||||||
end
|
|
||||||
|
@ -95,6 +95,8 @@ Returns T_NONE if unknown
|
|||||||
int
|
int
|
||||||
ctx_get_top_type(ctx_t* ctx)
|
ctx_get_top_type(ctx_t* ctx)
|
||||||
{
|
{
|
||||||
|
RUBY_ASSERT(ctx->stack_size > 0);
|
||||||
|
|
||||||
if (ctx->stack_size > MAX_TEMP_TYPES)
|
if (ctx->stack_size > MAX_TEMP_TYPES)
|
||||||
return T_NONE;
|
return T_NONE;
|
||||||
|
|
||||||
|
16
ujit_core.h
16
ujit_core.h
@ -23,7 +23,10 @@
|
|||||||
// Maximum number of temp value types we keep track of
|
// Maximum number of temp value types we keep track of
|
||||||
#define MAX_TEMP_TYPES 8
|
#define MAX_TEMP_TYPES 8
|
||||||
|
|
||||||
// Code generation context
|
/**
|
||||||
|
Code generation context
|
||||||
|
Contains information we can use to optimize code
|
||||||
|
*/
|
||||||
typedef struct CtxStruct
|
typedef struct CtxStruct
|
||||||
{
|
{
|
||||||
// Temporary variable types we keep track of
|
// Temporary variable types we keep track of
|
||||||
@ -64,7 +67,10 @@ enum uint8_t
|
|||||||
// Branch code generation function signature
|
// Branch code generation function signature
|
||||||
typedef void (*branchgen_fn)(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t shape);
|
typedef void (*branchgen_fn)(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t shape);
|
||||||
|
|
||||||
// Store info about an outgoing branch in a code segment
|
/**
|
||||||
|
Store info about an outgoing branch in a code segment
|
||||||
|
Note: care must be taken to minimize the size of branch_t objects
|
||||||
|
*/
|
||||||
typedef struct BranchEntry
|
typedef struct BranchEntry
|
||||||
{
|
{
|
||||||
// Positions where the generated code starts and ends
|
// Positions where the generated code starts and ends
|
||||||
@ -89,7 +95,11 @@ typedef struct BranchEntry
|
|||||||
|
|
||||||
} branch_t;
|
} branch_t;
|
||||||
|
|
||||||
// Basic block version
|
/**
|
||||||
|
Basic block version
|
||||||
|
Represents a portion of an iseq compiled with a given context
|
||||||
|
Note: care must be taken to minimize the size of block_t objects
|
||||||
|
*/
|
||||||
typedef struct BlockVersion
|
typedef struct BlockVersion
|
||||||
{
|
{
|
||||||
// Bytecode sequence (iseq, idx) this is a version of
|
// Bytecode sequence (iseq, idx) this is a version of
|
||||||
|
26
ujit_iface.c
26
ujit_iface.c
@ -253,23 +253,6 @@ rb_ujit_method_lookup_change(VALUE cme_or_cc)
|
|||||||
// Invalidate all regions that depend on the cme or cc
|
// Invalidate all regions that depend on the cme or cc
|
||||||
for (int32_t i = 0; i < array->size; i++) {
|
for (int32_t i = 0; i < array->size; i++) {
|
||||||
block_t* block = array->data[i];
|
block_t* block = array->data[i];
|
||||||
|
|
||||||
/*
|
|
||||||
struct compiled_region *region = &array->data[i];
|
|
||||||
const struct rb_iseq_constant_body *body = region->iseq->body;
|
|
||||||
RUBY_ASSERT((unsigned int)region->start_idx < body->iseq_size);
|
|
||||||
|
|
||||||
// Restore region address to interpreter address in bytecode sequence
|
|
||||||
if (body->iseq_encoded[region->start_idx] == (VALUE)region->code) {
|
|
||||||
const void *const *code_threading_table = rb_vm_get_insns_address_table();
|
|
||||||
int opcode = rb_vm_insn_addr2insn(region->code);
|
|
||||||
body->iseq_encoded[region->start_idx] = (VALUE)code_threading_table[opcode];
|
|
||||||
if (UJIT_DUMP_MODE > 0) {
|
|
||||||
fprintf(stderr, "cc_or_cme=%p now out of date. Restored idx=%u in iseq=%p\n", (void *)cme_or_cc, (unsigned)region->start_idx, (void *)region->iseq);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
invalidate(block);
|
invalidate(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +316,7 @@ ujit_blocks_for(VALUE mod, VALUE rb_iseq)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ujit_insert(VALUE mod, VALUE iseq)
|
ujit_install_entry(VALUE mod, VALUE iseq)
|
||||||
{
|
{
|
||||||
rb_ujit_compile_iseq(rb_iseqw_to_iseq(iseq));
|
rb_ujit_compile_iseq(rb_iseqw_to_iseq(iseq));
|
||||||
return iseq;
|
return iseq;
|
||||||
@ -355,7 +338,10 @@ block_code(VALUE self)
|
|||||||
block_t * block;
|
block_t * block;
|
||||||
TypedData_Get_Struct(self, block_t, &ujit_block_type, block);
|
TypedData_Get_Struct(self, block_t, &ujit_block_type, block);
|
||||||
|
|
||||||
return rb_str_new(cb->mem_block + block->start_pos, block->end_pos - block->start_pos);
|
return (VALUE)rb_str_new(
|
||||||
|
(const char*)cb->mem_block + block->start_pos,
|
||||||
|
block->end_pos - block->start_pos
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the start index in the Instruction Sequence that corresponds to this
|
/* Get the start index in the Instruction Sequence that corresponds to this
|
||||||
@ -394,7 +380,7 @@ rb_ujit_init(void)
|
|||||||
ujit_init_codegen();
|
ujit_init_codegen();
|
||||||
|
|
||||||
VALUE mUjit = rb_define_module("UJIT");
|
VALUE mUjit = rb_define_module("UJIT");
|
||||||
rb_define_module_function(mUjit, "install_entry", ujit_insert, 1);
|
rb_define_module_function(mUjit, "install_entry", ujit_install_entry, 1);
|
||||||
rb_define_module_function(mUjit, "blocks_for", ujit_blocks_for, 1);
|
rb_define_module_function(mUjit, "blocks_for", ujit_blocks_for, 1);
|
||||||
|
|
||||||
cUjitBlock = rb_define_class_under(mUjit, "Block", rb_cObject);
|
cUjitBlock = rb_define_class_under(mUjit, "Block", rb_cObject);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user