| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/ast.h" | 7 #include "src/ast.h" |
| 8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) { | 268 bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) { |
| 269 // Inline smi case inside loops, but not division and modulo which | 269 // Inline smi case inside loops, but not division and modulo which |
| 270 // are too complicated and take up too much space. | 270 // are too complicated and take up too much space. |
| 271 if (op == Token::DIV ||op == Token::MOD) return false; | 271 if (op == Token::DIV ||op == Token::MOD) return false; |
| 272 if (FLAG_always_inline_smi_code) return true; | 272 if (FLAG_always_inline_smi_code) return true; |
| 273 return loop_depth_ > 0; | 273 return loop_depth_ > 0; |
| 274 } | 274 } |
| 275 | 275 |
| 276 | 276 |
| 277 void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
| 278 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 279 } |
| 280 |
| 281 |
| 282 void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
| 283 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 284 codegen()->GetVar(result_register(), var); |
| 285 } |
| 286 |
| 287 |
| 288 void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
| 289 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 290 // For simplicity we always test the accumulator register. |
| 291 codegen()->GetVar(result_register(), var); |
| 292 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
| 293 codegen()->DoTest(this); |
| 294 } |
| 295 |
| 296 |
| 277 void FullCodeGenerator::EffectContext::Plug(Register reg) const { | 297 void FullCodeGenerator::EffectContext::Plug(Register reg) const { |
| 278 } | 298 } |
| 279 | 299 |
| 280 | 300 |
| 281 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { | 301 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { |
| 282 __ Move(result_register(), reg); | 302 __ Move(result_register(), reg); |
| 283 } | 303 } |
| 284 | 304 |
| 285 | 305 |
| 286 void FullCodeGenerator::StackValueContext::Plug(Register reg) const { | 306 void FullCodeGenerator::StackValueContext::Plug(Register reg) const { |
| 287 __ Push(reg); | 307 __ Push(reg); |
| 288 } | 308 } |
| 289 | 309 |
| 290 | 310 |
| 291 void FullCodeGenerator::TestContext::Plug(Register reg) const { | 311 void FullCodeGenerator::TestContext::Plug(Register reg) const { |
| 292 // For simplicity we always test the accumulator register. | 312 // For simplicity we always test the accumulator register. |
| 293 __ Move(result_register(), reg); | 313 __ Move(result_register(), reg); |
| 294 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); | 314 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
| 295 codegen()->DoTest(this); | 315 codegen()->DoTest(this); |
| 296 } | 316 } |
| 297 | 317 |
| 298 | 318 |
| 319 void FullCodeGenerator::EffectContext::Plug(bool flag) const {} |
| 320 |
| 321 |
| 299 void FullCodeGenerator::EffectContext::PlugTOS() const { | 322 void FullCodeGenerator::EffectContext::PlugTOS() const { |
| 300 __ Drop(1); | 323 __ Drop(1); |
| 301 } | 324 } |
| 302 | 325 |
| 303 | 326 |
| 304 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { | 327 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { |
| 305 __ Pop(result_register()); | 328 __ Pop(result_register()); |
| 306 } | 329 } |
| 307 | 330 |
| 308 | 331 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 isolate()->factory()->NewFixedArray(globals_->length(), TENURED); | 410 isolate()->factory()->NewFixedArray(globals_->length(), TENURED); |
| 388 for (int i = 0; i < globals_->length(); ++i) | 411 for (int i = 0; i < globals_->length(); ++i) |
| 389 array->set(i, *globals_->at(i)); | 412 array->set(i, *globals_->at(i)); |
| 390 DeclareGlobals(array); | 413 DeclareGlobals(array); |
| 391 } | 414 } |
| 392 | 415 |
| 393 globals_ = saved_globals; | 416 globals_ = saved_globals; |
| 394 } | 417 } |
| 395 | 418 |
| 396 | 419 |
| 420 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 421 VariableProxy* proxy = declaration->proxy(); |
| 422 Variable* variable = proxy->var(); |
| 423 switch (variable->location()) { |
| 424 case VariableLocation::GLOBAL: |
| 425 case VariableLocation::UNALLOCATED: |
| 426 // TODO(rossberg) |
| 427 break; |
| 428 |
| 429 case VariableLocation::CONTEXT: { |
| 430 Comment cmnt(masm_, "[ ImportDeclaration"); |
| 431 EmitDebugCheckDeclarationContext(variable); |
| 432 // TODO(rossberg) |
| 433 break; |
| 434 } |
| 435 |
| 436 case VariableLocation::PARAMETER: |
| 437 case VariableLocation::LOCAL: |
| 438 case VariableLocation::LOOKUP: |
| 439 UNREACHABLE(); |
| 440 } |
| 441 } |
| 442 |
| 443 |
| 444 void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 445 // TODO(rossberg) |
| 446 } |
| 447 |
| 448 |
| 449 void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 450 Comment cmnt(masm_, "[ VariableProxy"); |
| 451 EmitVariableLoad(expr); |
| 452 } |
| 453 |
| 454 |
| 397 int FullCodeGenerator::DeclareGlobalsFlags() { | 455 int FullCodeGenerator::DeclareGlobalsFlags() { |
| 398 DCHECK(DeclareGlobalsLanguageMode::is_valid(language_mode())); | 456 DCHECK(DeclareGlobalsLanguageMode::is_valid(language_mode())); |
| 399 return DeclareGlobalsEvalFlag::encode(is_eval()) | | 457 return DeclareGlobalsEvalFlag::encode(is_eval()) | |
| 400 DeclareGlobalsNativeFlag::encode(is_native()) | | 458 DeclareGlobalsNativeFlag::encode(is_native()) | |
| 401 DeclareGlobalsLanguageMode::encode(language_mode()); | 459 DeclareGlobalsLanguageMode::encode(language_mode()); |
| 402 } | 460 } |
| 403 | 461 |
| 404 | 462 |
| 463 void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
| 464 // Load the arguments on the stack and call the stub. |
| 465 SubStringStub stub(isolate()); |
| 466 ZoneList<Expression*>* args = expr->arguments(); |
| 467 DCHECK(args->length() == 3); |
| 468 VisitForStackValue(args->at(0)); |
| 469 VisitForStackValue(args->at(1)); |
| 470 VisitForStackValue(args->at(2)); |
| 471 __ CallStub(&stub); |
| 472 context()->Plug(result_register()); |
| 473 } |
| 474 |
| 475 |
| 476 void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
| 477 // Load the arguments on the stack and call the stub. |
| 478 RegExpExecStub stub(isolate()); |
| 479 ZoneList<Expression*>* args = expr->arguments(); |
| 480 DCHECK(args->length() == 4); |
| 481 VisitForStackValue(args->at(0)); |
| 482 VisitForStackValue(args->at(1)); |
| 483 VisitForStackValue(args->at(2)); |
| 484 VisitForStackValue(args->at(3)); |
| 485 __ CallStub(&stub); |
| 486 context()->Plug(result_register()); |
| 487 } |
| 488 |
| 489 |
| 490 void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
| 491 // Load the arguments on the stack and call the runtime function. |
| 492 ZoneList<Expression*>* args = expr->arguments(); |
| 493 DCHECK(args->length() == 2); |
| 494 VisitForStackValue(args->at(0)); |
| 495 VisitForStackValue(args->at(1)); |
| 496 |
| 497 MathPowStub stub(isolate(), MathPowStub::ON_STACK); |
| 498 __ CallStub(&stub); |
| 499 context()->Plug(result_register()); |
| 500 } |
| 501 |
| 502 |
| 503 void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 504 ZoneList<Expression*>* args = expr->arguments(); |
| 505 DCHECK_EQ(2, args->length()); |
| 506 |
| 507 VisitForStackValue(args->at(0)); |
| 508 VisitForStackValue(args->at(1)); |
| 509 |
| 510 StringCompareStub stub(isolate()); |
| 511 __ CallStub(&stub); |
| 512 context()->Plug(result_register()); |
| 513 } |
| 514 |
| 515 |
| 405 bool RecordStatementPosition(MacroAssembler* masm, int pos) { | 516 bool RecordStatementPosition(MacroAssembler* masm, int pos) { |
| 406 if (pos == RelocInfo::kNoPosition) return false; | 517 if (pos == RelocInfo::kNoPosition) return false; |
| 407 masm->positions_recorder()->RecordStatementPosition(pos); | 518 masm->positions_recorder()->RecordStatementPosition(pos); |
| 408 masm->positions_recorder()->RecordPosition(pos); | 519 masm->positions_recorder()->RecordPosition(pos); |
| 409 return masm->positions_recorder()->WriteRecordedPositions(); | 520 return masm->positions_recorder()->WriteRecordedPositions(); |
| 410 } | 521 } |
| 411 | 522 |
| 412 | 523 |
| 413 bool RecordPosition(MacroAssembler* masm, int pos) { | 524 bool RecordPosition(MacroAssembler* masm, int pos) { |
| 414 if (pos == RelocInfo::kNoPosition) return false; | 525 if (pos == RelocInfo::kNoPosition) return false; |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); | 1586 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); |
| 1476 codegen_->scope_ = saved_scope_; | 1587 codegen_->scope_ = saved_scope_; |
| 1477 } | 1588 } |
| 1478 | 1589 |
| 1479 | 1590 |
| 1480 #undef __ | 1591 #undef __ |
| 1481 | 1592 |
| 1482 | 1593 |
| 1483 } // namespace internal | 1594 } // namespace internal |
| 1484 } // namespace v8 | 1595 } // namespace v8 |
| OLD | NEW |