Ruby  2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
Data Structures | Macros | Typedefs | Functions | Variables
iseq.c File Reference
#include "internal.h"
#include "ruby/util.h"
#include "eval_intern.h"
#include "gc.h"
#include "vm_core.h"
#include "iseq.h"
#include "id_table.h"
#include "builtin.h"
#include "insns.inc"
#include "insns_info.inc"
#include "mjit.h"
#include "node_name.inc"

Go to the source code of this file.

Data Structures

struct  insn_data_struct
 
struct  trace_set_local_events_struct
 
struct  trace_clear_local_events_struct
 
struct  succ_index_table
 
struct  succ_index_table::succ_dict_block
 

Macros

#define RUBY_VM_INSNS_INFO   1
 
#define hidden_obj_p(obj)   (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
 
#define SET_COMPILE_OPTION(o, h, mem)
 
#define SET_COMPILE_OPTION_NUM(o, h, mem)
 
#define SET_COMPILE_OPTION(o, h, mem)    rb_hash_aset((h), ID2SYM(rb_intern(#mem)), (o)->mem ? Qtrue : Qfalse)
 
#define SET_COMPILE_OPTION_NUM(o, h, mem)    rb_hash_aset((h), ID2SYM(rb_intern(#mem)), INT2NUM((o)->mem))
 
#define CHECK_ARRAY(v)   rb_to_array_type(v)
 
#define CHECK_HASH(v)   rb_to_hash_type(v)
 
#define CHECK_STRING(v)   rb_str_to_str(v)
 
#define CHECK_SYMBOL(v)   rb_to_symbol_type(v)
 
#define INITIALIZED   volatile /* suppress warnings by gcc 4.8 */
 
#define CALL_FLAG(n)   if (ci->flag & VM_CALL_##n) rb_ary_push(flags, rb_str_new2(#n))
 
#define C(ev, cstr, l)   if (events & ev) rb_ary_push(ary, rb_ary_new_from_args(2, l, ID2SYM(rb_intern(cstr))));
 
#define DECL_SYMBOL(name)    static ID sym_##name
 
#define INIT_SYMBOL(name)    sym_##name = rb_intern(#name)
 
#define CHECK_EVENT(ev)   if (events & ev) rb_ary_push(body, ID2SYM(rb_intern(#ev)));
 
#define PARAM_TYPE(type)   rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))
 
#define PARAM_ID(i)   body->local_table[(i)]
 
#define PARAM(i, type)
 
#define INSN_CODE(insn)   ((VALUE)table[insn])
 
#define IMMEDIATE_TABLE_SIZE   54 /* a multiple of 9, and < 128 */
 
#define imm_block_rank_set(v, i, r)   (v) |= (uint64_t)(r) << (7 * (i))
 
#define imm_block_rank_get(v, i)   (((int)((v) >> ((i) * 7))) & 0x7f)
 
#define small_block_rank_set(v, i, r)   (v) |= (uint64_t)(r) << (9 * ((i) - 1))
 
#define small_block_rank_get(v, i)   ((i) == 0 ? 0 : (((int)((v) >> (((i) - 1) * 9))) & 0x1ff))
 

Typedefs

typedef VALUE iseq_value_itr_t(void *ctx, VALUE obj)
 
typedef VALUE rb_vm_insns_translator_t(const void *addr)
 
typedef struct insn_data_struct insn_data_t
 

Functions

void rb_iseq_free (const rb_iseq_t *iseq)
 
void rb_iseq_update_references (rb_iseq_t *iseq)
 
void rb_iseq_mark (const rb_iseq_t *iseq)
 
size_t rb_iseq_memsize (const rb_iseq_t *iseq)
 
struct rb_iseq_constant_bodyrb_iseq_constant_body_alloc (void)
 
VALUE rb_iseq_pathobj_new (VALUE path, VALUE realpath)
 
void rb_iseq_pathobj_set (const rb_iseq_t *iseq, VALUE path, VALUE realpath)
 
void rb_iseq_insns_info_encode_positions (const rb_iseq_t *iseq)
 
unsigned intrb_iseq_insns_info_decode_positions (const struct rb_iseq_constant_body *body)
 
void rb_iseq_init_trace (rb_iseq_t *iseq)
 
rb_iseq_trb_iseq_new (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type type)
 
