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

Added comments. Fixed compiler warning.

This commit is contained in:
Maxime Chevalier-Boisvert 2021-01-22 12:22:34 -05:00 committed by Alan Wu
parent 11512a80fc
commit d528cf4fd5
4 changed files with 29 additions and 30 deletions

View file

@ -1,6 +1,12 @@
begin
require "crabstone"
require "stringio"
require "crabstone"
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
def self.disasm(iseq)
@ -27,8 +33,3 @@ module UJIT
io.string
end
end
rescue
puts "Please install crabstone like this:"
puts " $ brew install capstone"
puts " $ gem install capstone"
end

View file

@ -95,6 +95,8 @@ Returns T_NONE if unknown
int
ctx_get_top_type(ctx_t* ctx)
{
RUBY_ASSERT(ctx->stack_size > 0);
if (ctx->stack_size > MAX_TEMP_TYPES)
return T_NONE;

View file

@ -23,7 +23,10 @@
// Maximum number of temp value types we keep track of
#define MAX_TEMP_TYPES 8
// Code generation context
/**
Code generation context
Contains information we can use to optimize code
*/
typedef struct CtxStruct
{
// Temporary variable types we keep track of
@ -64,7 +67,10 @@ enum uint8_t
// Branch code generation function signature
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
{
// Positions where the generated code starts and ends
@ -89,7 +95,11 @@ typedef struct BranchEntry
} 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
{
// Bytecode sequence (iseq, idx) this is a version of

View file

@ -253,23 +253,6 @@ rb_ujit_method_lookup_change(VALUE cme_or_cc)
// Invalidate all regions that depend on the cme or cc
for (int32_t i = 0; i < array->size; 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);
}
@ -333,7 +316,7 @@ ujit_blocks_for(VALUE mod, VALUE rb_iseq)
}
static VALUE
ujit_insert(VALUE mod, VALUE iseq)
ujit_install_entry(VALUE mod, VALUE iseq)
{
rb_ujit_compile_iseq(rb_iseqw_to_iseq(iseq));
return iseq;
@ -355,7 +338,10 @@ block_code(VALUE self)
block_t * 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
@ -394,7 +380,7 @@ rb_ujit_init(void)
ujit_init_codegen();
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);
cUjitBlock = rb_define_class_under(mUjit, "Block", rb_cObject);