| 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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 ReturnComputation(call); | 842 ReturnComputation(call); |
| 843 } | 843 } |
| 844 | 844 |
| 845 | 845 |
| 846 // <Expression> ::= StaticCall { function: Function | 846 // <Expression> ::= StaticCall { function: Function |
| 847 // arguments: <ArgumentList> } | 847 // arguments: <ArgumentList> } |
| 848 void EffectGraphVisitor::VisitStaticCallNode(StaticCallNode* node) { | 848 void EffectGraphVisitor::VisitStaticCallNode(StaticCallNode* node) { |
| 849 int length = node->arguments()->length(); | 849 int length = node->arguments()->length(); |
| 850 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(length); | 850 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(length); |
| 851 TranslateArgumentList(*node->arguments(), temp_index(), values); | 851 TranslateArgumentList(*node->arguments(), temp_index(), values); |
| 852 StaticCallComp* call = new StaticCallComp(node, values); | 852 StaticCallComp* call = |
| 853 new StaticCallComp(node->token_index(), |
| 854 node->function(), |
| 855 node->arguments()->names(), |
| 856 values); |
| 853 ReturnComputation(call); | 857 ReturnComputation(call); |
| 854 } | 858 } |
| 855 | 859 |
| 856 | 860 |
| 857 void EffectGraphVisitor::VisitClosureCallNode(ClosureCallNode* node) { | 861 void EffectGraphVisitor::VisitClosureCallNode(ClosureCallNode* node) { |
| 858 Bailout("EffectGraphVisitor::VisitClosureCallNode"); | 862 Bailout("EffectGraphVisitor::VisitClosureCallNode"); |
| 859 } | 863 } |
| 860 | 864 |
| 861 | 865 |
| 862 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) { | 866 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) { |
| 863 Bailout("EffectGraphVisitor::VisitCloneContextNode"); | 867 Bailout("EffectGraphVisitor::VisitCloneContextNode"); |
| 864 } | 868 } |
| 865 | 869 |
| 866 | 870 |
| 867 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { | 871 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 868 Bailout("EffectGraphVisitor::VisitConstructorCallNode"); | 872 Bailout("EffectGraphVisitor::VisitConstructorCallNode"); |
| 869 } | 873 } |
| 870 | 874 |
| 871 | 875 |
| 876 void EffectGraphVisitor::BuildTypeArguments(ConstructorCallNode* node, |
| 877 ZoneGrowableArray<Value*>* args) { |
| 878 const Class& cls = Class::ZoneHandle(node->constructor().owner()); |
| 879 ASSERT(cls.HasTypeArguments()); |
| 880 if (node->type_arguments().IsNull() || |
| 881 node->type_arguments().IsInstantiated()) { |
| 882 AddInstruction( |
| 883 new BindInstr(temp_index(), new ConstantVal(node->type_arguments()))); |
| 884 args->Add(new TempVal(temp_index())); |
| 885 if (node->constructor().IsFactory()) { |
| 886 UNIMPLEMENTED(); |
| 887 } else { |
| 888 // Null instantiator. |
| 889 AddInstruction(new BindInstr( |
| 890 temp_index() + 1, new ConstantVal(Object::ZoneHandle()))); |
| 891 args->Add(new TempVal(temp_index() + 1)); |
| 892 } |
| 893 return; |
| 894 } |
| 895 Bailout("EffectGraphVisitor::BuildTypeArguments"); |
| 896 } |
| 897 |
| 898 |
| 899 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 900 if (node->constructor().IsFactory()) { |
| 901 Bailout("EffectGraphVisitor::VisitConstructorCallNode Factory"); |
| 902 } |
| 903 |
| 904 const Class& cls = Class::ZoneHandle(node->constructor().owner()); |
| 905 const bool requires_type_arguments = cls.HasTypeArguments(); |
| 906 ZoneGrowableArray<Value*>* allocate_arguments = |
| 907 new ZoneGrowableArray<Value*>(); |
| 908 |
| 909 if (requires_type_arguments) { |
| 910 BuildTypeArguments(node, allocate_arguments); |
| 911 } |
| 912 // t_n contains the allocated and initialized object. |
| 913 // t_n <- AllocateObject(class) |
| 914 // t_n+1 <- Pick(t_n) |
| 915 // t_n+2 <- ctor-arg |
| 916 // t_n+3... <- constructor arguments start here |
| 917 // StaticCall(constructor, t_n+1, t_n+2, ...) |
| 918 |
| 919 AllocateObjectComp* alloc_comp = |
| 920 new AllocateObjectComp(node, allocate_arguments); |
| 921 AddInstruction(new BindInstr(temp_index(), alloc_comp)); |
| 922 intptr_t result_index = AllocateTempIndex(); |
| 923 TempVal* alloc_value = new TempVal(result_index); |
| 924 TempVal* dup_alloc_value = new TempVal(result_index + 1); |
| 925 TempVal* ctor_arg_value = new TempVal(result_index + 2); |
| 926 AddInstruction( |
| 927 new PickTempInstr(dup_alloc_value->index(), alloc_value->index())); |
| 928 |
| 929 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(); |
| 930 values->Add(dup_alloc_value); |
| 931 const Smi& ctor_arg = Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)); |
| 932 AddInstruction( |
| 933 new BindInstr(ctor_arg_value->index(), new ConstantVal(ctor_arg))); |
| 934 values->Add(ctor_arg_value); |
| 935 TranslateArgumentList(*node->arguments(), result_index + 3, values); |
| 936 StaticCallComp* call = |
| 937 new StaticCallComp(node->token_index(), |
| 938 node->constructor(), |
| 939 node->arguments()->names(), |
| 940 values); |
| 941 AddInstruction(new DoInstr(call)); |
| 942 ReturnValue(alloc_value); |
| 943 } |
| 944 |
| 945 |
| 872 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { | 946 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { |
| 873 ArgumentGraphVisitor for_receiver(owner(), temp_index()); | 947 ArgumentGraphVisitor for_receiver(owner(), temp_index()); |
| 874 node->receiver()->Visit(&for_receiver); | 948 node->receiver()->Visit(&for_receiver); |
| 875 Append(for_receiver); | 949 Append(for_receiver); |
| 876 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); | 950 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); |
| 877 arguments->Add(for_receiver.value()); | 951 arguments->Add(for_receiver.value()); |
| 878 const String& name = | 952 const String& name = |
| 879 String::ZoneHandle(Field::GetterSymbol(node->field_name())); | 953 String::ZoneHandle(Field::GetterSymbol(node->field_name())); |
| 880 InstanceCallComp* call = | 954 InstanceCallComp* call = |
| 881 new InstanceCallComp(node->id(), node->token_index(), name, | 955 new InstanceCallComp(node->id(), node->token_index(), name, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 } | 1217 } |
| 1144 } | 1218 } |
| 1145 | 1219 |
| 1146 | 1220 |
| 1147 void FlowGraphPrinter::VisitTemp(TempVal* val) { | 1221 void FlowGraphPrinter::VisitTemp(TempVal* val) { |
| 1148 OS::Print("t%d", val->index()); | 1222 OS::Print("t%d", val->index()); |
| 1149 } | 1223 } |
| 1150 | 1224 |
| 1151 | 1225 |
| 1152 void FlowGraphPrinter::VisitConstant(ConstantVal* val) { | 1226 void FlowGraphPrinter::VisitConstant(ConstantVal* val) { |
| 1153 OS::Print("#%s", val->instance().ToCString()); | 1227 OS::Print("#%s", val->value().ToCString()); |
| 1154 } | 1228 } |
| 1155 | 1229 |
| 1156 | 1230 |
| 1157 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) { | 1231 void FlowGraphPrinter::VisitAssertAssignable(AssertAssignableComp* comp) { |
| 1158 OS::Print("AssertAssignable("); | 1232 OS::Print("AssertAssignable("); |
| 1159 comp->value()->Accept(this); | 1233 comp->value()->Accept(this); |
| 1160 OS::Print(", %s)", comp->type().ToCString()); | 1234 OS::Print(", %s)", comp->type().ToCString()); |
| 1161 } | 1235 } |
| 1162 | 1236 |
| 1163 | 1237 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 | 1342 |
| 1269 | 1343 |
| 1270 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) { | 1344 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) { |
| 1271 comp->value()->Accept(this); | 1345 comp->value()->Accept(this); |
| 1272 OS::Print(" %s %s", | 1346 OS::Print(" %s %s", |
| 1273 comp->negate_result() ? "ISNOT" : "IS", | 1347 comp->negate_result() ? "ISNOT" : "IS", |
| 1274 String::Handle(comp->type().Name()).ToCString()); | 1348 String::Handle(comp->type().Name()).ToCString()); |
| 1275 } | 1349 } |
| 1276 | 1350 |
| 1277 | 1351 |
| 1352 void FlowGraphPrinter::VisitAllocateObject(AllocateObjectComp* comp) { |
| 1353 OS::Print("AllocateObject(%s", |
| 1354 Class::Handle(comp->constructor().owner()).ToCString()); |
| 1355 for (intptr_t i = 0; i < comp->arguments().length(); i++) { |
| 1356 OS::Print(", "); |
| 1357 comp->arguments()[i]->Accept(this); |
| 1358 } |
| 1359 OS::Print(")"); |
| 1360 } |
| 1361 |
| 1362 |
| 1278 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) { | 1363 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) { |
| 1279 OS::Print("CreateArray("); | 1364 OS::Print("CreateArray("); |
| 1280 for (int i = 0; i < comp->ElementCount(); ++i) { | 1365 for (int i = 0; i < comp->ElementCount(); ++i) { |
| 1281 if (i != 0) OS::Print(", "); | 1366 if (i != 0) OS::Print(", "); |
| 1282 comp->ElementAt(i)->Accept(this); | 1367 comp->ElementAt(i)->Accept(this); |
| 1283 } | 1368 } |
| 1284 OS::Print(")"); | 1369 OS::Print(")"); |
| 1285 } | 1370 } |
| 1286 | 1371 |
| 1287 | 1372 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 char* chars = reinterpret_cast<char*>( | 1449 char* chars = reinterpret_cast<char*>( |
| 1365 Isolate::Current()->current_zone()->Allocate(len)); | 1450 Isolate::Current()->current_zone()->Allocate(len)); |
| 1366 OS::SNPrint(chars, len, kFormat, function_name, reason); | 1451 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 1367 const Error& error = Error::Handle( | 1452 const Error& error = Error::Handle( |
| 1368 LanguageError::New(String::Handle(String::New(chars)))); | 1453 LanguageError::New(String::Handle(String::New(chars)))); |
| 1369 Isolate::Current()->long_jump_base()->Jump(1, error); | 1454 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 1370 } | 1455 } |
| 1371 | 1456 |
| 1372 | 1457 |
| 1373 } // namespace dart | 1458 } // namespace dart |
| OLD | NEW |