rb_iseq_trb_iseq_new_top (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
 
rb_iseq_trb_iseq_new_main (const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent)
 
rb_iseq_trb_iseq_new_with_opt (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type type, const rb_compile_option_t *option)
 
rb_iseq_trb_iseq_new_with_callback (const struct rb_iseq_new_with_callback_callback_func *ifunc, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type type, const rb_compile_option_t *option)
 
const rb_iseq_trb_iseq_load_iseq (VALUE fname)
 
VALUE rb_iseq_load (VALUE data, VALUE parent, VALUE opt)
 
VALUE rb_iseq_path (const rb_iseq_t *iseq)
 
VALUE rb_iseq_realpath (const rb_iseq_t *iseq)
 
VALUE rb_iseq_absolute_path (const rb_iseq_t *iseq)
 
VALUE rb_iseq_label (const rb_iseq_t *iseq)
 
VALUE rb_iseq_base_label (const rb_iseq_t *iseq)
 
VALUE rb_iseq_first_lineno (const rb_iseq_t *iseq)
 
VALUE rb_iseq_method_name (const rb_iseq_t *iseq)
 
void rb_iseq_code_location (const rb_iseq_t *iseq, int *beg_pos_lineno, int *beg_pos_column, int *end_pos_lineno, int *end_pos_column)
 
VALUE rb_iseq_coverage (const rb_iseq_t *iseq)
 
void rb_iseq_remove_coverage_all (void)
 
VALUE rb_iseqw_new (const rb_iseq_t *iseq)
 
const rb_iseq_trb_iseqw_to_iseq (VALUE iseqw)
 
unsigned int rb_iseq_line_no (const rb_iseq_t *iseq, size_t pos)
 
MJIT_FUNC_EXPORTED rb_event_flag_t rb_iseq_event_flags (const rb_iseq_t *iseq, size_t pos)
 
void rb_iseq_clear_event_flags (const rb_iseq_t *iseq, size_t pos, rb_event_flag_t reset)
 
int rb_insn_unified_local_var_level (VALUE)
 
VALUE rb_insn_operand_intern (const rb_iseq_t *iseq, VALUE insn, int op_no, VALUE op, int len, size_t pos, const VALUE *pnop, VALUE child)
 
int rb_iseq_disasm_insn (VALUE ret, const VALUE *code, size_t pos, const rb_iseq_t *iseq, VALUE child)
 Disassemble a instruction Iseq -> Iseq inspect object. More...
 
VALUE rb_iseq_disasm (const rb_iseq_t *iseq)
 
const charruby_node_name (int node)
 
VALUE rb_iseq_parameters (const rb_iseq_t *iseq, int is_proc)
 
VALUE rb_iseq_defined_string (enum defined_type type)
 
void rb_vm_encoded_insn_data_table_init (void)
 
int rb_vm_insn_addr2insn (const void *addr)
 
void rb_iseq_trace_flag_cleared (const rb_iseq_t *iseq, size_t pos)
 
int rb_iseq_add_local_tracepoint_recursively (const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line)
 
int rb_iseq_remove_local_tracepoint_recursively (const rb_iseq_t *iseq, VALUE tpval)
 
void rb_iseq_trace_set (const rb_iseq_t *iseq, rb_event_flag_t turnon_events)
 
void rb_iseq_trace_set_all (rb_event_flag_t turnon_events)
 
VALUE rb_iseqw_local_variables (VALUE iseqval)
 
void Init_ISeq (void)
 

Variables

VALUE rb_cISeq
 

Macro Definition Documentation

◆ C

#define C (   ev,
  cstr,
 
)    if (events & ev) rb_ary_push(ary, rb_ary_new_from_args(2, l, ID2SYM(rb_intern(cstr))));

◆ CALL_FLAG

#define CALL_FLAG (   n)    if (ci->flag & VM_CALL_##n) rb_ary_push(flags, rb_str_new2(#n))

◆ CHECK_ARRAY

#define CHECK_ARRAY (   v)    rb_to_array_type(v)

Definition at line 858 of file iseq.c.

◆ CHECK_EVENT

#define CHECK_EVENT (   ev)    if (events & ev) rb_ary_push(body, ID2SYM(rb_intern(#ev)));

◆ CHECK_HASH

#define CHECK_HASH (   v)    rb_to_hash_type(v)

Definition at line 859 of file iseq.c.

◆ CHECK_STRING

#define CHECK_STRING (   v)    rb_str_to_str(v)

Definition at line 860 of file iseq.c.

◆ CHECK_SYMBOL

#define CHECK_SYMBOL (   v)    rb_to_symbol_type(v)

Definition at line 861 of file iseq.c.

◆ DECL_SYMBOL

#define DECL_SYMBOL (   name)     static ID sym_##name

Definition at line 2544 of file iseq.c.

◆ hidden_obj_p

#define hidden_obj_p (   obj)    (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)

