| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 345 } |
| 346 | 346 |
| 347 | 347 |
| 348 void CodeGenerator::GenerateFastCaseSwitchStatement(SwitchStatement* node, | 348 void CodeGenerator::GenerateFastCaseSwitchStatement(SwitchStatement* node, |
| 349 int min_index, | 349 int min_index, |
| 350 int range, | 350 int range, |
| 351 int default_index) { | 351 int default_index) { |
| 352 ZoneList<CaseClause*>* cases = node->cases(); | 352 ZoneList<CaseClause*>* cases = node->cases(); |
| 353 int length = cases->length(); | 353 int length = cases->length(); |
| 354 | 354 |
| 355 // Label pointer per number in range | 355 // JumpTarget pointer per number in range. |
| 356 SmartPointer<Label*> case_targets(NewArray<Label*>(range)); | 356 SmartPointer<JumpTarget*> case_targets(NewArray<JumpTarget*>(range)); |
| 357 | 357 |
| 358 // Label per switch case | 358 // JumpTarget per switch case. |
| 359 SmartPointer<Label> case_labels(NewArray<Label>(length)); | 359 SmartPointer<JumpTarget> case_labels(NewArray<JumpTarget>(length)); |
| 360 for (int i = 0; i < length; i++) { |
| 361 case_labels[i].set_code_generator(this); |
| 362 } |
| 360 | 363 |
| 361 Label* fail_label = default_index >= 0 ? &(case_labels[default_index]) | 364 JumpTarget* fail_label = default_index >= 0 ? &(case_labels[default_index]) |
| 362 : node->break_target(); | 365 : node->break_target(); |
| 363 | 366 |
| 364 // Populate array of label pointers for each number in the range. | 367 // Populate array of label pointers for each number in the range. |
| 365 // Initally put the failure label everywhere. | 368 // Initally put the failure label everywhere. |
| 366 for (int i = 0; i < range; i++) { | 369 for (int i = 0; i < range; i++) { |
| 367 case_targets[i] = fail_label; | 370 case_targets[i] = fail_label; |
| 368 } | 371 } |
| 369 | 372 |
| 370 // Overwrite with label of a case for the number value of that case. | 373 // Overwrite with label of a case for the number value of that case. |
| 371 // (In reverse order, so that if the same label occurs twice, the | 374 // (In reverse order, so that if the same label occurs twice, the |
| 372 // first one wins). | 375 // first one wins). |
| 373 for (int i = length-1; i >= 0 ; i--) { | 376 for (int i = length-1; i >= 0 ; i--) { |
| 374 CaseClause* clause = cases->at(i); | 377 CaseClause* clause = cases->at(i); |
| 375 if (!clause->is_default()) { | 378 if (!clause->is_default()) { |
| 376 Object* label_value = *(clause->label()->AsLiteral()->handle()); | 379 Object* label_value = *(clause->label()->AsLiteral()->handle()); |
| 377 int case_value = Smi::cast(label_value)->value(); | 380 int case_value = Smi::cast(label_value)->value(); |
| 378 case_targets[case_value - min_index] = &(case_labels[i]); | 381 case_targets[case_value - min_index] = &(case_labels[i]); |
| 379 } | 382 } |
| 380 } | 383 } |
| 381 | 384 |
| 382 GenerateFastCaseSwitchJumpTable(node, | 385 GenerateFastCaseSwitchJumpTable(node, |
| 383 min_index, | 386 min_index, |
| 384 range, | 387 range, |
| 385 fail_label, | 388 fail_label, |
| 386 Vector<Label*>(*case_targets, range), | 389 Vector<JumpTarget*>(*case_targets, range), |
| 387 Vector<Label>(*case_labels, length)); | 390 Vector<JumpTarget>(*case_labels, length)); |
| 388 } | 391 } |
| 389 | 392 |
| 390 | 393 |
| 391 void CodeGenerator::GenerateFastCaseSwitchCases( | 394 void CodeGenerator::GenerateFastCaseSwitchCases( |
| 392 SwitchStatement* node, | 395 SwitchStatement* node, |
| 393 Vector<Label> case_labels) { | 396 Vector<JumpTarget> case_labels, |
| 397 JumpTarget* table_start) { |
| 394 ZoneList<CaseClause*>* cases = node->cases(); | 398 ZoneList<CaseClause*>* cases = node->cases(); |
| 395 int length = cases->length(); | 399 int length = cases->length(); |
| 396 | 400 |
| 397 for (int i = 0; i < length; i++) { | 401 for (int i = 0; i < length; i++) { |
| 398 Comment cmnt(masm(), "[ Case clause"); | 402 Comment cmnt(masm(), "[ Case clause"); |
| 399 masm()->bind(&(case_labels[i])); | 403 case_labels[i].Bind(); |
| 400 VisitStatements(cases->at(i)->statements()); | 404 VisitStatements(cases->at(i)->statements()); |
| 405 |
| 406 // All of the labels match the same expected frame as the table start. |
| 407 // If control flow cannot fall off the end of the case statement, we |
| 408 // pick up the expected frame from the table start. Otherwise we have |
| 409 // to generate merge code to match the next label. |
| 410 if (frame_ == NULL) { |
| 411 frame_ = new VirtualFrame(table_start->expected_frame()); |
| 412 } else { |
| 413 frame_->MergeTo(table_start->expected_frame()); |
| 414 } |
| 401 } | 415 } |
| 402 | 416 |
| 403 masm()->bind(node->break_target()); | 417 node->break_target()->Bind(); |
| 404 } | 418 } |
| 405 | 419 |
| 406 | 420 |
| 407 bool CodeGenerator::TryGenerateFastCaseSwitchStatement(SwitchStatement* node) { | 421 bool CodeGenerator::TryGenerateFastCaseSwitchStatement(SwitchStatement* node) { |
| 408 ZoneList<CaseClause*>* cases = node->cases(); | 422 ZoneList<CaseClause*>* cases = node->cases(); |
| 409 int length = cases->length(); | 423 int length = cases->length(); |
| 410 | 424 |
| 411 if (length < FastCaseSwitchMinCaseCount()) { | 425 if (length < FastCaseSwitchMinCaseCount()) { |
| 412 return false; | 426 return false; |
| 413 } | 427 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { | 479 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { |
| 466 switch (type_) { | 480 switch (type_) { |
| 467 case READ_LENGTH: GenerateReadLength(masm); break; | 481 case READ_LENGTH: GenerateReadLength(masm); break; |
| 468 case READ_ELEMENT: GenerateReadElement(masm); break; | 482 case READ_ELEMENT: GenerateReadElement(masm); break; |
| 469 case NEW_OBJECT: GenerateNewObject(masm); break; | 483 case NEW_OBJECT: GenerateNewObject(masm); break; |
| 470 } | 484 } |
| 471 } | 485 } |
| 472 | 486 |
| 473 | 487 |
| 474 } } // namespace v8::internal | 488 } } // namespace v8::internal |
| OLD | NEW |