3 /**********************************************************************
8 created at: 04/01/01 16:56:59 JST
10 Copyright (C) 2004-2007 Koichi Sasada
12 **********************************************************************/
15 typedef unsigned long lindex_t
;
17 typedef rb_iseq_t
*ISEQ
;
21 #define DEBUG_ENTER_INSN(insn) \
22 rb_vmdebug_debug_print_pre(ec, GET_CFP(), GET_PC());
25 #define SC_REGS() , reg_a, reg_b
30 #define DEBUG_END_INSN() \
31 rb_vmdebug_debug_print_post(ec, GET_CFP() SC_REGS());
36 #define DEBUG_ENTER_INSN(insn)
37 #define DEBUG_END_INSN()
40 #define throwdebug if(0)ruby_debug_printf
41 /* #define throwdebug ruby_debug_printf */
43 #ifndef USE_INSNS_COUNTER
44 #define USE_INSNS_COUNTER 0
47 /************************************************/
48 #if defined(DISPATCH_XXX)
50 /************************************************/
51 #elif OPT_CALL_THREADED_CODE
53 #define LABEL(x) insn_func_##x
55 #define LABEL_PTR(x) &LABEL(x)
57 #define INSN_ENTRY(insn) \
58 static rb_control_frame_t * \
59 FUNC_FASTCALL(LABEL(insn))(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp) {
61 #define END_INSN(insn) return reg_cfp;}
63 #define NEXT_INSN() return reg_cfp;
65 #define START_OF_ORIGINAL_INSN(x) /* ignore */
66 #define DISPATCH_ORIGINAL_INSN(x) return LABEL(x)(ec, reg_cfp);
68 /************************************************/
69 #elif OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE
70 /* threaded code with gcc */
72 #define LABEL(x) INSN_LABEL_##x
73 #define ELABEL(x) INSN_ELABEL_##x
74 #define LABEL_PTR(x) RB_GNUC_EXTENSION(&&LABEL(x))
76 #define INSN_ENTRY_SIG(insn) \
78 ruby_debug_printf("exec: %s@(%"PRIdPTRDIFF", %"PRIdPTRDIFF")@%s:%u\n", #insn, \
79 (reg_pc - reg_cfp->iseq->body->iseq_encoded), \
80 (reg_cfp->pc - reg_cfp->iseq->body->iseq_encoded), \
81 RSTRING_PTR(rb_iseq_path(reg_cfp->iseq)), \
82 rb_iseq_line_no(reg_cfp->iseq, reg_pc - reg_cfp->iseq->body->iseq_encoded)); \
84 if (USE_INSNS_COUNTER) vm_insns_counter_count_insn(BIN(insn));
86 #define INSN_DISPATCH_SIG(insn)
88 #define INSN_ENTRY(insn) \
90 INSN_ENTRY_SIG(insn); \
92 /**********************************/
93 #if OPT_DIRECT_THREADED_CODE
96 #define TC_DISPATCH(insn) \
97 INSN_DISPATCH_SIG(insn); \
98 RB_GNUC_EXTENSION_BLOCK(goto *(void const *)GET_CURRENT_INSN()); \
102 /* token threaded code */
105 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && __GNUC__ == 3
106 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
107 __asm__ __volatile__("jmp *%0;\t# -- inserted by vm.h\t[length = 2]" : : "r" (addr))
110 #define DISPATCH_ARCH_DEPEND_WAY(addr) \
113 #define TC_DISPATCH(insn) \
114 DISPATCH_ARCH_DEPEND_WAY(insns_address_table[GET_CURRENT_INSN()]); \
115 INSN_DISPATCH_SIG(insn); \
116 RB_GNUC_EXTENSION_BLOCK(goto *insns_address_table[GET_CURRENT_INSN()]); \
119 #endif /* OPT_DIRECT_THREADED_CODE */
121 #define END_INSN(insn) \
125 #define INSN_DISPATCH() \
126 TC_DISPATCH(__START__) \
129 #define END_INSNS_DISPATCH() \
130 rb_bug("unknown insn: %"PRIdVALUE, GET_CURRENT_INSN()); \
131 } /* end of while loop */ \
133 #define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__)
135 /************************************************/
136 #else /* no threaded code */
137 /* most common method */
139 #define INSN_ENTRY(insn) \
142 #define END_INSN(insn) \
146 #define INSN_DISPATCH() \
148 switch (GET_CURRENT_INSN()) {
150 #define END_INSNS_DISPATCH() \
153 rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
154 } /* end of switch */ \
155 } /* end of while loop */ \
157 #define NEXT_INSN() goto first
161 #ifndef START_OF_ORIGINAL_INSN
162 #define START_OF_ORIGINAL_INSN(x) if (0) goto start_of_##x; start_of_##x:
163 #define DISPATCH_ORIGINAL_INSN(x) goto start_of_##x;
166 #define VM_SP_CNT(ec, sp) ((sp) - (ec)->vm_stack)
169 #define THROW_EXCEPTION(exc) do { \
170 ec->errinfo = (VALUE)(exc); \
171 EC_JUMP_TAG(ec, ec->tag->state); \
174 #if OPT_CALL_THREADED_CODE
175 #define THROW_EXCEPTION(exc) do { \
176 ec->errinfo = (VALUE)(exc); \
180 #define THROW_EXCEPTION(exc) return (VALUE)(exc)
184 #define SCREG(r) (reg_##r)
186 #define VM_DEBUG_STACKOVERFLOW 0
188 #if VM_DEBUG_STACKOVERFLOW
189 #define CHECK_VM_STACK_OVERFLOW_FOR_INSN CHECK_VM_STACK_OVERFLOW
191 #define CHECK_VM_STACK_OVERFLOW_FOR_INSN(cfp, margin)
194 #define INSN_LABEL2(insn, name) INSN_LABEL_ ## insn ## _ ## name
195 #define INSN_LABEL(x) INSN_LABEL2(NAME_OF_CURRENT_INSN, x)
197 #endif /* RUBY_VM_EXEC_H */