Ruby
1.9.3p551(2014-11-13revision48407)
Main Page
Modules
Data Structures
Files
File List
Globals
vm_exec.h
Go to the documentation of this file.
1
/**********************************************************************
2
3
vm.h -
4
5
$Author: usa $
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
unsigned
long
dindex_t
;
18
typedef
VALUE
GENTRY
;
19
typedef
rb_iseq_t
*
ISEQ
;
20
21
#ifdef COLLECT_USAGE_ANALYSIS
22
#define USAGE_ANALYSIS_INSN(insn) vm_analysis_insn(insn)
23
#define USAGE_ANALYSIS_OPERAND(insn, n, op) vm_analysis_operand((insn), (n), (VALUE)(op))
24
#define USAGE_ANALYSIS_REGISTER(reg, s) vm_analysis_register((reg), (s))
25
#else
26
#define USAGE_ANALYSIS_INSN(insn)
/* none */
27
#define USAGE_ANALYSIS_OPERAND(insn, n, op)
/* none */
28
#define USAGE_ANALYSIS_REGISTER(reg, s)
/* none */
29
#endif
30
31
#ifdef __GCC__
32
/* TODO: machine dependent prefetch instruction */
33
#define PREFETCH(pc)
34
#else
35
#define PREFETCH(pc)
36
#endif
37
38
#if VMDEBUG > 0
39
#define debugs printf
40
#define DEBUG_ENTER_INSN(insn) \
41
debug_print_pre(th, GET_CFP());
42
43
#if OPT_STACK_CACHING
44
#define SC_REGS() , reg_a, reg_b
45
#else
46
#define SC_REGS()
47
#endif
48
49
#define DEBUG_END_INSN() \
50
debug_print_post(th, GET_CFP() SC_REGS());
51
52
#else
53
54
#define debugs
55
#define DEBUG_ENTER_INSN(insn)
56
#define DEBUG_END_INSN()
57
#endif
58
59
#define throwdebug if(0)printf
60
/* #define throwdebug printf */
61
62
/************************************************/
63
#if DISPATCH_XXX
64
error !
65
/************************************************/
66
#elif OPT_CALL_THREADED_CODE
67
68
#define LABEL(x) insn_func_##x
69
#define ELABEL(x)
70
#define LABEL_PTR(x) &LABEL(x)
71
72
#define INSN_ENTRY(insn) \
73
static rb_control_frame_t * \
74
FUNC_FASTCALL(LABEL(insn))(rb_thread_t *th, rb_control_frame_t *reg_cfp) {
75
76
#define END_INSN(insn) return reg_cfp;}
77
78
#define NEXT_INSN() return reg_cfp;
79
80
/************************************************/
81
#elif OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE
82
/* threaded code with gcc */
83
84
#define LABEL(x) INSN_LABEL_##x
85
#define ELABEL(x) INSN_ELABEL_##x
86
#define LABEL_PTR(x) &&LABEL(x)
87
88
#define INSN_ENTRY_SIG(insn)
89
90
91
#define INSN_DISPATCH_SIG(insn)
92
93
#define INSN_ENTRY(insn) \
94
LABEL(insn): \
95
INSN_ENTRY_SIG(insn); \
96
97
/* dispather */
98
#if __GNUC__ && (__i386__ || __x86_64__) && __GNUC__ == 3
99
#define DISPATCH_ARCH_DEPEND_WAY(addr) \
100
asm volatile("jmp *%0;\t# -- inseted by vm.h\t[length = 2]" : : "r" (addr))
101
102
#else
103
#define DISPATCH_ARCH_DEPEND_WAY(addr) \
104
/* do nothing */
105
106
#endif
107
108
109
/**********************************/
110
#if OPT_DIRECT_THREADED_CODE
111
112
/* for GCC 3.4.x */
113
#define TC_DISPATCH(insn) \
114
INSN_DISPATCH_SIG(insn); \
115
goto *(void const *)GET_CURRENT_INSN(); \
116
;
117
118
#else
119
/* token threade code */
120
121
#define TC_DISPATCH(insn) \
122
DISPATCH_ARCH_DEPEND_WAY(insns_address_table[GET_CURRENT_INSN()]); \
123
INSN_DISPATCH_SIG(insn); \
124
goto *insns_address_table[GET_CURRENT_INSN()]; \
125
rb_bug("tc error");
126
127
128
#endif
/* DISPATCH_DIRECT_THREADED_CODE */
129
130
#define END_INSN(insn) \
131
DEBUG_END_INSN(); \
132
TC_DISPATCH(insn); \
133
134
#define INSN_DISPATCH() \
135
TC_DISPATCH(__START__) \
136
{
137
138
#define END_INSNS_DISPATCH() \
139
rb_bug("unknown insn: %"PRIdVALUE, GET_CURRENT_INSN()); \
140
}
/* end of while loop */
\
141
142
#define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__)
143
144
/************************************************/
145
#else
/* no threaded code */
146
/* most common method */
147
148
#define INSN_ENTRY(insn) \
149
case BIN(insn):
150
151
#define END_INSN(insn) \
152
DEBUG_END_INSN(); \
153
break;
154
155
156
#define INSN_DISPATCH() \
157
while(1){ \
158
switch(GET_CURRENT_INSN()){
159
160
#define END_INSNS_DISPATCH() \
161
default: \
162
SDR(); \
163
rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
164
}
/* end of switch */
\
165
}
/* end of while loop */
\
166
167
#define NEXT_INSN() goto first
168
169
#endif
170
171
#define VM_SP_CNT(th, sp) ((sp) - (th)->stack)
172
173
#if OPT_CALL_THREADED_CODE
174
#define THROW_EXCEPTION(exc) do { \
175
th->errinfo = (VALUE)(exc); \
176
return 0; \
177
} while (0)
178
#else
179
#define THROW_EXCEPTION(exc) return (VALUE)(exc)
180
#endif
181
182
#define SCREG(r) (reg_##r)
183
184
#endif
/* RUBY_VM_EXEC_H */
dindex_t
unsigned long dindex_t
Definition:
vm_exec.h:17
OFFSET
long OFFSET
Definition:
vm_exec.h:15
VALUE
unsigned long VALUE
Definition:
ruby.h:88
ISEQ
rb_iseq_t * ISEQ
Definition:
vm_exec.h:19
lindex_t
unsigned long lindex_t
Definition:
vm_exec.h:16
rb_iseq_struct
Definition:
vm_core.h:151
GENTRY
VALUE GENTRY
Definition:
vm_exec.h:18
Generated by
1.8.5