13#include "internal/gc.h"
16#include "prism_compile.h"
19#define ISEQ_MAJOR_VERSION ((unsigned int)ruby_api_version[0])
20#define ISEQ_MINOR_VERSION ((unsigned int)ruby_api_version[1])
22#define ISEQ_MBITS_SIZE sizeof(iseq_bits_t)
23#define ISEQ_MBITS_BITLENGTH (ISEQ_MBITS_SIZE * CHAR_BIT)
24#define ISEQ_MBITS_SET(buf, i) (buf[(i) / ISEQ_MBITS_BITLENGTH] |= ((iseq_bits_t)1 << ((i) % ISEQ_MBITS_BITLENGTH)))
25#define ISEQ_MBITS_SET_P(buf, i) ((buf[(i) / ISEQ_MBITS_BITLENGTH] >> ((i) % ISEQ_MBITS_BITLENGTH)) & 0x1)
26#define ISEQ_MBITS_BUFLEN(size) roomof(size, ISEQ_MBITS_BITLENGTH)
28#ifndef USE_ISEQ_NODE_ID
29#define USE_ISEQ_NODE_ID 1
34#define rb_iseq_t rb_iseq_t
36typedef void (*rb_iseq_callback)(
const rb_iseq_t *,
void *);
38extern const ID rb_iseq_shared_exc_local_tbl[];
40#define ISEQ_COVERAGE(iseq) ISEQ_BODY(iseq)->variable.coverage
41#define ISEQ_COVERAGE_SET(iseq, cov) RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->variable.coverage, cov)
42#define ISEQ_LINE_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_LINES)
43#define ISEQ_BRANCH_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_BRANCHES)
45#define ISEQ_PC2BRANCHINDEX(iseq) ISEQ_BODY(iseq)->variable.pc2branchindex
46#define ISEQ_PC2BRANCHINDEX_SET(iseq, h) RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->variable.pc2branchindex, h)
48#define ISEQ_FLIP_CNT(iseq) ISEQ_BODY(iseq)->variable.flip_count
50#define ISEQ_FROZEN_STRING_LITERAL_ENABLED 1
51#define ISEQ_FROZEN_STRING_LITERAL_DISABLED 0
52#define ISEQ_FROZEN_STRING_LITERAL_UNSET -1
54static inline rb_snum_t
55ISEQ_FLIP_CNT_INCREMENT(
const rb_iseq_t *iseq)
57 rb_snum_t cnt = ISEQ_BODY(iseq)->variable.flip_count;
58 ISEQ_BODY(iseq)->variable.flip_count += 1;
63ISEQ_ORIGINAL_ISEQ(
const rb_iseq_t *iseq)
65 return ISEQ_BODY(iseq)->variable.original_iseq;
69ISEQ_ORIGINAL_ISEQ_CLEAR(
const rb_iseq_t *iseq)
71 void *ptr = ISEQ_BODY(iseq)->variable.original_iseq;
72 ISEQ_BODY(iseq)->variable.original_iseq = NULL;
77ISEQ_ORIGINAL_ISEQ_ALLOC(
const rb_iseq_t *iseq,
long size)
79 return ISEQ_BODY(iseq)->variable.original_iseq =
83#define ISEQ_TRACE_EVENTS (RUBY_EVENT_LINE | \
89 RUBY_EVENT_C_RETURN | \
91 RUBY_EVENT_B_RETURN | \
93 RUBY_EVENT_COVERAGE_LINE| \
94 RUBY_EVENT_COVERAGE_BRANCH)
96#define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1
97#define ISEQ_USE_COMPILE_DATA IMEMO_FL_USER2
98#define ISEQ_TRANSLATED IMEMO_FL_USER3
100#define ISEQ_EXECUTABLE_P(iseq) (FL_TEST_RAW(((VALUE)iseq), ISEQ_NOT_LOADED_YET | ISEQ_USE_COMPILE_DATA) == 0)
104 const VALUE err_info;
105 const VALUE catch_table_ary;
111 const rb_iseq_t *current_block;
127 unsigned int ci_index;
128 unsigned int ic_index;
129 const rb_compile_option_t *option;
132 const NODE *root_node;
140ISEQ_COMPILE_DATA(
const rb_iseq_t *iseq)
142 if (iseq->flags & ISEQ_USE_COMPILE_DATA) {
143 return iseq->aux.compile_data;
151ISEQ_COMPILE_DATA_ALLOC(rb_iseq_t *iseq)
154 iseq->flags |= ISEQ_USE_COMPILE_DATA;
158ISEQ_COMPILE_DATA_CLEAR(rb_iseq_t *iseq)
160 iseq->flags &= ~ISEQ_USE_COMPILE_DATA;
161 iseq->aux.compile_data = NULL;
164static inline rb_iseq_t *
165iseq_imemo_alloc(
void)
167 return IMEMO_NEW(rb_iseq_t, imemo_iseq, 0);
170VALUE rb_iseq_ibf_dump(
const rb_iseq_t *iseq,
VALUE opt);
171void rb_ibf_load_iseq_complete(rb_iseq_t *iseq);
172const rb_iseq_t *rb_iseq_ibf_load(
VALUE str);
173const rb_iseq_t *rb_iseq_ibf_load_bytes(
const char *cstr,
size_t);
175void rb_iseq_init_trace(rb_iseq_t *iseq);
176int rb_iseq_add_local_tracepoint_recursively(
const rb_iseq_t *iseq,
rb_event_flag_t turnon_events,
VALUE tpval,
unsigned int target_line,
bool target_bmethod);
177int rb_iseq_remove_local_tracepoint_recursively(
const rb_iseq_t *iseq,
VALUE tpval);
178const rb_iseq_t *rb_iseq_load_iseq(
VALUE fname);
179int rb_iseq_opt_frozen_string_literal(
void);
181#if VM_INSN_INFO_TABLE_IMPL == 2
185int rb_vm_insn_addr2opcode(
const void *addr);
187RUBY_SYMBOL_EXPORT_BEGIN
190VALUE rb_iseq_compile_node(rb_iseq_t *iseq,
const NODE *node);
192VALUE *rb_iseq_original_iseq(
const rb_iseq_t *iseq);
193void rb_iseq_build_from_ary(rb_iseq_t *iseq,
VALUE misc,
199VALUE rb_iseq_parameters(
const rb_iseq_t *iseq,
int is_proc);
200unsigned int rb_iseq_line_no(
const rb_iseq_t *iseq,
size_t pos);
201#ifdef USE_ISEQ_NODE_ID
202int rb_iseq_node_id(
const rb_iseq_t *iseq,
size_t pos);
204void rb_iseq_trace_set(
const rb_iseq_t *iseq,
rb_event_flag_t turnon_events);
206void rb_iseq_insns_info_encode_positions(
const rb_iseq_t *iseq);
209VALUE rb_iseqw_new(
const rb_iseq_t *iseq);
210const rb_iseq_t *rb_iseqw_to_iseq(
VALUE iseqw);
212VALUE rb_iseq_absolute_path(
const rb_iseq_t *iseq);
213int rb_iseq_from_eval_p(
const rb_iseq_t *iseq);
214VALUE rb_iseq_type(
const rb_iseq_t *iseq);
215VALUE rb_iseq_label(
const rb_iseq_t *iseq);
216VALUE rb_iseq_base_label(
const rb_iseq_t *iseq);
217VALUE rb_iseq_first_lineno(
const rb_iseq_t *iseq);
218VALUE rb_iseq_method_name(
const rb_iseq_t *iseq);
219void rb_iseq_code_location(
const rb_iseq_t *iseq,
int *first_lineno,
int *first_column,
int *last_lineno,
int *last_column);
221void rb_iseq_remove_coverage_all(
void);
224const rb_iseq_t *rb_method_iseq(
VALUE body);
225const rb_iseq_t *rb_proc_get_iseq(
VALUE proc,
int *is_proc);
228 unsigned int inline_const_cache: 1;
229 unsigned int peephole_optimization: 1;
230 unsigned int tailcall_optimization: 1;
231 unsigned int specialized_instruction: 1;
232 unsigned int operands_unification: 1;
233 unsigned int instructions_unification: 1;
234 signed int frozen_string_literal: 2;
235 unsigned int debug_frozen_string_literal: 1;
236 unsigned int coverage_enabled: 1;
242#ifdef USE_ISEQ_NODE_ID
261 CATCH_TYPE_RESCUE =
INT2FIX(1),
262 CATCH_TYPE_ENSURE =
INT2FIX(2),
270 enum rb_catch_type type;
279RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN()
283} RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END();
286iseq_catch_table_bytes(
int n)
290 catch_table_entries_max = (INT_MAX - offsetof(
struct iseq_catch_table, entries)) / catch_table_entry_size
292 if (n > catch_table_entries_max) rb_fatal(
"too large iseq_catch_table - %d", n);
294 n * catch_table_entry_size);
297#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
303 char buff[FLEX_ARY_LEN];
329VALUE rb_iseq_defined_string(
enum defined_type
type);
332VALUE rb_iseq_local_variables(
const rb_iseq_t *iseq);
334attr_index_t rb_estimate_iv_count(
VALUE klass,
const rb_iseq_t * initialize_iseq);
336void rb_free_encoded_insn_data(
void);
338RUBY_SYMBOL_EXPORT_END
#define RUBY_EXTERN
Declaration of externally visible global variables.
uint32_t rb_event_flag_t
Represents event(s).
#define INT2FIX
Old name of RB_INT2FIX.
#define ZALLOC
Old name of RB_ZALLOC.
#define ALLOC_N
Old name of RB_ALLOC_N.
const int ruby_api_version[3]
API versions, in { major, minor, teeny } order.
VALUE type(ANYARGS)
ANYARGS-ed function type.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.