| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/code_descriptors.h" | 8 #include "vm/code_descriptors.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 type_arguments, | 500 type_arguments, |
| 501 node->right()->AsTypeNode()->type(), | 501 node->right()->AsTypeNode()->type(), |
| 502 (node->kind() == Token::kISNOT)); | 502 (node->kind() == Token::kISNOT)); |
| 503 ReturnComputation(instance_of); | 503 ReturnComputation(instance_of); |
| 504 } | 504 } |
| 505 | 505 |
| 506 | 506 |
| 507 // <Expression> :: Comparison { kind: Token::Kind | 507 // <Expression> :: Comparison { kind: Token::Kind |
| 508 // left: <Expression> | 508 // left: <Expression> |
| 509 // right: <Expression> } | 509 // right: <Expression> } |
| 510 // TODO(srdjan): Implement new equality. |
| 510 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { | 511 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { |
| 511 if (Token::IsInstanceofOperator(node->kind())) { | 512 if (Token::IsInstanceofOperator(node->kind())) { |
| 512 BuildInstanceOf(node); | 513 BuildInstanceOf(node); |
| 513 return; | 514 return; |
| 514 } | 515 } |
| 515 if ((node->kind() == Token::kEQ_STRICT) || | 516 if ((node->kind() == Token::kEQ_STRICT) || |
| 516 (node->kind() == Token::kNE_STRICT)) { | 517 (node->kind() == Token::kNE_STRICT)) { |
| 517 ValueGraphVisitor for_left_value(owner(), temp_index()); | 518 ValueGraphVisitor for_left_value(owner(), temp_index()); |
| 518 node->left()->Visit(&for_left_value); | 519 node->left()->Visit(&for_left_value); |
| 519 Append(for_left_value); | 520 Append(for_left_value); |
| 520 ValueGraphVisitor for_right_value(owner(), for_left_value.temp_index()); | 521 ValueGraphVisitor for_right_value(owner(), for_left_value.temp_index()); |
| 521 node->right()->Visit(&for_right_value); | 522 node->right()->Visit(&for_right_value); |
| 522 Append(for_right_value); | 523 Append(for_right_value); |
| 523 StrictCompareComp* comp = new StrictCompareComp( | 524 StrictCompareComp* comp = new StrictCompareComp( |
| 524 node->kind(), for_left_value.value(), for_right_value.value()); | 525 node->kind(), for_left_value.value(), for_right_value.value()); |
| 525 ReturnComputation(comp); | 526 ReturnComputation(comp); |
| 526 return; | 527 return; |
| 527 } | 528 } |
| 528 | 529 |
| 530 if ((node->kind() == Token::kEQ) || (node->kind() == Token::kNE)) { |
| 531 ValueGraphVisitor for_left_value(owner(), temp_index()); |
| 532 node->left()->Visit(&for_left_value); |
| 533 Append(for_left_value); |
| 534 ValueGraphVisitor for_right_value(owner(), for_left_value.temp_index()); |
| 535 node->right()->Visit(&for_right_value); |
| 536 Append(for_right_value); |
| 537 EqualityCompareComp* comp = new EqualityCompareComp( |
| 538 node->id(), node->token_index(), owner()->try_index(), |
| 539 for_left_value.value(), for_right_value.value()); |
| 540 if (node->kind() == Token::kEQ) { |
| 541 ReturnComputation(comp); |
| 542 } else { |
| 543 AddInstruction(new BindInstr(temp_index(), comp)); |
| 544 Value* eq_result = new TempVal(temp_index()); |
| 545 BooleanNegateComp* negate = new BooleanNegateComp(eq_result); |
| 546 ReturnComputation(negate); |
| 547 } |
| 548 return; |
| 549 } |
| 550 |
| 529 ArgumentGraphVisitor for_left_value(owner(), temp_index()); | 551 ArgumentGraphVisitor for_left_value(owner(), temp_index()); |
| 530 node->left()->Visit(&for_left_value); | 552 node->left()->Visit(&for_left_value); |
| 531 Append(for_left_value); | 553 Append(for_left_value); |
| 532 ArgumentGraphVisitor for_right_value(owner(), for_left_value.temp_index()); | 554 ArgumentGraphVisitor for_right_value(owner(), for_left_value.temp_index()); |
| 533 node->right()->Visit(&for_right_value); | 555 node->right()->Visit(&for_right_value); |
| 534 Append(for_right_value); | 556 Append(for_right_value); |
| 535 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(2); | 557 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(2); |
| 536 arguments->Add(for_left_value.value()); | 558 arguments->Add(for_left_value.value()); |
| 537 arguments->Add(for_right_value.value()); | 559 arguments->Add(for_right_value.value()); |
| 538 // 'kNE' is not overloadable, must implement as kEQ and negation. | 560 const String& name = String::ZoneHandle(String::NewSymbol(node->Name())); |
| 539 // Boolean negation '!' cannot be overloaded neither. | 561 InstanceCallComp* call = new InstanceCallComp( |
| 540 if (node->kind() == Token::kNE) { | 562 node->id(), node->token_index(), owner()->try_index(), name, |
| 541 const String& name = String::ZoneHandle(String::NewSymbol("==")); | 563 arguments, Array::ZoneHandle(), 2); |
| 542 InstanceCallComp* call_equal = new InstanceCallComp( | 564 ReturnComputation(call); |
| 543 node->id(), node->token_index(), owner()->try_index(), name, | |
| 544 arguments, Array::ZoneHandle(), 2); | |
| 545 AddInstruction(new BindInstr(temp_index(), call_equal)); | |
| 546 Value* eq_result = new TempVal(temp_index()); | |
| 547 if (FLAG_enable_type_checks) { | |
| 548 Bailout("GenerateConditionTypeCheck in kNE"); | |
| 549 } | |
| 550 BooleanNegateComp* negate = new BooleanNegateComp(eq_result); | |
| 551 ReturnComputation(negate); | |
| 552 } else { | |
| 553 const String& name = String::ZoneHandle(String::NewSymbol(node->Name())); | |
| 554 InstanceCallComp* call = new InstanceCallComp( | |
| 555 node->id(), node->token_index(), owner()->try_index(), name, | |
| 556 arguments, Array::ZoneHandle(), 2); | |
| 557 ReturnComputation(call); | |
| 558 } | |
| 559 } | 565 } |
| 560 | 566 |
| 561 | 567 |
| 562 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) { | 568 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) { |
| 563 // "!" cannot be overloaded, therefore do not call operator. | 569 // "!" cannot be overloaded, therefore do not call operator. |
| 564 if (node->kind() == Token::kNOT) { | 570 if (node->kind() == Token::kNOT) { |
| 565 ValueGraphVisitor for_value(owner(), temp_index()); | 571 ValueGraphVisitor for_value(owner(), temp_index()); |
| 566 node->operand()->Visit(&for_value); | 572 node->operand()->Visit(&for_value); |
| 567 Append(for_value); | 573 Append(for_value); |
| 568 if (FLAG_enable_type_checks) { | 574 if (FLAG_enable_type_checks) { |
| (...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2188 | 2194 |
| 2189 void FlowGraphPrinter::VisitStrictCompare(StrictCompareComp* comp) { | 2195 void FlowGraphPrinter::VisitStrictCompare(StrictCompareComp* comp) { |
| 2190 OS::Print("StrictCompare(%s, ", Token::Str(comp->kind())); | 2196 OS::Print("StrictCompare(%s, ", Token::Str(comp->kind())); |
| 2191 comp->left()->Accept(this); | 2197 comp->left()->Accept(this); |
| 2192 OS::Print(", "); | 2198 OS::Print(", "); |
| 2193 comp->right()->Accept(this); | 2199 comp->right()->Accept(this); |
| 2194 OS::Print(")"); | 2200 OS::Print(")"); |
| 2195 } | 2201 } |
| 2196 | 2202 |
| 2197 | 2203 |
| 2204 void FlowGraphPrinter::VisitEqualityCompare(EqualityCompareComp* comp) { |
| 2205 comp->left()->Accept(this); |
| 2206 OS::Print(" == "); |
| 2207 comp->right()->Accept(this); |
| 2208 } |
| 2209 |
| 2210 |
| 2198 | 2211 |
| 2199 void FlowGraphPrinter::VisitStaticCall(StaticCallComp* comp) { | 2212 void FlowGraphPrinter::VisitStaticCall(StaticCallComp* comp) { |
| 2200 OS::Print("StaticCall(%s", | 2213 OS::Print("StaticCall(%s", |
| 2201 String::Handle(comp->function().name()).ToCString()); | 2214 String::Handle(comp->function().name()).ToCString()); |
| 2202 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) { | 2215 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) { |
| 2203 OS::Print(", "); | 2216 OS::Print(", "); |
| 2204 comp->ArgumentAt(i)->Accept(this); | 2217 comp->ArgumentAt(i)->Accept(this); |
| 2205 } | 2218 } |
| 2206 OS::Print(")"); | 2219 OS::Print(")"); |
| 2207 } | 2220 } |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2602 char* chars = reinterpret_cast<char*>( | 2615 char* chars = reinterpret_cast<char*>( |
| 2603 Isolate::Current()->current_zone()->Allocate(len)); | 2616 Isolate::Current()->current_zone()->Allocate(len)); |
| 2604 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2617 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2605 const Error& error = Error::Handle( | 2618 const Error& error = Error::Handle( |
| 2606 LanguageError::New(String::Handle(String::New(chars)))); | 2619 LanguageError::New(String::Handle(String::New(chars)))); |
| 2607 Isolate::Current()->long_jump_base()->Jump(1, error); | 2620 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2608 } | 2621 } |
| 2609 | 2622 |
| 2610 | 2623 |
| 2611 } // namespace dart | 2624 } // namespace dart |
| OLD | NEW |