Definition at line 42 of file iseq.c.

◆ imm_block_rank_get

#define imm_block_rank_get (   v,
  i 
)    (((int)((v) >> ((i) * 7))) & 0x7f)

Definition at line 3430 of file iseq.c.

◆ imm_block_rank_set

#define imm_block_rank_set (   v,
  i,
 
)    (v) |= (uint64_t)(r) << (7 * (i))

Definition at line 3429 of file iseq.c.

◆ IMMEDIATE_TABLE_SIZE

#define IMMEDIATE_TABLE_SIZE   54 /* a multiple of 9, and < 128 */

Definition at line 3418 of file iseq.c.

◆ INIT_SYMBOL

#define INIT_SYMBOL (   name)     sym_##name = rb_intern(#name)

Definition at line 2547 of file iseq.c.

◆ INITIALIZED

#define INITIALIZED   volatile /* suppress warnings by gcc 4.8 */

◆ INSN_CODE

#define INSN_CODE (   insn)    ((VALUE)table[insn])

◆ PARAM

#define PARAM (   i,
  type 
)
Value:
( \
PARAM_TYPE(type), \
rb_id2str(PARAM_ID(i)) ? \
rb_ary_push(a, ID2SYM(PARAM_ID(i))) : \
a)

◆ PARAM_ID

#define PARAM_ID (   i)    body->local_table[(i)]

◆ PARAM_TYPE

#define PARAM_TYPE (   type)    rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))

◆ RUBY_VM_INSNS_INFO

#define RUBY_VM_INSNS_INFO   1

Definition at line 20 of file iseq.c.

◆ SET_COMPILE_OPTION [1/2]

#define SET_COMPILE_OPTION (   o,
  h,
  mem 
)
Value:
{ VALUE flag = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \
if (flag == Qtrue) { (o)->mem = 1; } \
else if (flag == Qfalse) { (o)->mem = 0; } \
}

◆ SET_COMPILE_OPTION [2/2]

