| 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 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 node->constructor(), | 928 node->constructor(), |
| 929 node->arguments()->names(), | 929 node->arguments()->names(), |
| 930 factory_arguments); | 930 factory_arguments); |
| 931 ReturnComputation(call); | 931 ReturnComputation(call); |
| 932 return; | 932 return; |
| 933 } | 933 } |
| 934 Bailout("EffectGraphVisitor::VisitConstructorCallNode"); | 934 Bailout("EffectGraphVisitor::VisitConstructorCallNode"); |
| 935 } | 935 } |
| 936 | 936 |
| 937 | 937 |
| 938 Value* EffectGraphVisitor::GenerateInstantiatorTypeArguments( |
| 939 intptr_t token_index, intptr_t value_index) { |
| 940 const Class& instantiator_class = Class::Handle( |
| 941 owner()->parsed_function().function().owner()); |
| 942 if (instantiator_class.NumTypeParameters() == 0) { |
| 943 // The type arguments are compile time constants. |
| 944 AbstractTypeArguments& type_arguments = AbstractTypeArguments::ZoneHandle(); |
| 945 // TODO(regis): Temporary type should be allocated in new gen heap. |
| 946 Type& type = Type::Handle( |
| 947 Type::New(instantiator_class, type_arguments, token_index)); |
| 948 type ^= ClassFinalizer::FinalizeType( |
| 949 instantiator_class, type, ClassFinalizer::kFinalizeWellFormed); |
| 950 type_arguments = type.arguments(); |
| 951 AddInstruction(new BindInstr(value_index, new ConstantVal(type_arguments))); |
| 952 return new TempVal(value_index); |
| 953 } |
| 954 ASSERT(owner()->parsed_function().instantiator() != NULL); |
| 955 ValueGraphVisitor for_instantiator(owner(), value_index); |
| 956 owner()->parsed_function().instantiator()->Visit(&for_instantiator); |
| 957 Append(for_instantiator); |
| 958 Function& outer_function = |
| 959 Function::Handle(owner()->parsed_function().function().raw()); |
| 960 while (outer_function.IsLocalFunction()) { |
| 961 outer_function = outer_function.parent_function(); |
| 962 } |
| 963 if (outer_function.IsFactory()) { |
| 964 // All OK. |
| 965 return for_instantiator.value(); |
| 966 } |
| 967 |
| 968 // The instantiator is the receiver of the caller, which is not a factory. |
| 969 // The receiver cannot be null; extract its AbstractTypeArguments object. |
| 970 // Note that in the factory case, the instantiator is the first parameter |
| 971 // of the factory, i.e. already an AbstractTypeArguments object. |
| 972 intptr_t type_arguments_instance_field_offset = |
| 973 instantiator_class.type_arguments_instance_field_offset(); |
| 974 ASSERT(type_arguments_instance_field_offset != Class::kNoTypeArguments); |
| 975 |
| 976 NativeLoadFieldComp* load = new NativeLoadFieldComp( |
| 977 for_instantiator.value(), type_arguments_instance_field_offset); |
| 978 AddInstruction(new BindInstr(value_index, load)); |
| 979 return new TempVal(value_index); |
| 980 } |
| 981 |
| 982 |
| 983 |
| 938 void EffectGraphVisitor::BuildTypeArguments(ConstructorCallNode* node, | 984 void EffectGraphVisitor::BuildTypeArguments(ConstructorCallNode* node, |
| 939 ZoneGrowableArray<Value*>* args) { | 985 ZoneGrowableArray<Value*>* args) { |
| 940 const Class& cls = Class::ZoneHandle(node->constructor().owner()); | 986 const Class& cls = Class::ZoneHandle(node->constructor().owner()); |
| 941 ASSERT(cls.HasTypeArguments() || node->constructor().IsFactory()); | 987 ASSERT(cls.HasTypeArguments() || node->constructor().IsFactory()); |
| 942 if (node->type_arguments().IsNull() || | 988 if (node->type_arguments().IsNull() || |
| 943 node->type_arguments().IsInstantiated()) { | 989 node->type_arguments().IsInstantiated()) { |
| 944 AddInstruction( | 990 AddInstruction( |
| 945 new BindInstr(temp_index(), new ConstantVal(node->type_arguments()))); | 991 new BindInstr(temp_index(), new ConstantVal(node->type_arguments()))); |
| 946 args->Add(new TempVal(temp_index())); | 992 args->Add(new TempVal(temp_index())); |
| 947 if (!node->constructor().IsFactory()) { | 993 if (!node->constructor().IsFactory()) { |
| 948 // Null instantiator. | 994 // Null instantiator. |
| 949 AddInstruction(new BindInstr( | 995 AddInstruction(new BindInstr( |
| 950 temp_index() + 1, new ConstantVal(Object::ZoneHandle()))); | 996 temp_index() + 1, new ConstantVal(Object::ZoneHandle()))); |
| 951 args->Add(new TempVal(temp_index() + 1)); | 997 args->Add(new TempVal(temp_index() + 1)); |
| 952 } | 998 } |
| 953 return; | 999 return; |
| 954 } | 1000 } |
| 955 Bailout("EffectGraphVisitor::BuildTypeArguments"); | 1001 if (!node->constructor().IsFactory()) { |
| 1002 // Place holder instruction as ExtractTypeArgumentsComp returns two values. |
| 1003 AddInstruction(new BindInstr(temp_index(), |
| 1004 new ConstantVal(Object::ZoneHandle()))); |
| 1005 } |
| 1006 // The type arguments are uninstantiated. |
| 1007 Value* instantiator_value = |
| 1008 GenerateInstantiatorTypeArguments(node->token_index(), temp_index() + 1); |
| 1009 ExtractTypeArgumentsComp* extract = new ExtractTypeArgumentsComp( |
| 1010 node, instantiator_value); |
| 1011 AddInstruction(new BindInstr(temp_index() + 1, extract)); |
| 1012 if (node->constructor().IsFactory()) { |
| 1013 args->Add(new TempVal(temp_index())); |
| 1014 } else { |
| 1015 args->Add(new TempVal(temp_index())); |
| 1016 args->Add(new TempVal(temp_index() + 1)); |
| 1017 } |
| 956 } | 1018 } |
| 957 | 1019 |
| 958 | 1020 |
| 959 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { | 1021 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 960 if (node->constructor().IsFactory()) { | 1022 if (node->constructor().IsFactory()) { |
| 961 EffectGraphVisitor::VisitConstructorCallNode(node); | 1023 EffectGraphVisitor::VisitConstructorCallNode(node); |
| 962 return; | 1024 return; |
| 963 } | 1025 } |
| 964 | 1026 |
| 965 const Class& cls = Class::ZoneHandle(node->constructor().owner()); | 1027 const Class& cls = Class::ZoneHandle(node->constructor().owner()); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 } | 1507 } |
| 1446 OS::Print(")"); | 1508 OS::Print(")"); |
| 1447 } | 1509 } |
| 1448 | 1510 |
| 1449 | 1511 |
| 1450 void FlowGraphPrinter::VisitCreateClosure(CreateClosureComp* comp) { | 1512 void FlowGraphPrinter::VisitCreateClosure(CreateClosureComp* comp) { |
| 1451 OS::Print("CreateClosure(%s)", comp->function().ToCString()); | 1513 OS::Print("CreateClosure(%s)", comp->function().ToCString()); |
| 1452 } | 1514 } |
| 1453 | 1515 |
| 1454 | 1516 |
| 1517 void FlowGraphPrinter::VisitNativeLoadField(NativeLoadFieldComp* comp) { |
| 1518 OS::Print("NativeLoadField("); |
| 1519 comp->value()->Accept(this); |
| 1520 OS::Print(", %d)", comp->offset_in_bytes()); |
| 1521 } |
| 1522 |
| 1523 |
| 1524 void FlowGraphPrinter::VisitExtractTypeArguments( |
| 1525 ExtractTypeArgumentsComp* comp) { |
| 1526 OS::Print("ExtractTypeArguments("); |
| 1527 comp->instantiator()->Accept(this); |
| 1528 OS::Print(")"); |
| 1529 } |
| 1530 |
| 1531 |
| 1455 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { | 1532 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { |
| 1456 OS::Print("%2d: [join]", instr->block_number()); | 1533 OS::Print("%2d: [join]", instr->block_number()); |
| 1457 } | 1534 } |
| 1458 | 1535 |
| 1459 | 1536 |
| 1460 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { | 1537 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { |
| 1461 OS::Print("%2d: [target]", instr->block_number()); | 1538 OS::Print("%2d: [target]", instr->block_number()); |
| 1462 } | 1539 } |
| 1463 | 1540 |
| 1464 | 1541 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 char* chars = reinterpret_cast<char*>( | 1609 char* chars = reinterpret_cast<char*>( |
| 1533 Isolate::Current()->current_zone()->Allocate(len)); | 1610 Isolate::Current()->current_zone()->Allocate(len)); |
| 1534 OS::SNPrint(chars, len, kFormat, function_name, reason); | 1611 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 1535 const Error& error = Error::Handle( | 1612 const Error& error = Error::Handle( |
| 1536 LanguageError::New(String::Handle(String::New(chars)))); | 1613 LanguageError::New(String::Handle(String::New(chars)))); |
| 1537 Isolate::Current()->long_jump_base()->Jump(1, error); | 1614 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 1538 } | 1615 } |
| 1539 | 1616 |
| 1540 | 1617 |
| 1541 } // namespace dart | 1618 } // namespace dart |
| OLD | NEW |