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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BytecodeUseDef_h
#define BytecodeUseDef_h
#include "CodeBlock.h"
namespace JSC {
template<typename Functor>
void computeUsesForBytecodeOffset(
CodeBlock* codeBlock, unsigned bytecodeOffset, Functor& functor)
{
Interpreter* interpreter = codeBlock->vm()->interpreter;
Instruction* instructionsBegin = codeBlock->instructions().begin();
Instruction* instruction = &instructionsBegin[bytecodeOffset];
OpcodeID opcodeID = interpreter->getOpcodeID(instruction->u.opcode);
switch (opcodeID) {
// No uses.
case op_new_regexp:
case op_new_array_buffer:
case op_throw_static_error:
case op_debug:
case op_resolve_scope:
case op_pop_scope:
case op_jneq_ptr:
case op_new_func_exp:
case op_loop_hint:
case op_jmp:
case op_new_object:
case op_init_lazy_reg:
case op_get_callee:
case op_enter:
case op_catch:
case op_touch_entry:
return;
case op_new_func:
case op_new_captured_func:
case op_create_lexical_environment:
case op_create_arguments:
case op_to_this:
case op_tear_off_lexical_environment:
case op_profile_will_call:
case op_profile_did_call:
case op_profile_type:
case op_throw:
case op_push_with_scope:
case op_end:
case op_ret:
case op_jtrue:
case op_jfalse:
case op_jeq_null:
case op_jneq_null:
case op_dec:
case op_inc: {
functor(codeBlock, instruction, opcodeID, instruction[1].u.operand);
return;
}
case op_ret_object_or_this:
case op_jlesseq:
case op_jgreater:
case op_jgreatereq:
case op_jnless:
case op_jnlesseq:
case op_jngreater:
case op_jngreatereq:
case op_jless: {
functor(codeBlock, instruction, opcodeID, instruction[1].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
return;
}
case op_put_by_val_direct:
case op_put_by_val: {
functor(codeBlock, instruction, opcodeID, instruction[1].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[3].u.operand);
return;
}
case op_put_by_index:
case op_put_by_id_transition_direct:
case op_put_by_id_transition_direct_out_of_line:
case op_put_by_id_transition_normal:
case op_put_by_id_transition_normal_out_of_line:
case op_put_by_id_out_of_line:
case op_put_by_id:
case op_put_to_scope: {
functor(codeBlock, instruction, opcodeID, instruction[1].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[3].u.operand);
return;
}
case op_put_getter_setter: {
functor(codeBlock, instruction, opcodeID, instruction[1].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[3].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[4].u.operand);
return;
}
case op_get_enumerable_length:
case op_to_index_string:
case op_init_global_const_nop:
case op_init_global_const:
case op_push_name_scope:
case op_get_from_scope:
case op_to_primitive:
case op_get_by_id:
case op_get_by_id_out_of_line:
case op_get_array_length:
case op_get_arguments_length:
case op_typeof:
case op_is_undefined:
case op_is_boolean:
case op_is_number:
case op_is_string:
case op_is_object:
case op_is_function:
case op_to_number:
case op_negate:
case op_neq_null:
case op_eq_null:
case op_not:
case op_mov:
case op_captured_mov:
case op_new_array_with_size:
case op_create_this:
case op_del_by_id:
case op_unsigned: {
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
return;
}
case op_has_generic_property:
case op_get_structure_property_enumerator:
case op_has_indexed_property:
case op_next_enumerator_pname:
case op_get_by_val:
case op_get_argument_by_val:
case op_in:
case op_instanceof:
case op_check_has_instance:
case op_add:
case op_mul:
case op_div:
case op_mod:
case op_sub:
case op_lshift:
case op_rshift:
case op_urshift:
case op_bitand:
case op_bitxor:
case op_bitor:
case op_less:
case op_lesseq:
case op_greater:
case op_greatereq:
case op_nstricteq:
case op_stricteq:
case op_neq:
case op_eq:
case op_del_by_val: {
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[3].u.operand);
return;
}
case op_has_structure_property:
case op_get_generic_property_enumerator:
case op_construct_varargs:
case op_call_varargs: {
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[3].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[4].u.operand);
return;
}
case op_get_direct_pname: {
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[3].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[4].u.operand);
functor(codeBlock, instruction, opcodeID, instruction[5].u.operand);
return;
}
case op_switch_string:
case op_switch_char:
case op_switch_imm: {
functor(codeBlock, instruction, opcodeID, instruction[3].u.operand);
return;
}
case op_new_array:
case op_strcat: {
int base = instruction[2].u.operand;
int count = instruction[3].u.operand;
for (int i = 0; i < count; i++)
functor(codeBlock, instruction, opcodeID, base - i);
return;
}
case op_construct:
case op_call_eval:
case op_call: {
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
int argCount = instruction[3].u.operand;
int registerOffset = -instruction[4].u.operand;
int lastArg = registerOffset + CallFrame::thisArgumentOffset();
for (int i = opcodeID == op_construct ? 1 : 0; i < argCount; i++)
functor(codeBlock, instruction, opcodeID, lastArg + i);
return;
}
case op_tear_off_arguments: {
functor(codeBlock, instruction, opcodeID, instruction[1].u.operand);
functor(codeBlock, instruction, opcodeID, unmodifiedArgumentsRegister(VirtualRegister(instruction[1].u.operand)).offset());
functor(codeBlock, instruction, opcodeID, instruction[2].u.operand);
return;
}
default:
RELEASE_ASSERT_NOT_REACHED();
break;
}
}
template<typename Functor>
void computeDefsForBytecodeOffset(CodeBlock* codeBlock, unsigned bytecodeOffset, Functor& functor)
{
Interpreter* interpreter = codeBlock->vm()->interpreter;
Instruction* instructionsBegin = codeBlock->instructions().begin();
Instruction* instruction = &instructionsBegin[bytecodeOffset];
OpcodeID opcodeID = interpreter->getOpcodeID(instruction->u.opcode);
switch (opcodeID) {
// These don't define anything.
case op_init_global_const:
case op_init_global_const_nop:
case op_push_name_scope:
case op_push_with_scope:
case op_put_to_scope:
case op_pop_scope:
case op_end:
case op_profile_will_call:
case op_profile_did_call:
case op_throw:
case op_throw_static_error:
case op_debug:
case op_ret:
case op_ret_object_or_this:
case op_jmp:
case op_jtrue:
case op_jfalse:
case op_jeq_null:
case op_jneq_null:
case op_jneq_ptr:
case op_jless:
case op_jlesseq:
case op_jgreater:
case op_jgreatereq:
case op_jnless:
case op_jnlesseq:
case op_jngreater:
case op_jngreatereq:
case op_loop_hint:
case op_switch_imm:
case op_switch_char:
case op_switch_string:
case op_put_by_id:
case op_put_by_id_out_of_line:
case op_put_by_id_transition_direct:
case op_put_by_id_transition_direct_out_of_line:
case op_put_by_id_transition_normal:
case op_put_by_id_transition_normal_out_of_line:
case op_put_getter_setter:
case op_put_by_val:
case op_put_by_val_direct:
case op_put_by_index:
case op_tear_off_arguments:
case op_profile_type:
case op_touch_entry:
#define LLINT_HELPER_OPCODES(opcode, length) case opcode:
FOR_EACH_LLINT_OPCODE_EXTENSION(LLINT_HELPER_OPCODES);
#undef LLINT_HELPER_OPCODES
return;
// These all have a single destination for the first argument.
case op_to_index_string:
case op_get_generic_property_enumerator:
case op_get_enumerable_length:
case op_has_indexed_property:
case op_has_structure_property:
case op_has_generic_property:
case op_get_direct_pname:
case op_get_structure_property_enumerator:
case op_next_enumerator_pname:
case op_resolve_scope:
case op_strcat:
case op_tear_off_lexical_environment:
case op_to_primitive:
case op_catch:
case op_create_this:
case op_new_array:
case op_new_array_buffer:
case op_new_array_with_size:
case op_new_regexp:
case op_new_func:
case op_new_captured_func:
case op_new_func_exp:
case op_call_varargs:
case op_construct_varargs:
case op_get_from_scope:
case op_call:
case op_call_eval:
case op_construct:
case op_get_by_id:
case op_get_by_id_out_of_line:
case op_get_array_length:
case op_check_has_instance:
case op_instanceof:
case op_get_by_val:
case op_get_argument_by_val:
case op_get_arguments_length:
case op_typeof:
case op_is_undefined:
case op_is_boolean:
case op_is_number:
case op_is_string:
case op_is_object:
case op_is_function:
case op_in:
case op_to_number:
case op_negate:
case op_add:
case op_mul:
case op_div:
case op_mod:
case op_sub:
case op_lshift:
case op_rshift:
case op_urshift:
case op_bitand:
case op_bitxor:
case op_bitor:
case op_inc:
case op_dec:
case op_eq:
case op_neq:
case op_stricteq:
case op_nstricteq:
case op_less:
case op_lesseq:
case op_greater:
case op_greatereq:
case op_neq_null:
case op_eq_null:
case op_not:
case op_mov:
case op_captured_mov:
case op_new_object:
case op_to_this:
case op_get_callee:
case op_init_lazy_reg:
case op_create_lexical_environment:
case op_create_arguments:
case op_del_by_id:
case op_del_by_val:
case op_unsigned: {
functor(codeBlock, instruction, opcodeID, instruction[1].u.operand);
return;
}
case op_enter: {
for (unsigned i = codeBlock->m_numVars; i--;)
functor(codeBlock, instruction, opcodeID, virtualRegisterForLocal(i).offset());
return;
} }
}
} // namespace JSC
#endif // BytecodeUseDef_h
|