| 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 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 void EffectGraphVisitor::VisitArrayNode(ArrayNode* node) { | 1160 void EffectGraphVisitor::VisitArrayNode(ArrayNode* node) { |
| 1161 // Translate the array elements and collect their values. | 1161 // Translate the array elements and collect their values. |
| 1162 ZoneGrowableArray<Value*>* values = | 1162 ZoneGrowableArray<Value*>* values = |
| 1163 new ZoneGrowableArray<Value*>(node->length()); | 1163 new ZoneGrowableArray<Value*>(node->length()); |
| 1164 for (int i = 0; i < node->length(); ++i) { | 1164 for (int i = 0; i < node->length(); ++i) { |
| 1165 ValueGraphVisitor for_value(owner(), temp_index()); | 1165 ValueGraphVisitor for_value(owner(), temp_index()); |
| 1166 node->ElementAt(i)->Visit(&for_value); | 1166 node->ElementAt(i)->Visit(&for_value); |
| 1167 Append(for_value); | 1167 Append(for_value); |
| 1168 values->Add(for_value.value()); | 1168 values->Add(for_value.value()); |
| 1169 } | 1169 } |
| 1170 CreateArrayComp* create = new CreateArrayComp(node, | 1170 Value* element_type = new UseVal( |
| 1171 BuildInstantiatedTypeArguments(node->token_index(), |
| 1172 node->type_arguments())); |
| 1173 CreateArrayComp* create = new CreateArrayComp(node->token_index(), |
| 1171 owner()->try_index(), | 1174 owner()->try_index(), |
| 1172 values); | 1175 values, |
| 1176 element_type); |
| 1173 ReturnComputation(create); | 1177 ReturnComputation(create); |
| 1174 } | 1178 } |
| 1175 | 1179 |
| 1176 | 1180 |
| 1177 void EffectGraphVisitor::VisitClosureNode(ClosureNode* node) { | 1181 void EffectGraphVisitor::VisitClosureNode(ClosureNode* node) { |
| 1178 const Function& function = node->function(); | 1182 const Function& function = node->function(); |
| 1179 | 1183 |
| 1180 if (function.IsNonImplicitClosureFunction()) { | 1184 if (function.IsNonImplicitClosureFunction()) { |
| 1181 const ContextScope& context_scope = ContextScope::ZoneHandle( | 1185 const ContextScope& context_scope = ContextScope::ZoneHandle( |
| 1182 node->scope()->PreserveOuterScope(owner()->context_level())); | 1186 node->scope()->PreserveOuterScope(owner()->context_level())); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 node->arguments()->names(), | 1352 node->arguments()->names(), |
| 1349 values); | 1353 values); |
| 1350 AddInstruction(new DoInstr(call)); | 1354 AddInstruction(new DoInstr(call)); |
| 1351 } | 1355 } |
| 1352 | 1356 |
| 1353 | 1357 |
| 1354 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { | 1358 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 1355 if (node->constructor().IsFactory()) { | 1359 if (node->constructor().IsFactory()) { |
| 1356 ZoneGrowableArray<Value*>* factory_arguments = | 1360 ZoneGrowableArray<Value*>* factory_arguments = |
| 1357 new ZoneGrowableArray<Value*>(); | 1361 new ZoneGrowableArray<Value*>(); |
| 1358 factory_arguments->Add(new UseVal(BuildFactoryTypeArguments(node))); | 1362 factory_arguments->Add( |
| 1363 new UseVal(BuildInstantiatedTypeArguments(node->token_index(), |
| 1364 node->type_arguments()))); |
| 1359 ASSERT(factory_arguments->length() == 1); | 1365 ASSERT(factory_arguments->length() == 1); |
| 1360 TranslateArgumentList(*node->arguments(), factory_arguments); | 1366 TranslateArgumentList(*node->arguments(), factory_arguments); |
| 1361 StaticCallComp* call = | 1367 StaticCallComp* call = |
| 1362 new StaticCallComp(node->token_index(), | 1368 new StaticCallComp(node->token_index(), |
| 1363 owner()->try_index(), | 1369 owner()->try_index(), |
| 1364 node->constructor(), | 1370 node->constructor(), |
| 1365 node->arguments()->names(), | 1371 node->arguments()->names(), |
| 1366 factory_arguments); | 1372 factory_arguments); |
| 1367 ReturnComputation(call); | 1373 ReturnComputation(call); |
| 1368 return; | 1374 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 | 1425 |
| 1420 BindInstr* load = | 1426 BindInstr* load = |
| 1421 new BindInstr(new NativeLoadFieldComp( | 1427 new BindInstr(new NativeLoadFieldComp( |
| 1422 for_instantiator.value(), | 1428 for_instantiator.value(), |
| 1423 type_arguments_instance_field_offset)); | 1429 type_arguments_instance_field_offset)); |
| 1424 AddInstruction(load); | 1430 AddInstruction(load); |
| 1425 return new UseVal(load); | 1431 return new UseVal(load); |
| 1426 } | 1432 } |
| 1427 | 1433 |
| 1428 | 1434 |
| 1429 Definition* EffectGraphVisitor::BuildFactoryTypeArguments( | 1435 Definition* EffectGraphVisitor::BuildInstantiatedTypeArguments( |
| 1430 ConstructorCallNode* node) { | 1436 intptr_t token_index, |
| 1431 ASSERT(node->constructor().IsFactory()); | 1437 const AbstractTypeArguments& type_arguments) { |
| 1432 if (node->type_arguments().IsNull() || | 1438 if (type_arguments.IsNull() || type_arguments.IsInstantiated()) { |
| 1433 node->type_arguments().IsInstantiated()) { | |
| 1434 BindInstr* type_args = | 1439 BindInstr* type_args = |
| 1435 new BindInstr(new ConstantVal(node->type_arguments())); | 1440 new BindInstr(new ConstantVal(type_arguments)); |
| 1436 AddInstruction(type_args); | 1441 AddInstruction(type_args); |
| 1437 return type_args; | 1442 return type_args; |
| 1438 } | 1443 } |
| 1439 // The type arguments are uninstantiated. | 1444 // The type arguments are uninstantiated. |
| 1440 Value* instantiator_value = | 1445 Value* instantiator_value = BuildInstantiatorTypeArguments(token_index); |
| 1441 BuildInstantiatorTypeArguments(node->token_index()); | 1446 BindInstr* instantiate = |
| 1442 BindInstr* extract = | 1447 new BindInstr(new InstantiateTypeArgumentsComp(token_index, |
| 1443 new BindInstr(new ExtractFactoryTypeArgumentsComp(node, | 1448 owner()->try_index(), |
| 1444 owner()->try_index(), | 1449 type_arguments, |
| 1445 instantiator_value)); | 1450 instantiator_value)); |
| 1446 AddInstruction(extract); | 1451 AddInstruction(instantiate); |
| 1447 return extract; | 1452 return instantiate; |
| 1448 } | 1453 } |
| 1449 | 1454 |
| 1450 | 1455 |
| 1451 void EffectGraphVisitor::BuildConstructorTypeArguments( | 1456 void EffectGraphVisitor::BuildConstructorTypeArguments( |
| 1452 ConstructorCallNode* node, | 1457 ConstructorCallNode* node, |
| 1453 ZoneGrowableArray<Value*>* args) { | 1458 ZoneGrowableArray<Value*>* args) { |
| 1454 const Class& cls = Class::ZoneHandle(node->constructor().owner()); | 1459 const Class& cls = Class::ZoneHandle(node->constructor().owner()); |
| 1455 ASSERT(cls.HasTypeArguments() && !node->constructor().IsFactory()); | 1460 ASSERT(cls.HasTypeArguments() && !node->constructor().IsFactory()); |
| 1456 if (node->type_arguments().IsNull() || | 1461 if (node->type_arguments().IsNull() || |
| 1457 node->type_arguments().IsInstantiated()) { | 1462 node->type_arguments().IsInstantiated()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1472 // Place holder to hold uninstantiated constructor type arguments. | 1477 // Place holder to hold uninstantiated constructor type arguments. |
| 1473 BindInstr* placeholder = | 1478 BindInstr* placeholder = |
| 1474 new BindInstr(new ConstantVal(Object::ZoneHandle())); | 1479 new BindInstr(new ConstantVal(Object::ZoneHandle())); |
| 1475 AddInstruction(placeholder); | 1480 AddInstruction(placeholder); |
| 1476 Value* instantiator = | 1481 Value* instantiator = |
| 1477 BuildInstantiatorTypeArguments(node->token_index()); | 1482 BuildInstantiatorTypeArguments(node->token_index()); |
| 1478 ASSERT(instantiator->IsUse()); | 1483 ASSERT(instantiator->IsUse()); |
| 1479 PickTempInstr* duplicate_instantiator = | 1484 PickTempInstr* duplicate_instantiator = |
| 1480 new PickTempInstr(instantiator->AsUse()->definition()->temp_index()); | 1485 new PickTempInstr(instantiator->AsUse()->definition()->temp_index()); |
| 1481 AddInstruction(duplicate_instantiator); | 1486 AddInstruction(duplicate_instantiator); |
| 1482 BindInstr* extract_type_arguments = | 1487 BindInstr* extract_type_arguments = new BindInstr( |
| 1483 new BindInstr(new ExtractConstructorTypeArgumentsComp( | 1488 new ExtractConstructorTypeArgumentsComp( |
| 1484 node, new UseVal(duplicate_instantiator))); | 1489 node->token_index(), |
| 1490 owner()->try_index(), |
| 1491 node->type_arguments(), |
| 1492 new UseVal(duplicate_instantiator))); |
| 1485 AddInstruction(extract_type_arguments); | 1493 AddInstruction(extract_type_arguments); |
| 1486 AddInstruction(new TuckTempInstr(placeholder->temp_index(), | 1494 AddInstruction(new TuckTempInstr(placeholder->temp_index(), |
| 1487 extract_type_arguments->temp_index())); | 1495 extract_type_arguments->temp_index())); |
| 1488 BindInstr* extract_instantiator = | 1496 BindInstr* extract_instantiator = |
| 1489 new BindInstr(new ExtractConstructorInstantiatorComp( | 1497 new BindInstr(new ExtractConstructorInstantiatorComp( |
| 1490 node, | 1498 node, |
| 1491 instantiator, | 1499 instantiator, |
| 1492 new UseVal(extract_type_arguments))); | 1500 new UseVal(extract_type_arguments))); |
| 1493 AddInstruction(extract_instantiator); | 1501 AddInstruction(extract_instantiator); |
| 1494 args->Add(new UseVal(placeholder)); | 1502 args->Add(new UseVal(placeholder)); |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2280 OS::Print(")"); | 2288 OS::Print(")"); |
| 2281 } | 2289 } |
| 2282 | 2290 |
| 2283 | 2291 |
| 2284 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) { | 2292 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) { |
| 2285 OS::Print("CreateArray("); | 2293 OS::Print("CreateArray("); |
| 2286 for (int i = 0; i < comp->ElementCount(); ++i) { | 2294 for (int i = 0; i < comp->ElementCount(); ++i) { |
| 2287 if (i != 0) OS::Print(", "); | 2295 if (i != 0) OS::Print(", "); |
| 2288 comp->ElementAt(i)->Accept(this); | 2296 comp->ElementAt(i)->Accept(this); |
| 2289 } | 2297 } |
| 2298 if (comp->ElementCount() > 0) OS::Print(", "); |
| 2299 comp->element_type()->Accept(this); |
| 2290 OS::Print(")"); | 2300 OS::Print(")"); |
| 2291 } | 2301 } |
| 2292 | 2302 |
| 2293 | 2303 |
| 2294 void FlowGraphPrinter::VisitCreateClosure(CreateClosureComp* comp) { | 2304 void FlowGraphPrinter::VisitCreateClosure(CreateClosureComp* comp) { |
| 2295 OS::Print("CreateClosure(%s", comp->function().ToCString()); | 2305 OS::Print("CreateClosure(%s", comp->function().ToCString()); |
| 2296 if (comp->type_arguments() != NULL) { | 2306 if (comp->type_arguments() != NULL) { |
| 2297 OS::Print(", "); | 2307 OS::Print(", "); |
| 2298 comp->type_arguments()->Accept(this); | 2308 comp->type_arguments()->Accept(this); |
| 2299 } | 2309 } |
| 2300 OS::Print(")"); | 2310 OS::Print(")"); |
| 2301 } | 2311 } |
| 2302 | 2312 |
| 2303 | 2313 |
| 2304 void FlowGraphPrinter::VisitNativeLoadField(NativeLoadFieldComp* comp) { | 2314 void FlowGraphPrinter::VisitNativeLoadField(NativeLoadFieldComp* comp) { |
| 2305 OS::Print("NativeLoadField("); | 2315 OS::Print("NativeLoadField("); |
| 2306 comp->value()->Accept(this); | 2316 comp->value()->Accept(this); |
| 2307 OS::Print(", %d)", comp->offset_in_bytes()); | 2317 OS::Print(", %d)", comp->offset_in_bytes()); |
| 2308 } | 2318 } |
| 2309 | 2319 |
| 2310 | 2320 |
| 2311 void FlowGraphPrinter::VisitExtractFactoryTypeArguments( | 2321 void FlowGraphPrinter::VisitInstantiateTypeArguments( |
| 2312 ExtractFactoryTypeArgumentsComp* comp) { | 2322 InstantiateTypeArgumentsComp* comp) { |
| 2313 OS::Print("ExtractFactoryTypeArguments("); | 2323 const String& type_args = String::Handle(comp->type_arguments().Name()); |
| 2324 OS::Print("InstantiateTypeArguments(%s, ", type_args.ToCString()); |
| 2314 comp->instantiator()->Accept(this); | 2325 comp->instantiator()->Accept(this); |
| 2315 OS::Print(")"); | 2326 OS::Print(")"); |
| 2316 } | 2327 } |
| 2317 | 2328 |
| 2318 | 2329 |
| 2319 void FlowGraphPrinter::VisitExtractConstructorTypeArguments( | 2330 void FlowGraphPrinter::VisitExtractConstructorTypeArguments( |
| 2320 ExtractConstructorTypeArgumentsComp* comp) { | 2331 ExtractConstructorTypeArgumentsComp* comp) { |
| 2321 OS::Print("ExtractConstructorTypeArguments("); | 2332 const String& type_args = String::Handle(comp->type_arguments().Name()); |
| 2333 OS::Print("ExtractConstructorTypeArguments(%s, ", type_args.ToCString()); |
| 2322 comp->instantiator()->Accept(this); | 2334 comp->instantiator()->Accept(this); |
| 2323 OS::Print(")"); | 2335 OS::Print(")"); |
| 2324 } | 2336 } |
| 2325 | 2337 |
| 2326 | 2338 |
| 2327 void FlowGraphPrinter::VisitExtractConstructorInstantiator( | 2339 void FlowGraphPrinter::VisitExtractConstructorInstantiator( |
| 2328 ExtractConstructorInstantiatorComp* comp) { | 2340 ExtractConstructorInstantiatorComp* comp) { |
| 2329 OS::Print("ExtractConstructorInstantiator("); | 2341 OS::Print("ExtractConstructorInstantiator("); |
| 2330 comp->instantiator()->Accept(this); | 2342 comp->instantiator()->Accept(this); |
| 2331 OS::Print(", "); | 2343 OS::Print(", "); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2576 char* chars = reinterpret_cast<char*>( | 2588 char* chars = reinterpret_cast<char*>( |
| 2577 Isolate::Current()->current_zone()->Allocate(len)); | 2589 Isolate::Current()->current_zone()->Allocate(len)); |
| 2578 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2590 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2579 const Error& error = Error::Handle( | 2591 const Error& error = Error::Handle( |
| 2580 LanguageError::New(String::Handle(String::New(chars)))); | 2592 LanguageError::New(String::Handle(String::New(chars)))); |
| 2581 Isolate::Current()->long_jump_base()->Jump(1, error); | 2593 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2582 } | 2594 } |
| 2583 | 2595 |
| 2584 | 2596 |
| 2585 } // namespace dart | 2597 } // namespace dart |
| OLD | NEW |