| 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/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 ReturnComputation(call); | 665 ReturnComputation(call); |
| 666 } | 666 } |
| 667 | 667 |
| 668 | 668 |
| 669 // <Expression> ::= StaticCall { function: Function | 669 // <Expression> ::= StaticCall { function: Function |
| 670 // arguments: <ArgumentList> } | 670 // arguments: <ArgumentList> } |
| 671 void EffectGraphVisitor::VisitStaticCallNode(StaticCallNode* node) { | 671 void EffectGraphVisitor::VisitStaticCallNode(StaticCallNode* node) { |
| 672 int length = node->arguments()->length(); | 672 int length = node->arguments()->length(); |
| 673 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(length); | 673 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(length); |
| 674 TranslateArgumentList(*node->arguments(), temp_index(), values); | 674 TranslateArgumentList(*node->arguments(), temp_index(), values); |
| 675 StaticCallComp* call = new StaticCallComp(node, values); | 675 StaticCallComp* call = |
| 676 new StaticCallComp(node->token_index(), |
| 677 node->function(), |
| 678 node->arguments()->names(), |
| 679 values); |
| 676 ReturnComputation(call); | 680 ReturnComputation(call); |
| 677 } | 681 } |
| 678 | 682 |
| 679 | 683 |
| 680 void EffectGraphVisitor::VisitClosureCallNode(ClosureCallNode* node) { | 684 void EffectGraphVisitor::VisitClosureCallNode(ClosureCallNode* node) { |
| 681 Bailout("EffectGraphVisitor::VisitClosureCallNode"); | 685 Bailout("EffectGraphVisitor::VisitClosureCallNode"); |
| 682 } | 686 } |
| 683 | 687 |
| 684 | 688 |
| 685 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) { | 689 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) { |
| 686 Bailout("EffectGraphVisitor::VisitCloneContextNode"); | 690 Bailout("EffectGraphVisitor::VisitCloneContextNode"); |
| 687 } | 691 } |
| 688 | 692 |
| 689 | 693 |
| 690 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { | 694 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 691 Bailout("EffectGraphVisitor::VisitConstructorCallNode"); | 695 Bailout("EffectGraphVisitor::VisitConstructorCallNode"); |
| 692 } | 696 } |
| 693 | 697 |
| 694 | 698 |
| 699 void EffectGraphVisitor::BuildTypeArguments(ConstructorCallNode* node) { |
| 700 const Class& cls = Class::ZoneHandle(node->constructor().owner()); |
| 701 ASSERT(cls.HasTypeArguments()); |
| 702 if (node->type_arguments().IsNull() || |
| 703 node->type_arguments().IsInstantiated()) { |
| 704 AddInstruction( |
| 705 new BindInstr(temp_index(), new ConstantVal(node->type_arguments()))); |
| 706 if (node->constructor().IsFactory()) { |
| 707 UNIMPLEMENTED(); |
| 708 } else { |
| 709 // Null instantiator. |
| 710 AddInstruction(new BindInstr( |
| 711 temp_index() + 1, new ConstantVal(Object::ZoneHandle()))); |
| 712 } |
| 713 return; |
| 714 } |
| 715 Bailout("EffectGraphVisitor::BuildTypeArguments"); |
| 716 } |
| 717 |
| 718 |
| 719 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 720 if (node->constructor().IsFactory()) { |
| 721 Bailout("EffectGraphVisitor::VisitConstructorCallNode Factory"); |
| 722 } |
| 723 |
| 724 const Class& cls = Class::ZoneHandle(node->constructor().owner()); |
| 725 const bool requires_type_arguments = cls.HasTypeArguments(); |
| 726 if (requires_type_arguments) { |
| 727 BuildTypeArguments(node); |
| 728 } |
| 729 // t_n contains the allocated and initialized object. |
| 730 // t_n <- AllocateObject(class) |
| 731 // t_n+1 <- Pick(t_n) |
| 732 // t_n+2 <- ctor-arg |
| 733 // t_n+3... <- constructor arguments start here |
| 734 // StaticCall(constructor, t_n+1, t_n+2, ...) |
| 735 |
| 736 AllocateObjectComp* alloc_comp = new AllocateObjectComp(node); |
| 737 AddInstruction(new BindInstr(temp_index(), alloc_comp)); |
| 738 intptr_t result_index = AllocateTempIndex(); |
| 739 TempVal* alloc_value = new TempVal(result_index); |
| 740 TempVal* dup_alloc_value = new TempVal(result_index + 1); |
| 741 TempVal* ctor_arg_value = new TempVal(result_index + 2); |
| 742 AddInstruction( |
| 743 new PickTempInstr(dup_alloc_value->index(), alloc_value->index())); |
| 744 |
| 745 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(); |
| 746 values->Add(dup_alloc_value); |
| 747 const Smi& ctor_arg = Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)); |
| 748 AddInstruction( |
| 749 new BindInstr(ctor_arg_value->index(), new ConstantVal(ctor_arg))); |
| 750 values->Add(ctor_arg_value); |
| 751 TranslateArgumentList(*node->arguments(), result_index + 3, values); |
| 752 StaticCallComp* call = |
| 753 new StaticCallComp(node->token_index(), |
| 754 node->constructor(), |
| 755 node->arguments()->names(), |
| 756 values); |
| 757 AddInstruction(new DoInstr(call)); |
| 758 ReturnValue(alloc_value); |
| 759 } |
| 760 |
| 761 |
| 695 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { | 762 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { |
| 696 ArgumentGraphVisitor for_receiver(owner(), temp_index()); | 763 ArgumentGraphVisitor for_receiver(owner(), temp_index()); |
| 697 node->receiver()->Visit(&for_receiver); | 764 node->receiver()->Visit(&for_receiver); |
| 698 Append(for_receiver); | 765 Append(for_receiver); |
| 699 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); | 766 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); |
| 700 arguments->Add(for_receiver.value()); | 767 arguments->Add(for_receiver.value()); |
| 701 const String& name = | 768 const String& name = |
| 702 String::ZoneHandle(Field::GetterSymbol(node->field_name())); | 769 String::ZoneHandle(Field::GetterSymbol(node->field_name())); |
| 703 InstanceCallComp* call = | 770 InstanceCallComp* call = |
| 704 new InstanceCallComp(node->id(), node->token_index(), name, | 771 new InstanceCallComp(node->id(), node->token_index(), name, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 } | 1033 } |
| 967 } | 1034 } |
| 968 | 1035 |
| 969 | 1036 |
| 970 void FlowGraphPrinter::VisitTemp(TempVal* val) { | 1037 void FlowGraphPrinter::VisitTemp(TempVal* val) { |
| 971 OS::Print("t%d", val->index()); | 1038 OS::Print("t%d", val->index()); |
| 972 } | 1039 } |
| 973 | 1040 |
| 974 | 1041 |
| 975 void FlowGraphPrinter::VisitConstant(ConstantVal* val) { | 1042 void FlowGraphPrinter::VisitConstant(ConstantVal* val) { |
| 976 OS::Print("#%s", val->instance().ToCString()); | 1043 OS::Print("#%s", val->value().ToCString()); |
| 977 } | 1044 } |
| 978 | 1045 |
| 979 | 1046 |
| 980 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) { | 1047 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) { |
| 981 OS::Print("AssertAssignable("); | 1048 OS::Print("AssertAssignable("); |
| 982 comp->value()->Accept(this); | 1049 comp->value()->Accept(this); |
| 983 OS::Print(", %s)", comp->type().ToCString()); | 1050 OS::Print(", %s)", comp->type().ToCString()); |
| 984 } | 1051 } |
| 985 | 1052 |
| 986 | 1053 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 } | 1157 } |
| 1091 | 1158 |
| 1092 | 1159 |
| 1093 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) { | 1160 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) { |
| 1094 comp->value()->Accept(this); | 1161 comp->value()->Accept(this); |
| 1095 OS::Print(" %s %s", | 1162 OS::Print(" %s %s", |
| 1096 comp->negate_result() ? "ISNOT" : "IS", | 1163 comp->negate_result() ? "ISNOT" : "IS", |
| 1097 String::Handle(comp->type().Name()).ToCString()); | 1164 String::Handle(comp->type().Name()).ToCString()); |
| 1098 } | 1165 } |
| 1099 | 1166 |
| 1167 void FlowGraphPrinter::VisitAllocateObject(AllocateObjectComp* comp) { |
| 1168 OS::Print("AllocateObject(%s)", |
| 1169 Class::Handle(comp->constructor().owner()).ToCString()); |
| 1170 } |
| 1171 |
| 1172 |
| 1100 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { | 1173 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { |
| 1101 OS::Print("%2d: [join]", instr->block_number()); | 1174 OS::Print("%2d: [join]", instr->block_number()); |
| 1102 } | 1175 } |
| 1103 | 1176 |
| 1104 | 1177 |
| 1105 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { | 1178 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { |
| 1106 OS::Print("%2d: [target]", instr->block_number()); | 1179 OS::Print("%2d: [target]", instr->block_number()); |
| 1107 } | 1180 } |
| 1108 | 1181 |
| 1109 | 1182 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 char* chars = reinterpret_cast<char*>( | 1249 char* chars = reinterpret_cast<char*>( |
| 1177 Isolate::Current()->current_zone()->Allocate(len)); | 1250 Isolate::Current()->current_zone()->Allocate(len)); |
| 1178 OS::SNPrint(chars, len, kFormat, function_name, reason); | 1251 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 1179 const Error& error = Error::Handle( | 1252 const Error& error = Error::Handle( |
| 1180 LanguageError::New(String::Handle(String::New(chars)))); | 1253 LanguageError::New(String::Handle(String::New(chars)))); |
| 1181 Isolate::Current()->long_jump_base()->Jump(1, error); | 1254 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 1182 } | 1255 } |
| 1183 | 1256 |
| 1184 | 1257 |
| 1185 } // namespace dart | 1258 } // namespace dart |
| OLD | NEW |