1 /**********************************************************************
6 created at: 04/01/01 16:56:59 JST
8 Copyright (C) 2004-2007 Koichi Sasada
10 **********************************************************************/
16 typedef unsigned long lindex_t
;
17 typedef unsigned long dindex_t
;
18 typedef rb_num_t GENTRY
;
19 typedef rb_iseq_t
*ISEQ
;
22 extern VALUE ruby_vm_global_state_version
;
23 extern VALUE ruby_vm_redefined_flag
;
31 * 1: show instruction name
32 * 2: show stack frame when control stack frame is changed
33 * 3: show stack status
49 #ifdef COLLECT_USAGE_ANALYSIS
50 #define USAGE_ANALYSIS_INSN(insn) vm_analysis_insn(insn)
51 #define USAGE_ANALYSIS_OPERAND(insn, n, op) vm_analysis_operand(insn, n, (VALUE)op)
52 #define USAGE_ANALYSIS_REGISTER(reg, s) vm_analysis_register(reg, s)
54 #define USAGE_ANALYSIS_INSN(insn) /* none */
55 #define USAGE_ANALYSIS_OPERAND(insn, n, op) /* none */
56 #define USAGE_ANALYSIS_REGISTER(reg, s) /* none */
60 /* TODO: machine dependent prefetch instruction */
68 #define DEBUG_ENTER_INSN(insn) \
69 debug_print_pre(th, GET_CFP());
72 #define SC_REGS() , reg_a, reg_b
77 #define DEBUG_END_INSN() \
78 debug_print_post(th, GET_CFP() SC_REGS());
83 #define DEBUG_ENTER_INSN(insn)
84 #define DEBUG_END_INSN()
87 #define throwdebug if(0)printf
88 /* #define throwdebug printf */
90 #define SDR2(cfp) vm_stack_dump_raw(GET_THREAD(), (cfp))
93 /************************************************/
96 /************************************************/
97 #elif OPT_CALL_THREADED_CODE
99 #define LABEL(x) insn_func_##x
101 #define LABEL_PTR(x) &LABEL(x)
103 #define INSN_ENTRY(insn) \
104 static rb_control_frame_t * \
105 FUNC_FASTCALL(LABEL(insn))(rb_thread_t *th, rb_control_frame_t *reg_cfp) {
107 #define END_INSN(insn) return reg_cfp;}
109 #define NEXT_INSN() return reg_cfp;
111 /************************************************/
112 #elif OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE
113 /* threaded code with gcc */
115 #define LABEL(x) INSN_LABEL_##x
116 #define ELABEL(x) INSN_ELABEL_##x
117 #define LABEL_PTR(x) &&LABEL(x)
119 #define INSN_ENTRY_SIG(insn)
122 #define INSN_DISPATCH_SIG(insn)
124 #define INSN_ENTRY(insn) \
126 INSN_ENTRY_SIG(insn); \
129 #if __GNUC__ && (__i386__ || __x86_64__) && __GNUC__ == 3
130 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
131 asm volatile("jmp *%0;\t# -- inseted by vm.h\t[length = 2]" : : "r" (addr))
134 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
140 /**********************************/
141 #if OPT_DIRECT_THREADED_CODE
144 #define TC_DISPATCH(insn) \
145 INSN_DISPATCH_SIG(insn); \
146 goto *GET_CURRENT_INSN(); \
150 /* token threade code */
152 #define TC_DISPATCH(insn) \
153 DISPATCH_ARCH_DEPEND_WAY(insns_address_table[GET_CURRENT_INSN()]); \
154 INSN_DISPATCH_SIG(insn); \
155 goto *insns_address_table[GET_CURRENT_INSN()]; \
159 #endif /* DISPATCH_DIRECT_THREADED_CODE */
161 #define END_INSN(insn) \
165 #define INSN_DISPATCH() \
166 TC_DISPATCH(__START__) \
169 #define END_INSNS_DISPATCH() \
170 rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
171 } /* end of while loop */ \
173 #define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__)
175 /************************************************/
176 #else /* no threaded code */
177 /* most common method */
179 #define INSN_ENTRY(insn) \
182 #define END_INSN(insn) \
187 #define INSN_DISPATCH() \
189 switch(GET_CURRENT_INSN()){
191 #define END_INSNS_DISPATCH() \
194 rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
195 } /* end of switch */ \
196 } /* end of while loop */ \
198 #define NEXT_INSN() goto first
203 /************************************************/
204 /************************************************/
206 #define VM_CFP_CNT(th, cfp) \
207 ((rb_control_frame_t *)(th->stack + th->stack_size) - (rb_control_frame_t *)(cfp))
208 #define VM_SP_CNT(th, sp) ((sp) - (th)->stack)
212 env[0] // special (block or prev env)
214 env[2] // prev env val
218 #define ENV_IN_HEAP_P(th, env) \
219 (!((th)->stack < (env) && (env) < ((th)->stack + (th)->stack_size)))
220 #define ENV_VAL(env) ((env)[1])
222 #if OPT_CALL_THREADED_CODE
223 #define THROW_EXCEPTION(exc) do { \
224 th->errinfo = (VALUE)(exc); \
228 #define THROW_EXCEPTION(exc) return (VALUE)(exc)
231 #define SCREG(r) (reg_##r)
233 /* VM state version */
235 #define GET_VM_STATE_VERSION() (ruby_vm_global_state_version)
236 #define INC_VM_STATE_VERSION() \
237 (ruby_vm_global_state_version = (ruby_vm_global_state_version+1) & 0x8fffffff)
239 #define BOP_PLUS 0x01
240 #define BOP_MINUS 0x02
241 #define BOP_MULT 0x04
247 #define BOP_LTLT 0x100
248 #define BOP_AREF 0x200
249 #define BOP_ASET 0x400
250 #define BOP_LENGTH 0x800
251 #define BOP_SUCC 0x1000
252 #define BOP_GT 0x2000
253 #define BOP_GE 0x4000
254 #define BOP_NOT 0x8000
255 #define BOP_NEQ 0x10000
257 #endif /* RUBY_VM_H */