Ruby 1.9.3p327(2012-11-10revision37606)
|
00001 /********************************************************************** 00002 00003 vm.h - 00004 00005 $Author: akr $ 00006 created at: 04/01/01 16:56:59 JST 00007 00008 Copyright (C) 2004-2007 Koichi Sasada 00009 00010 **********************************************************************/ 00011 00012 #ifndef RUBY_VM_EXEC_H 00013 #define RUBY_VM_EXEC_H 00014 00015 typedef long OFFSET; 00016 typedef unsigned long lindex_t; 00017 typedef unsigned long dindex_t; 00018 typedef rb_num_t GENTRY; 00019 typedef rb_iseq_t *ISEQ; 00020 00021 #ifdef COLLECT_USAGE_ANALYSIS 00022 #define USAGE_ANALYSIS_INSN(insn) vm_analysis_insn(insn) 00023 #define USAGE_ANALYSIS_OPERAND(insn, n, op) vm_analysis_operand((insn), (n), (VALUE)(op)) 00024 #define USAGE_ANALYSIS_REGISTER(reg, s) vm_analysis_register((reg), (s)) 00025 #else 00026 #define USAGE_ANALYSIS_INSN(insn) /* none */ 00027 #define USAGE_ANALYSIS_OPERAND(insn, n, op) /* none */ 00028 #define USAGE_ANALYSIS_REGISTER(reg, s) /* none */ 00029 #endif 00030 00031 #ifdef __GCC__ 00032 /* TODO: machine dependent prefetch instruction */ 00033 #define PREFETCH(pc) 00034 #else 00035 #define PREFETCH(pc) 00036 #endif 00037 00038 #if VMDEBUG > 0 00039 #define debugs printf 00040 #define DEBUG_ENTER_INSN(insn) \ 00041 debug_print_pre(th, GET_CFP()); 00042 00043 #if OPT_STACK_CACHING 00044 #define SC_REGS() , reg_a, reg_b 00045 #else 00046 #define SC_REGS() 00047 #endif 00048 00049 #define DEBUG_END_INSN() \ 00050 debug_print_post(th, GET_CFP() SC_REGS()); 00051 00052 #else 00053 00054 #define debugs 00055 #define DEBUG_ENTER_INSN(insn) 00056 #define DEBUG_END_INSN() 00057 #endif 00058 00059 #define throwdebug if(0)printf 00060 /* #define throwdebug printf */ 00061 00062 /************************************************/ 00063 #if DISPATCH_XXX 00064 error ! 00065 /************************************************/ 00066 #elif OPT_CALL_THREADED_CODE 00067 00068 #define LABEL(x) insn_func_##x 00069 #define ELABEL(x) 00070 #define LABEL_PTR(x) &LABEL(x) 00071 00072 #define INSN_ENTRY(insn) \ 00073 static rb_control_frame_t * \ 00074 FUNC_FASTCALL(LABEL(insn))(rb_thread_t *th, rb_control_frame_t *reg_cfp) { 00075 00076 #define END_INSN(insn) return reg_cfp;} 00077 00078 #define NEXT_INSN() return reg_cfp; 00079 00080 /************************************************/ 00081 #elif OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE 00082 /* threaded code with gcc */ 00083 00084 #define LABEL(x) INSN_LABEL_##x 00085 #define ELABEL(x) INSN_ELABEL_##x 00086 #define LABEL_PTR(x) &&LABEL(x) 00087 00088 #define INSN_ENTRY_SIG(insn) 00089 00090 00091 #define INSN_DISPATCH_SIG(insn) 00092 00093 #define INSN_ENTRY(insn) \ 00094 LABEL(insn): \ 00095 INSN_ENTRY_SIG(insn); \ 00096 00097 /* dispather */ 00098 #if __GNUC__ && (__i386__ || __x86_64__) && __GNUC__ == 3 00099 #define DISPATCH_ARCH_DEPEND_WAY(addr) \ 00100 asm volatile("jmp *%0;\t# -- inseted by vm.h\t[length = 2]" : : "r" (addr)) 00101 00102 #else 00103 #define DISPATCH_ARCH_DEPEND_WAY(addr) \ 00104 /* do nothing */ 00105 00106 #endif 00107 00108 00109 /**********************************/ 00110 #if OPT_DIRECT_THREADED_CODE 00111 00112 /* for GCC 3.4.x */ 00113 #define TC_DISPATCH(insn) \ 00114 INSN_DISPATCH_SIG(insn); \ 00115 goto *(void const *)GET_CURRENT_INSN(); \ 00116 ; 00117 00118 #else 00119 /* token threade code */ 00120 00121 #define TC_DISPATCH(insn) \ 00122 DISPATCH_ARCH_DEPEND_WAY(insns_address_table[GET_CURRENT_INSN()]); \ 00123 INSN_DISPATCH_SIG(insn); \ 00124 goto *insns_address_table[GET_CURRENT_INSN()]; \ 00125 rb_bug("tc error"); 00126 00127 00128 #endif /* DISPATCH_DIRECT_THREADED_CODE */ 00129 00130 #define END_INSN(insn) \ 00131 DEBUG_END_INSN(); \ 00132 TC_DISPATCH(insn); \ 00133 00134 #define INSN_DISPATCH() \ 00135 TC_DISPATCH(__START__) \ 00136 { 00137 00138 #define END_INSNS_DISPATCH() \ 00139 rb_bug("unknown insn: %"PRIdVALUE, GET_CURRENT_INSN()); \ 00140 } /* end of while loop */ \ 00141 00142 #define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__) 00143 00144 /************************************************/ 00145 #else /* no threaded code */ 00146 /* most common method */ 00147 00148 #define INSN_ENTRY(insn) \ 00149 case BIN(insn): 00150 00151 #define END_INSN(insn) \ 00152 DEBUG_END_INSN(); \ 00153 break; 00154 00155 00156 #define INSN_DISPATCH() \ 00157 while(1){ \ 00158 switch(GET_CURRENT_INSN()){ 00159 00160 #define END_INSNS_DISPATCH() \ 00161 default: \ 00162 SDR(); \ 00163 rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \ 00164 } /* end of switch */ \ 00165 } /* end of while loop */ \ 00166 00167 #define NEXT_INSN() goto first 00168 00169 #endif 00170 00171 #define VM_SP_CNT(th, sp) ((sp) - (th)->stack) 00172 00173 #if OPT_CALL_THREADED_CODE 00174 #define THROW_EXCEPTION(exc) do { \ 00175 th->errinfo = (VALUE)(exc); \ 00176 return 0; \ 00177 } while (0) 00178 #else 00179 #define THROW_EXCEPTION(exc) return (VALUE)(exc) 00180 #endif 00181 00182 #define SCREG(r) (reg_##r) 00183 00184 #endif /* RUBY_VM_EXEC_H */ 00185