Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "data-flow.h" | |
| 30 #include "fast-codegen.h" | 31 #include "fast-codegen.h" |
| 31 #include "scopes.h" | 32 #include "scopes.h" |
| 32 | 33 |
| 33 namespace v8 { | 34 namespace v8 { |
| 34 namespace internal { | 35 namespace internal { |
| 35 | 36 |
| 36 #define BAILOUT(reason) \ | 37 #define BAILOUT(reason) \ |
| 37 do { \ | 38 do { \ |
| 38 if (FLAG_trace_bailout) { \ | 39 if (FLAG_trace_bailout) { \ |
| 39 PrintF("%s\n", reason); \ | 40 PrintF("%s\n", reason); \ |
| 40 } \ | 41 } \ |
| 41 has_supported_syntax_ = false; \ | 42 has_supported_syntax_ = false; \ |
| 42 return; \ | 43 return; \ |
| 43 } while (false) | 44 } while (false) |
| 44 | 45 |
| 45 | 46 |
| 46 #define CHECK_BAILOUT \ | 47 #define CHECK_BAILOUT \ |
| 47 do { \ | 48 do { \ |
| 48 if (!has_supported_syntax_) return; \ | 49 if (!has_supported_syntax_) return; \ |
| 49 } while (false) | 50 } while (false) |
| 50 | 51 |
| 51 | 52 |
| 52 void FastCodeGenSyntaxChecker::Check(FunctionLiteral* fun, | 53 void FastCodeGenSyntaxChecker::Check(FunctionLiteral* fun, |
| 53 CompilationInfo* info) { | 54 CompilationInfo* info) { |
| 55 info_ = info; | |
| 56 | |
| 54 // We do not specialize if we do not have a receiver. | 57 // We do not specialize if we do not have a receiver. |
| 55 if (!info->has_receiver()) BAILOUT("No receiver"); | 58 if (!info->has_receiver()) BAILOUT("No receiver"); |
| 56 | 59 |
| 57 // We do not support stack or heap slots (both of which require | 60 // We do not support stack or heap slots (both of which require |
| 58 // allocation). | 61 // allocation). |
| 59 Scope* scope = fun->scope(); | 62 Scope* scope = fun->scope(); |
| 60 if (scope->num_stack_slots() > 0) { | 63 if (scope->num_stack_slots() > 0) { |
| 61 BAILOUT("Function has stack-allocated locals"); | 64 BAILOUT("Function has stack-allocated locals"); |
| 62 } | 65 } |
| 63 if (scope->num_heap_slots() > 0) { | 66 if (scope->num_heap_slots() > 0) { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 | 318 |
| 316 | 319 |
| 317 void FastCodeGenSyntaxChecker::VisitThisFunction(ThisFunction* expr) { | 320 void FastCodeGenSyntaxChecker::VisitThisFunction(ThisFunction* expr) { |
| 318 BAILOUT("ThisFunction"); | 321 BAILOUT("ThisFunction"); |
| 319 } | 322 } |
| 320 | 323 |
| 321 #undef BAILOUT | 324 #undef BAILOUT |
| 322 #undef CHECK_BAILOUT | 325 #undef CHECK_BAILOUT |
| 323 | 326 |
| 324 | 327 |
| 328 void FastCodeGenerator::MakeCode(FunctionLiteral* fun, | |
| 329 Handle<Script> script, | |
| 330 bool is_eval, | |
| 331 CompilationInfo* info) { | |
| 332 AstLabeler labeler; | |
| 333 FastCodeGenerator cgen(script, is_eval); | |
| 334 labeler.Label(fun); | |
| 335 cgen.Generate(fun, info); | |
| 336 } | |
| 337 | |
| 338 | |
| 339 void FastCodeGenerator::Generate(FunctionLiteral* fun, CompilationInfo* info) { | |
| 340 ASSERT(function_ == NULL); | |
| 341 ASSERT(info_ == NULL); | |
| 342 function_ = fun; | |
| 343 info_ = info; | |
| 344 VisitStatements(fun->body()); | |
| 345 function_ = NULL; | |
| 346 info_ = NULL; | |
|
fschneider
2010/01/29 13:02:29
Maybe I miss something here. Why do we need to res
| |
| 347 } | |
| 348 | |
| 349 | |
| 350 void FastCodeGenerator::VisitDeclaration(Declaration* decl) { | |
| 351 UNREACHABLE(); | |
| 352 } | |
| 353 | |
| 354 | |
| 355 void FastCodeGenerator::VisitBlock(Block* stmt) { | |
| 356 VisitStatements(stmt->statements()); | |
| 357 } | |
| 358 | |
| 359 | |
| 360 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | |
| 361 Visit(stmt->expression()); | |
| 362 } | |
| 363 | |
| 364 | |
| 365 void FastCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { | |
| 366 // Nothing to do. | |
| 367 } | |
| 368 | |
| 369 | |
| 370 void FastCodeGenerator::VisitIfStatement(IfStatement* stmt) { | |
| 371 UNREACHABLE(); | |
| 372 } | |
| 373 | |
| 374 | |
| 375 void FastCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) { | |
| 376 UNREACHABLE(); | |
| 377 } | |
| 378 | |
| 379 | |
| 380 void FastCodeGenerator::VisitBreakStatement(BreakStatement* stmt) { | |
| 381 UNREACHABLE(); | |
| 382 } | |
| 383 | |
| 384 | |
| 385 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | |
| 386 UNREACHABLE(); | |
| 387 } | |
| 388 | |
| 389 | |
| 390 void FastCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) { | |
| 391 UNREACHABLE(); | |
| 392 } | |
| 393 | |
| 394 | |
| 395 void FastCodeGenerator::VisitWithExitStatement(WithExitStatement* stmt) { | |
| 396 UNREACHABLE(); | |
| 397 } | |
| 398 | |
| 399 | |
| 400 void FastCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { | |
| 401 UNREACHABLE(); | |
| 402 } | |
| 403 | |
| 404 | |
| 405 void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { | |
| 406 UNREACHABLE(); | |
| 407 } | |
| 408 | |
| 409 | |
| 410 void FastCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { | |
| 411 UNREACHABLE(); | |
| 412 } | |
| 413 | |
| 414 | |
| 415 void FastCodeGenerator::VisitForStatement(ForStatement* stmt) { | |
| 416 UNREACHABLE(); | |
| 417 } | |
| 418 | |
| 419 | |
| 420 void FastCodeGenerator::VisitForInStatement(ForInStatement* stmt) { | |
| 421 UNREACHABLE(); | |
| 422 } | |
| 423 | |
| 424 | |
| 425 void FastCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { | |
| 426 UNREACHABLE(); | |
| 427 } | |
| 428 | |
| 429 | |
| 430 void FastCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | |
| 431 UNREACHABLE(); | |
| 432 } | |
| 433 | |
| 434 | |
| 435 void FastCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { | |
| 436 UNREACHABLE(); | |
| 437 } | |
| 438 | |
| 439 | |
| 440 void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { | |
| 441 UNREACHABLE(); | |
| 442 } | |
| 443 | |
| 444 | |
| 445 void FastCodeGenerator::VisitFunctionBoilerplateLiteral( | |
| 446 FunctionBoilerplateLiteral* expr) { | |
| 447 UNREACHABLE(); | |
| 448 } | |
| 449 | |
| 450 | |
| 451 void FastCodeGenerator::VisitConditional(Conditional* expr) { | |
| 452 UNREACHABLE(); | |
| 453 } | |
| 454 | |
| 455 | |
| 456 void FastCodeGenerator::VisitSlot(Slot* expr) { | |
| 457 UNREACHABLE(); | |
| 458 } | |
| 459 | |
| 460 | |
| 461 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { | |
| 462 if (FLAG_print_ir) { | |
| 463 ASSERT(expr->var()->is_global() && !expr->var()->is_this()); | |
| 464 SmartPointer<char> name = expr->name()->ToCString(); | |
| 465 PrintF("%d: t%d = Global(%s)\n", expr->num(), expr->num(), *name); | |
| 466 } | |
| 467 } | |
| 468 | |
| 469 | |
| 470 void FastCodeGenerator::VisitLiteral(Literal* expr) { | |
| 471 UNREACHABLE(); | |
| 472 } | |
| 473 | |
| 474 | |
| 475 void FastCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { | |
| 476 UNREACHABLE(); | |
| 477 } | |
| 478 | |
| 479 | |
| 480 void FastCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | |
| 481 UNREACHABLE(); | |
| 482 } | |
| 483 | |
| 484 | |
| 485 void FastCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | |
| 486 UNREACHABLE(); | |
| 487 } | |
| 488 | |
| 489 | |
| 490 void FastCodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* expr) { | |
| 491 UNREACHABLE(); | |
| 492 } | |
| 493 | |
| 494 | |
| 495 void FastCodeGenerator::VisitAssignment(Assignment* expr) { | |
| 496 // Known to be a simple this property assignment. | |
| 497 Visit(expr->value()); | |
| 498 | |
| 499 if (FLAG_print_ir) { | |
| 500 Property* prop = expr->target()->AsProperty(); | |
| 501 ASSERT_NOT_NULL(prop); | |
| 502 ASSERT_NOT_NULL(prop->obj()->AsVariableProxy()); | |
| 503 ASSERT(prop->obj()->AsVariableProxy()->var()->is_this()); | |
| 504 ASSERT(prop->key()->IsPropertyName()); | |
| 505 Handle<String> key = | |
| 506 Handle<String>::cast(prop->key()->AsLiteral()->handle()); | |
| 507 SmartPointer<char> name = key->ToCString(); | |
| 508 PrintF("%d: t%d = Store(this, \"%s\", t%d)\n", | |
| 509 expr->num(), expr->num(), *name, expr->value()->num()); | |
| 510 } | |
| 511 } | |
| 512 | |
| 513 | |
| 514 void FastCodeGenerator::VisitThrow(Throw* expr) { | |
| 515 UNREACHABLE(); | |
| 516 } | |
| 517 | |
| 518 | |
| 519 void FastCodeGenerator::VisitProperty(Property* expr) { | |
| 520 UNREACHABLE(); | |
| 521 } | |
| 522 | |
| 523 | |
| 524 void FastCodeGenerator::VisitCall(Call* expr) { | |
| 525 UNREACHABLE(); | |
| 526 } | |
| 527 | |
| 528 | |
| 529 void FastCodeGenerator::VisitCallNew(CallNew* expr) { | |
| 530 UNREACHABLE(); | |
| 531 } | |
| 532 | |
| 533 | |
| 534 void FastCodeGenerator::VisitCallRuntime(CallRuntime* expr) { | |
| 535 UNREACHABLE(); | |
| 536 } | |
| 537 | |
| 538 | |
| 539 void FastCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { | |
| 540 UNREACHABLE(); | |
| 541 } | |
| 542 | |
| 543 | |
| 544 void FastCodeGenerator::VisitCountOperation(CountOperation* expr) { | |
| 545 UNREACHABLE(); | |
| 546 } | |
| 547 | |
| 548 | |
| 549 void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { | |
| 550 UNREACHABLE(); | |
| 551 } | |
| 552 | |
| 553 | |
| 554 void FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) { | |
| 555 UNREACHABLE(); | |
| 556 } | |
| 557 | |
| 558 | |
| 559 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { | |
| 560 UNREACHABLE(); | |
| 561 } | |
| 562 | |
| 325 } } // namespace v8::internal | 563 } } // namespace v8::internal |
| OLD | NEW |