Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

vm_exec.h
Go to the documentation of this file.
1 /**********************************************************************
2
3 vm.h -
4
5 $Author$
6 created at: 04/01/01 16:56:59 JST
7
8 Copyright (C) 2004-2007 Koichi Sasada
9
10 **********************************************************************/
11
12 #ifndef RUBY_VM_EXEC_H
13 #define RUBY_VM_EXEC_H
14
15 typedef long OFFSET;
16 typedef unsigned long lindex_t;
17 typedef VALUE GENTRY;
18 typedef rb_iseq_t *ISEQ;
19
20 #if VMDEBUG > 0
21 #define debugs printf
22 #define DEBUG_ENTER_INSN(insn) \
23 rb_vmdebug_debug_print_pre(ec, GET_CFP(), GET_PC());
24
25 #if OPT_STACK_CACHING
26 #define SC_REGS() , reg_a, reg_b
27 #else
28 #define SC_REGS()
29 #endif
30
31 #define DEBUG_END_INSN() \
32 rb_vmdebug_debug_print_post(ec, GET_CFP() SC_REGS());
33
34 #else
35
36 #define debugs
37 #define DEBUG_ENTER_INSN(insn)
38 #define DEBUG_END_INSN()
39 #endif
40
41 #define throwdebug if(0)printf
42 /* #define throwdebug printf */
43
44 /************************************************/
45 #if defined(DISPATCH_XXX)
46 error !
47 /************************************************/
48 #elif OPT_CALL_THREADED_CODE
49
50 #define LABEL(x) insn_func_##x
51 #define ELABEL(x)
52 #define LABEL_PTR(x) &LABEL(x)
53
54 #define INSN_ENTRY(insn) \
55 static rb_control_frame_t * \
56 FUNC_FASTCALL(LABEL(insn))(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp) {
57
58 #define END_INSN(insn) return reg_cfp;}
59
60 #define NEXT_INSN() return reg_cfp;
61
62 #define START_OF_ORIGINAL_INSN(x) /* ignore */
63 #define DISPATCH_ORIGINAL_INSN(x) return LABEL(x)(ec, reg_cfp);
64
65 /************************************************/
66 #elif OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE
67 /* threaded code with gcc */
68
69 #define LABEL(x) INSN_LABEL_##x
70 #define ELABEL(x) INSN_ELABEL_##x
71 #define LABEL_PTR(x) RB_GNUC_EXTENSION(&&LABEL(x))
72
73 #define INSN_ENTRY_SIG(insn) \
74 if (0) fprintf(stderr, "exec: %s@(%"PRIdPTRDIFF", %"PRIdPTRDIFF")@%s:%u\n", #insn, \
75 (reg_pc - reg_cfp->iseq->body->iseq_encoded), \
76 (reg_cfp->pc - reg_cfp->iseq->body->iseq_encoded), \
77 RSTRING_PTR(rb_iseq_path(reg_cfp->iseq)), \
78 rb_iseq_line_no(reg_cfp->iseq, reg_pc - reg_cfp->iseq->body->iseq_encoded));
79
80 #define INSN_DISPATCH_SIG(insn)
81
82 #define INSN_ENTRY(insn) \
83 LABEL(insn): \
84 INSN_ENTRY_SIG(insn); \
85
86 /**********************************/
87 #if OPT_DIRECT_THREADED_CODE
88
89 /* for GCC 3.4.x */
90 #define TC_DISPATCH(insn) \
91 INSN_DISPATCH_SIG(insn); \
92 RB_GNUC_EXTENSION_BLOCK(goto *(void const *)GET_CURRENT_INSN()); \
93 ;
94
95 #else
96 /* token threaded code */
97
98 /* dispatcher */
99 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && __GNUC__ == 3
100 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
101 __asm__ __volatile__("jmp *%0;\t# -- inserted by vm.h\t[length = 2]" : : "r" (addr))
102
103 #else
104 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
105 /* do nothing */
106 #endif
107 #define TC_DISPATCH(insn) \
108 DISPATCH_ARCH_DEPEND_WAY(insns_address_table[GET_CURRENT_INSN()]); \
109 INSN_DISPATCH_SIG(insn); \
110 RB_GNUC_EXTENSION_BLOCK(goto *insns_address_table[GET_CURRENT_INSN()]); \
111 rb_bug("tc error");
112
113 #endif /* OPT_DIRECT_THREADED_CODE */
114
115 #define END_INSN(insn) \
116 DEBUG_END_INSN(); \
117 TC_DISPATCH(insn);
118
119 #define INSN_DISPATCH() \
120 TC_DISPATCH(__START__) \
121 {
122
123 #define END_INSNS_DISPATCH() \
124 rb_bug("unknown insn: %"PRIdVALUE, GET_CURRENT_INSN()); \
125 } /* end of while loop */ \
126
127 #define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__)
128
129 #define START_OF_ORIGINAL_INSN(x) start_of_##x:
130 #define DISPATCH_ORIGINAL_INSN(x) goto start_of_##x;
131
132 /************************************************/
133 #else /* no threaded code */
134 /* most common method */
135
136 #define INSN_ENTRY(insn) \
137 case BIN(insn):
138
139 #define END_INSN(insn) \
140 DEBUG_END_INSN(); \
141 break;
142
143 #define INSN_DISPATCH() \
144 while (1) { \
145 switch (GET_CURRENT_INSN()) {
146
147 #define END_INSNS_DISPATCH() \
148 default: \
149 SDR(); \
150 rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
151 } /* end of switch */ \
152 } /* end of while loop */ \
153
154 #define NEXT_INSN() goto first
155
156 #define START_OF_ORIGINAL_INSN(x) start_of_##x:
157 #define DISPATCH_ORIGINAL_INSN(x) goto start_of_##x;
158
159 #endif
160
161 #define VM_SP_CNT(ec, sp) ((sp) - (ec)->vm_stack)
162
163 #ifdef MJIT_HEADER
164 #define THROW_EXCEPTION(exc) do { \
165 ec->errinfo = (VALUE)(exc); \
166 EC_JUMP_TAG(ec, ec->tag->state); \
167 } while (0)
168 #else
169 #if OPT_CALL_THREADED_CODE
170 #define THROW_EXCEPTION(exc) do { \
171 ec->errinfo = (VALUE)(exc); \
172 return 0; \
173 } while (0)
174 #else
175 #define THROW_EXCEPTION(exc) return (VALUE)(exc)
176 #endif
177 #endif
178
179 #define SCREG(r) (reg_##r)
180
181 #define VM_DEBUG_STACKOVERFLOW 0
182
183 #if VM_DEBUG_STACKOVERFLOW
184 #define CHECK_VM_STACK_OVERFLOW_FOR_INSN(cfp, margin) \
185 WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stack_overflow_for_insn()
186 #else
187 #define CHECK_VM_STACK_OVERFLOW_FOR_INSN(cfp, margin)
188 #endif
189
190 #define INSN_LABEL2(insn, name) INSN_LABEL_ ## insn ## _ ## name
191 #define INSN_LABEL(x) INSN_LABEL2(NAME_OF_CURRENT_INSN, x)
192
193 #endif /* RUBY_VM_EXEC_H */
rb_iseq_struct
Definition: vm_core.h:456
VALUE
unsigned long VALUE
Definition: ruby.h:102
ISEQ
rb_iseq_t * ISEQ
Definition: vm_exec.h:18
OFFSET
long OFFSET
Definition: vm_exec.h:15
error
const rb_iseq_t const char * error
Definition: rb_mjit_min_header-2.7.0.h:13506
lindex_t
unsigned long lindex_t
Definition: vm_exec.h:16
GENTRY
VALUE GENTRY
Definition: vm_exec.h:17