#define SET_COMPILE_OPTION (   o,
  h,
  mem 
)     rb_hash_aset((h), ID2SYM(rb_intern(#mem)), (o)->mem ? Qtrue : Qfalse)

◆ SET_COMPILE_OPTION_NUM [1/2]

#define SET_COMPILE_OPTION_NUM (   o,
  h,
  mem 
)
Value:
{ VALUE num = rb_hash_aref(opt, ID2SYM(rb_intern(#mem))); \
if (!NIL_P(num)) (o)->mem = NUM2INT(num); \
}

◆ SET_COMPILE_OPTION_NUM [2/2]

#define SET_COMPILE_OPTION_NUM (   o,
  h,
  mem 
)     rb_hash_aset((h), ID2SYM(rb_intern(#mem)), INT2NUM((o)->mem))

◆ small_block_rank_get

#define small_block_rank_get (   v,
  i 
)    ((i) == 0 ? 0 : (((int)((v) >> (((i) - 1) * 9))) & 0x1ff))

Definition at line 3432 of file iseq.c.

◆ small_block_rank_set

#define small_block_rank_set (   v,
  i,
 
)    (v) |= (uint64_t)(r) << (9 * ((i) - 1))

Definition at line 3431 of file iseq.c.

Typedef Documentation

◆ insn_data_t

typedef struct insn_data_struct insn_data_t

◆ iseq_value_itr_t

typedef VALUE iseq_value_itr_t(void *ctx, VALUE obj)

Definition at line 147 of file iseq.c.

◆ rb_vm_insns_translator_t

typedef VALUE rb_vm_insns_translator_t(const void *addr)

Definition at line 148 of file iseq.c.

Function Documentation

◆ Init_ISeq()

void Init_ISeq ( void  )

◆ rb_insn_operand_intern()

VALUE rb_insn_operand_intern ( const rb_iseq_t iseq,
VALUE  insn,
int  op_no,
VALUE  op,
int  len,
size_t  pos,
const VALUE pnop,
VALUE  child 
)

◆ rb_insn_unified_local_var_level()

int rb_insn_unified_local_var_level ( VALUE  )

◆ rb_iseq_absolute_path()

VALUE rb_iseq_absolute_path ( const rb_iseq_t iseq)

Definition at line 1039 of file iseq.c.

References iseq, and rb_iseq_realpath().

◆ rb_iseq_add_local_tracepoint_recursively()

int rb_iseq_add_local_tracepoint_recursively ( const rb_iseq_t iseq,
rb_event_flag_t  turnon_events,
VALUE  tpval,
unsigned int  target_line 
)

◆ rb_iseq_base_label()

VALUE rb_iseq_base_label ( const rb_iseq_t iseq)

◆ rb_iseq_clear_event_flags()

void rb_iseq_clear_event_flags ( const rb_iseq_t iseq,
size_t  pos,
rb_event_flag_t  reset 
)

Definition at line 1786 of file iseq.c.

◆ rb_iseq_code_location()

void rb_iseq_code_location ( const rb_iseq_t iseq,
int beg_pos_lineno,
int beg_pos_column,
int end_pos_lineno,
int end_pos_column 
)

◆ rb_iseq_constant_body_alloc()

struct rb_iseq_constant_body* rb_iseq_constant_body_alloc ( void  )

Definition at line 433 of file iseq.c.

References rb_iseq_constant_body::iseq_unique_id, and ZALLOC.

◆ rb_iseq_coverage()

VALUE rb_iseq_coverage ( const rb_iseq_t iseq)

Definition at line 1086 of file iseq.c.

References iseq, and ISEQ_COVERAGE.

◆ rb_iseq_defined_string()

VALUE rb_iseq_defined_string ( enum defined_type  type)

◆ rb_iseq_disasm()

VALUE rb_iseq_disasm ( const rb_iseq_t iseq)

Definition at line 2278 of file iseq.c.

◆ rb_iseq_disasm_insn()

int rb_iseq_disasm_insn ( VALUE  ret,
const VALUE code,
size_t  pos,
const rb_iseq_t iseq,
VALUE  child 
)

◆ rb_iseq_event_flags()

MJIT_FUNC_EXPORTED rb_event_flag_t rb_iseq_event_flags ( const rb_iseq_t iseq,
size_t  pos 
)

Definition at line 1774 of file iseq.c.

Referenced by rb_iseq_disasm_insn(), and rb_iseq_trace_set().

◆ rb_iseq_first_lineno()

VALUE rb_iseq_first_lineno ( const rb_iseq_t iseq)

◆ rb_iseq_free()

void rb_iseq_free ( const rb_iseq_t iseq)

◆ rb_iseq_init_trace()

void rb_iseq_init_trace ( rb_iseq_t iseq)

◆ rb_iseq_insns_info_decode_positions()

unsigned int* rb_iseq_insns_info_decode_positions ( const struct rb_iseq_constant_body body)

◆ rb_iseq_insns_info_encode_positions()

void rb_iseq_insns_info_encode_positions ( const rb_iseq_t iseq)

◆ rb_iseq_label()

VALUE rb_iseq_label ( const rb_iseq_t iseq)

◆ rb_iseq_line_no()

unsigned int rb_iseq_line_no ( const rb_iseq_t iseq,
size_t  pos 
)

Definition at line 1761 of file iseq.c.

Referenced by rb_iseq_disasm_insn().

◆ rb_iseq_load()

VALUE rb_iseq_load ( VALUE  data,
VALUE  parent,
VALUE  opt 
)

Definition at line 972 of file iseq.c.

◆ rb_iseq_load_iseq()

const rb_iseq_t* rb_iseq_load_iseq ( VALUE  fname)

Definition at line 847 of file iseq.c.

References rb_check_funcall(), rb_cISeq, rb_intern, RBASIC_CLASS, and SPECIAL_CONST_P.

◆ rb_iseq_mark()

void rb_iseq_mark ( const rb_iseq_t iseq)

◆ rb_iseq_memsize()

size_t rb_iseq_memsize ( const rb_iseq_t iseq)

◆ rb_iseq_method_name()

VALUE rb_iseq_method_name ( const rb_iseq_t iseq)

◆ rb_iseq_new()

rb_iseq_t* rb_iseq_new ( const rb_ast_body_t ast,
VALUE  name,
VALUE  path,
VALUE  realpath,
const rb_iseq_t parent,
enum iseq_type  type 
)

Definition at line 761 of file iseq.c.

References INT2FIX, name, path, rb_iseq_new_with_opt(), and realpath().

Referenced by rb_vm_call_cfunc().

◆ rb_iseq_new_main()

rb_iseq_t* rb_iseq_new_main ( const rb_ast_body_t ast,
VALUE  path,
VALUE  realpath,
const rb_iseq_t parent 
)

◆ rb_iseq_new_top()

rb_iseq_t* rb_iseq_new_top ( const rb_ast_body_t ast,
VALUE  name,
VALUE  path,
VALUE  realpath,
const rb_iseq_t parent 
)

◆ rb_iseq_new_with_callback()

rb_iseq_t* rb_iseq_new_with_callback ( const struct rb_iseq_new_with_callback_callback_func ifunc,
VALUE  name,
VALUE  path,
VALUE  realpath,
VALUE  first_lineno,
const rb_iseq_t parent,
enum iseq_type  type,
const rb_compile_option_t option 
)

Definition at line 828 of file iseq.c.

References iseq, and iseq_alloc().

◆ rb_iseq_new_with_opt()

rb_iseq_t* rb_iseq_new_with_opt ( const rb_ast_body_t ast,
VALUE  name,
VALUE  path,
VALUE  realpath,
VALUE  first_lineno,
const rb_iseq_t parent,
enum iseq_type  type,
const rb_compile_option_t option 
)

Definition at line 807 of file iseq.c.

References iseq, iseq_alloc(), and rb_ast_body_struct::root.

Referenced by rb_iseq_new(), rb_iseq_new_main(), and rb_iseq_new_top().

◆ rb_iseq_parameters()

VALUE rb_iseq_parameters ( const rb_iseq_t iseq,
int  is_proc 
)

◆ rb_iseq_path()

VALUE rb_iseq_path ( const rb_iseq_t iseq)

Definition at line 1027 of file iseq.c.

Referenced by rb_resolve_me_location(), and rb_sourcefile().

◆ rb_iseq_pathobj_new()

VALUE rb_iseq_pathobj_new ( VALUE  path,
VALUE  realpath 
)

◆ rb_iseq_pathobj_set()

void rb_iseq_pathobj_set ( const rb_iseq_t iseq,
VALUE  path,
VALUE  realpath 
)

◆ rb_iseq_realpath()

VALUE rb_iseq_realpath ( const rb_iseq_t iseq)

Definition at line 1033 of file iseq.c.

Referenced by rb_iseq_absolute_path(), and rb_vm_set_progname().

◆ rb_iseq_remove_coverage_all()

void rb_iseq_remove_coverage_all ( void  )

Definition at line 1110 of file iseq.c.

References rb_objspace_each_objects().

Referenced by rb_reset_coverages().

◆ rb_iseq_remove_local_tracepoint_recursively()

int rb_iseq_remove_local_tracepoint_recursively ( const rb_iseq_t iseq,
VALUE  tpval 
)

◆ rb_iseq_trace_flag_cleared()

void rb_iseq_trace_flag_cleared ( const rb_iseq_t iseq,
size_t  pos 
)

Definition at line 3144 of file iseq.c.

References rb_iseq_struct::body, iseq, and rb_iseq_constant_body::iseq_encoded.

◆ rb_iseq_trace_set()

void rb_iseq_trace_set ( const rb_iseq_t iseq,
rb_event_flag_t  turnon_events 
)

◆ rb_iseq_trace_set_all()

void rb_iseq_trace_set_all ( rb_event_flag_t  turnon_events)

Definition at line 3319 of file iseq.c.

References rb_objspace_each_objects().

◆ rb_iseq_update_references()

void rb_iseq_update_references ( rb_iseq_t iseq)

◆ rb_iseqw_to_iseq()

const rb_iseq_t* rb_iseqw_to_iseq ( VALUE  iseqw)

Definition at line 1350 of file iseq.c.

◆ rb_vm_encoded_insn_data_table_init()

void rb_vm_encoded_insn_data_table_init ( void  )

Definition at line 3085 of file iseq.c.

References rb_vm_get_insns_address_table().

Referenced by ruby_setup().

◆ rb_vm_insn_addr2insn()

int rb_vm_insn_addr2insn ( const void addr)

Definition at line 3115 of file iseq.c.

References key, st_data_t, and st_lookup().

◆ ruby_node_name()

const char* ruby_node_name ( int  node)

Definition at line 2534 of file iseq.c.

References rb_bug().

Referenced by ruby_debug_print_node().

Variable Documentation

◆ rb_cISeq

VALUE rb_cISeq

Definition at line 32 of file iseq.c.

Referenced by Init_ISeq(), and rb_iseq_load_iseq().

i
uint32_t i
Definition: rb_mjit_min_header-2.7.2.h:5460
rb_hash_aref
VALUE rb_hash_aref(VALUE hash, VALUE key)
Definition: hash.c:2037
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_intern
#define rb_intern(str)
Qfalse
#define Qfalse
Definition: ruby.h:467
ID2SYM
#define ID2SYM(x)
Definition: ruby.h:414
PARAM_ID
#define PARAM_ID(i)
h
size_t st_index_t h
Definition: rb_mjit_min_header-2.7.2.h:5458
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
Qtrue
#define Qtrue
Definition: ruby.h:468
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39