]>
git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/Opcode.h
2 * Copyright (C) 2008, 2009, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "LLIntOpcode.h"
38 #include <wtf/Assertions.h>
42 #define FOR_EACH_CORE_OPCODE_ID_WITH_EXTENSION(macro, extension__) \
44 macro(op_create_activation, 2) \
45 macro(op_init_lazy_reg, 2) \
46 macro(op_create_arguments, 2) \
47 macro(op_create_this, 4) \
48 macro(op_get_callee, 3) \
49 macro(op_convert_this, 3) \
51 macro(op_new_object, 4) \
52 macro(op_new_array, 5) \
53 macro(op_new_array_with_size, 4) \
54 macro(op_new_array_buffer, 5) \
55 macro(op_new_regexp, 3) \
60 macro(op_eq_null, 3) \
62 macro(op_neq_null, 3) \
63 macro(op_stricteq, 4) \
64 macro(op_nstricteq, 4) \
67 macro(op_greater, 4) \
68 macro(op_greatereq, 4) \
72 macro(op_to_number, 3) \
82 macro(op_urshift, 4) \
87 macro(op_check_has_instance, 5) \
88 macro(op_instanceof, 4) \
90 macro(op_is_undefined, 3) \
91 macro(op_is_boolean, 3) \
92 macro(op_is_number, 3) \
93 macro(op_is_string, 3) \
94 macro(op_is_object, 3) \
95 macro(op_is_function, 3) \
98 macro(op_get_scoped_var, 5) /* has value profiling */ \
99 macro(op_put_scoped_var, 4) \
101 macro(op_resolve, 5) /* has value profiling */ \
102 macro(op_resolve_global_property, 5) /* has value profiling */ \
103 macro(op_resolve_global_var, 5) /* has value profiling */ \
104 macro(op_resolve_scoped_var, 5) /* has value profiling */ \
105 macro(op_resolve_scoped_var_on_top_scope, 5) /* has value profiling */ \
106 macro(op_resolve_scoped_var_with_top_scope_check, 5) /* has value profiling */ \
108 macro(op_resolve_base_to_global, 7) /* has value profiling */ \
109 macro(op_resolve_base_to_global_dynamic, 7) /* has value profiling */ \
110 macro(op_resolve_base_to_scope, 7) /* has value profiling */ \
111 macro(op_resolve_base_to_scope_with_top_scope_check, 7) /* has value profiling */ \
112 macro(op_resolve_base, 7) /* has value profiling */ \
114 macro(op_resolve_with_base, 7) /* has value profiling */ \
116 macro(op_resolve_with_this, 6) /* has value profiling */ \
118 macro(op_put_to_base, 5) \
119 macro(op_put_to_base_variable, 5) \
121 macro(op_init_global_const_nop, 5) \
122 macro(op_init_global_const, 5) \
123 macro(op_init_global_const_check, 5) \
124 macro(op_get_by_id, 9) /* has value profiling */ \
125 macro(op_get_by_id_out_of_line, 9) /* has value profiling */ \
126 macro(op_get_by_id_self, 9) /* has value profiling */ \
127 macro(op_get_by_id_proto, 9) /* has value profiling */ \
128 macro(op_get_by_id_chain, 9) /* has value profiling */ \
129 macro(op_get_by_id_getter_self, 9) /* has value profiling */ \
130 macro(op_get_by_id_getter_proto, 9) /* has value profiling */ \
131 macro(op_get_by_id_getter_chain, 9) /* has value profiling */ \
132 macro(op_get_by_id_custom_self, 9) /* has value profiling */ \
133 macro(op_get_by_id_custom_proto, 9) /* has value profiling */ \
134 macro(op_get_by_id_custom_chain, 9) /* has value profiling */ \
135 macro(op_get_by_id_generic, 9) /* has value profiling */ \
136 macro(op_get_array_length, 9) /* has value profiling */ \
137 macro(op_get_string_length, 9) /* has value profiling */ \
138 macro(op_get_arguments_length, 4) \
139 macro(op_put_by_id, 9) \
140 macro(op_put_by_id_out_of_line, 9) \
141 macro(op_put_by_id_transition, 9) \
142 macro(op_put_by_id_transition_direct, 9) \
143 macro(op_put_by_id_transition_direct_out_of_line, 9) \
144 macro(op_put_by_id_transition_normal, 9) \
145 macro(op_put_by_id_transition_normal_out_of_line, 9) \
146 macro(op_put_by_id_replace, 9) \
147 macro(op_put_by_id_generic, 9) \
148 macro(op_del_by_id, 4) \
149 macro(op_get_by_val, 6) /* has value profiling */ \
150 macro(op_get_argument_by_val, 6) /* must be the same size as op_get_by_val */ \
151 macro(op_get_by_pname, 7) \
152 macro(op_put_by_val, 5) \
153 macro(op_del_by_val, 4) \
154 macro(op_put_by_index, 4) \
155 macro(op_put_getter_setter, 5) \
159 macro(op_jfalse, 3) \
160 macro(op_jeq_null, 3) \
161 macro(op_jneq_null, 3) \
162 macro(op_jneq_ptr, 4) \
164 macro(op_jlesseq, 4) \
165 macro(op_jgreater, 4) \
166 macro(op_jgreatereq, 4) \
167 macro(op_jnless, 4) \
168 macro(op_jnlesseq, 4) \
169 macro(op_jngreater, 4) \
170 macro(op_jngreatereq, 4) \
172 macro(op_loop_hint, 1) \
174 macro(op_switch_imm, 4) \
175 macro(op_switch_char, 4) \
176 macro(op_switch_string, 4) \
178 macro(op_new_func, 4) \
179 macro(op_new_func_exp, 3) \
181 macro(op_call_eval, 6) \
182 macro(op_call_varargs, 5) \
183 macro(op_tear_off_activation, 2) \
184 macro(op_tear_off_arguments, 3) \
186 macro(op_call_put_result, 3) /* has value profiling */ \
187 macro(op_ret_object_or_this, 3) \
189 macro(op_construct, 6) \
190 macro(op_strcat, 4) \
191 macro(op_to_primitive, 3) \
193 macro(op_get_pnames, 6) \
194 macro(op_next_pname, 7) \
196 macro(op_push_with_scope, 2) \
197 macro(op_pop_scope, 1) \
198 macro(op_push_name_scope, 4) \
202 macro(op_throw_static_error, 3) \
205 macro(op_profile_will_call, 2) \
206 macro(op_profile_did_call, 2) \
210 macro(op_end, 2) // end must be the last opcode in the list
212 #define FOR_EACH_CORE_OPCODE_ID(macro) \
213 FOR_EACH_CORE_OPCODE_ID_WITH_EXTENSION(macro, /* No extension */ )
215 #define FOR_EACH_OPCODE_ID(macro) \
216 FOR_EACH_CORE_OPCODE_ID_WITH_EXTENSION( \
218 FOR_EACH_LLINT_OPCODE_EXTENSION(macro) \
222 #define OPCODE_ID_ENUM(opcode, length) opcode,
223 typedef enum { FOR_EACH_OPCODE_ID(OPCODE_ID_ENUM
) } OpcodeID
;
224 #undef OPCODE_ID_ENUM
226 const int maxOpcodeLength
= 9;
227 const int numOpcodeIDs
= op_end
+ 1;
229 #define OPCODE_ID_LENGTHS(id, length) const int id##_length = length;
230 FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS
);
231 #undef OPCODE_ID_LENGTHS
233 #define OPCODE_LENGTH(opcode) opcode##_length
235 #define OPCODE_ID_LENGTH_MAP(opcode, length) length,
236 const int opcodeLengths
[numOpcodeIDs
] = { FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTH_MAP
) };
237 #undef OPCODE_ID_LENGTH_MAP
239 #define VERIFY_OPCODE_ID(id, size) COMPILE_ASSERT(id <= op_end, ASSERT_THAT_JS_OPCODE_IDS_ARE_VALID);
240 FOR_EACH_OPCODE_ID(VERIFY_OPCODE_ID
);
241 #undef VERIFY_OPCODE_ID
243 #if ENABLE(COMPUTED_GOTO_OPCODES)
244 typedef void* Opcode
;
246 typedef OpcodeID Opcode
;
249 #define PADDING_STRING " "
250 #define PADDING_STRING_LENGTH static_cast<unsigned>(strlen(PADDING_STRING))
252 extern const char* const opcodeNames
[];
254 inline const char* padOpcodeName(OpcodeID op
, unsigned width
)
256 unsigned pad
= width
- strlen(opcodeNames
[op
]);
257 pad
= std::min(pad
, PADDING_STRING_LENGTH
);
258 return PADDING_STRING
+ PADDING_STRING_LENGTH
- pad
;
261 #undef PADDING_STRING_LENGTH
262 #undef PADDING_STRING
264 #if ENABLE(OPCODE_STATS)
269 static long long opcodeCounts
[numOpcodeIDs
];
270 static long long opcodePairCounts
[numOpcodeIDs
][numOpcodeIDs
];
271 static int lastOpcode
;
273 static void recordInstruction(int opcode
);
274 static void resetLastInstruction();
279 inline size_t opcodeLength(OpcodeID opcode
)
282 #define OPCODE_ID_LENGTHS(id, length) case id: return OPCODE_LENGTH(id);
283 FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS
)
284 #undef OPCODE_ID_LENGTHS
286 RELEASE_ASSERT_NOT_REACHED();