1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
/*
* tclExecute.h --
*
* This file contains the compiler-dependent macros that determine the
* instruction-threading method used by tclExecute.c
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclExecute.h,v 1.1.2.2 2001/07/13 21:25:00 msofer Exp $
*/
/*
* An instruction-threading method has to define the following macros:
*
* . _CASE_DECLS declarations of special variables required
* . CHECK_OPCODES 0/1, if the opcodes have to be checked before RT
* . _CASE_START start of the block containing instructions
* . _CASE(instruction) the labelling method for instruction start
* . NEXT_INSTR the jump to the next instruction
* . _CASE_END end of the block containing instructions
*
*
* Currently three different methods are implemented:
*
* 1. SWITCH produces standard C code valid for any compiler;
* jumps from the end of an instruction to the switch
* statement, from there to the next instruction after
* performing a bounds check
* 2. GCC uses a gcc extension to jump directly from the end
* of an instruction to the start of the next one, using
* a jump table and the "labels as values" extension
* 3. MSVC directs msvc to omit checking the bounds of the switch
*/
#define SWITCH 0
#define GCC 1
#define MSVC 2
/*
* Choose the threading method according to the compiler being used; if
* TCL_BYTECODE_DEBUG is set, fallback to SWITCH for any compiler
*/
#ifdef __GNUC__
#define JUMP_version GCC
#elif defined( _MSC_VER ) && ( _MSC_VER >= 1200 ) && defined( _MSC_EXTENSIONS )
/* msvc with extensions */
#define JUMP_version MSVC
#else /* standard C output */
#define JUMP_version SWITCH
#endif /* choice of method */
#ifdef TCL_BYTECODE_DEBUG
# undef JUMP_version
# define JUMP_version SWITCH
# define INIT_TRACE_CHECK \
if (tclTraceExec == 3) {\
fprintf(stdout, "%2d: %2d ", iPtr->numLevels, tosPtr - eePtr->stackPtr);\
TclPrintInstruction(codePtr, pc);\
fflush(stdout);\
}
#else /* not debugging */
# define INIT_TRACE_CHECK
#endif /* debugging code */
/*
* Define the macros for the different threading methods
*/
/**** SWITCH ****/
#if JUMP_version == SWITCH
#define _CASE_DECLS
#define CHECK_OPCODES 0
# define _CASE_START \
instructions_start: \
INIT_TRACE_CHECK \
switch (*pc) {
#define _CASE(instruction) case instruction
#define NEXT_INSTR goto instructions_start
#define _CASE_END \
default: \
panic("TclExecuteByteCode: unrecognized opCode %u", *pc);\
} /* end of switch on opCode */
#endif /* SWITCH methods */
/**** MSVC ****/
#if JUMP_version == MSVC
#define _CASE_DECLS
#define CHECK_OPCODES 1
#define _CASE_START \
instructions_start: \
switch (*pc) {
#define _CASE(instruction) case instruction
#define NEXT_INSTR goto instructions_start
#define _CASE_END \
default: \
__assume(0); /* do not check bounds of switch! */ \
} /* end of switch on opCode */
#endif /* MSVC methods */
/**** GCC ****/
#if JUMP_version == GCC
#define _CASE_DECLS \
static const void *jumpTable[] = _JUMP_TABLE;
#define CHECK_OPCODES 1
#define _CASE_START NEXT_INSTR;
#define _CASE(instruction) _CASE_ ## instruction
#define NEXT_INSTR goto *jumpTable[*pc]
#define _CASE_END /* end of switch on opCode */
/* _CASE_DECLS uses the following jump table
* IT HAS TO BE IN THE CORRECT ORDER, of course */
#define _JUMP_TABLE {\
&&_CASE(INST_DONE),\
&&_CASE(INST_PUSH1),\
&&_CASE(INST_PUSH4),\
&&_CASE(INST_POP),\
&&_CASE(INST_DUP),\
&&_CASE(INST_CONCAT1),\
&&_CASE(INST_INVOKE_STK1),\
&&_CASE(INST_INVOKE_STK4),\
&&_CASE(INST_EVAL_STK),\
&&_CASE(INST_EXPR_STK),\
&&_CASE(INST_LOAD_SCALAR1),\
&&_CASE(INST_LOAD_SCALAR4),\
&&_CASE(INST_LOAD_SCALAR_STK),\
&&_CASE(INST_LOAD_ARRAY1),\
&&_CASE(INST_LOAD_ARRAY4),\
&&_CASE(INST_LOAD_ARRAY_STK),\
&&_CASE(INST_LOAD_STK),\
&&_CASE(INST_STORE_SCALAR1),\
&&_CASE(INST_STORE_SCALAR4),\
&&_CASE(INST_STORE_SCALAR_STK),\
&&_CASE(INST_STORE_ARRAY1),\
&&_CASE(INST_STORE_ARRAY4),\
&&_CASE(INST_STORE_ARRAY_STK),\
&&_CASE(INST_STORE_STK),\
&&_CASE(INST_INCR_SCALAR1),\
&&_CASE(INST_INCR_SCALAR_STK),\
&&_CASE(INST_INCR_ARRAY1),\
&&_CASE(INST_INCR_ARRAY_STK),\
&&_CASE(INST_INCR_STK),\
&&_CASE(INST_INCR_SCALAR1_IMM),\
&&_CASE(INST_INCR_SCALAR_STK_IMM),\
&&_CASE(INST_INCR_ARRAY1_IMM),\
&&_CASE(INST_INCR_ARRAY_STK_IMM),\
&&_CASE(INST_INCR_STK_IMM),\
&&_CASE(INST_JUMP1),\
&&_CASE(INST_JUMP4),\
&&_CASE(INST_JUMP_TRUE1),\
&&_CASE(INST_JUMP_TRUE4),\
&&_CASE(INST_JUMP_FALSE1),\
&&_CASE(INST_JUMP_FALSE4),\
&&_CASE(INST_LOR),\
&&_CASE(INST_LAND),\
&&_CASE(INST_BITOR),\
&&_CASE(INST_BITXOR),\
&&_CASE(INST_BITAND),\
&&_CASE(INST_EQ),\
&&_CASE(INST_NEQ),\
&&_CASE(INST_LT),\
&&_CASE(INST_GT),\
&&_CASE(INST_LE),\
&&_CASE(INST_GE),\
&&_CASE(INST_LSHIFT),\
&&_CASE(INST_RSHIFT),\
&&_CASE(INST_ADD),\
&&_CASE(INST_SUB),\
&&_CASE(INST_MULT),\
&&_CASE(INST_DIV),\
&&_CASE(INST_MOD),\
&&_CASE(INST_UPLUS),\
&&_CASE(INST_UMINUS),\
&&_CASE(INST_BITNOT),\
&&_CASE(INST_LNOT),\
&&_CASE(INST_CALL_BUILTIN_FUNC1),\
&&_CASE(INST_CALL_FUNC1),\
&&_CASE(INST_TRY_CVT_TO_NUMERIC),\
&&_CASE(INST_BREAK),\
&&_CASE(INST_CONTINUE),\
&&_CASE(INST_FOREACH_START4),\
&&_CASE(INST_FOREACH_STEP4),\
&&_CASE(INST_BEGIN_CATCH4),\
&&_CASE(INST_END_CATCH),\
&&_CASE(INST_PUSH_RESULT),\
&&_CASE(INST_PUSH_RETURN_CODE),\
&&_CASE(INST_STR_EQ),\
&&_CASE(INST_STR_NEQ),\
&&_CASE(INST_STR_CMP),\
&&_CASE(INST_STR_LEN),\
&&_CASE(INST_STR_INDEX),\
&&_CASE(INST_STR_MATCH),\
&&_CASE(INST_LIST),\
&&_CASE(INST_LIST_INDEX),\
&&_CASE(INST_LIST_LENGTH),\
&&_CASE(INST_APPEND_SCALAR1),\
&&_CASE(INST_APPEND_SCALAR4),\
&&_CASE(INST_APPEND_ARRAY1),\
&&_CASE(INST_APPEND_ARRAY4),\
&&_CASE(INST_APPEND_ARRAY_STK),\
&&_CASE(INST_APPEND_STK),\
&&_CASE(INST_LAPPEND_SCALAR1),\
&&_CASE(INST_LAPPEND_SCALAR4),\
&&_CASE(INST_LAPPEND_ARRAY1),\
&&_CASE(INST_LAPPEND_ARRAY4),\
&&_CASE(INST_LAPPEND_ARRAY_STK),\
&&_CASE(INST_LAPPEND_STK)\
}
#endif /* GCC methods */
/* End of method definitions */
#undef SWITCH
#undef GCC
#undef MSVC
#undef JUMP_version
|