OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "vm/kernel_to_il.h" | 7 #include "vm/kernel_to_il.h" |
8 | 8 |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/intermediate_language.h" | 10 #include "vm/intermediate_language.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 | 379 |
380 const dart::String& TranslationHelper::DartSetterName(NameIndex setter) { | 380 const dart::String& TranslationHelper::DartSetterName(NameIndex setter) { |
381 return DartSetterName(CanonicalNameParent(setter), | 381 return DartSetterName(CanonicalNameParent(setter), |
382 CanonicalNameString(setter)); | 382 CanonicalNameString(setter)); |
383 } | 383 } |
384 | 384 |
385 | 385 |
386 const dart::String& TranslationHelper::DartSetterName(Name* setter_name) { | |
387 return DartSetterName(setter_name->library(), setter_name->string_index()); | |
388 } | |
389 | |
390 | |
391 const dart::String& TranslationHelper::DartSetterName(NameIndex parent, | 386 const dart::String& TranslationHelper::DartSetterName(NameIndex parent, |
392 StringIndex setter) { | 387 StringIndex setter) { |
393 // The names flowing into [setter] are coming from the Kernel file: | 388 // The names flowing into [setter] are coming from the Kernel file: |
394 // * user-defined setters: `fieldname=` | 389 // * user-defined setters: `fieldname=` |
395 // * property-set expressions: `fieldname` | 390 // * property-set expressions: `fieldname` |
396 // | 391 // |
397 // The VM uses `get:fieldname` and `set:fieldname`. | 392 // The VM uses `get:fieldname` and `set:fieldname`. |
398 // | 393 // |
399 // => In order to be consistent, we remove the `=` always and adopt the VM | 394 // => In order to be consistent, we remove the `=` always and adopt the VM |
400 // conventions. | 395 // conventions. |
(...skipping 14 matching lines...) Expand all Loading... |
415 return name; | 410 return name; |
416 } | 411 } |
417 | 412 |
418 | 413 |
419 const dart::String& TranslationHelper::DartGetterName(NameIndex getter) { | 414 const dart::String& TranslationHelper::DartGetterName(NameIndex getter) { |
420 return DartGetterName(CanonicalNameParent(getter), | 415 return DartGetterName(CanonicalNameParent(getter), |
421 CanonicalNameString(getter)); | 416 CanonicalNameString(getter)); |
422 } | 417 } |
423 | 418 |
424 | 419 |
425 const dart::String& TranslationHelper::DartGetterName(Name* getter_name) { | |
426 return DartGetterName(getter_name->library(), getter_name->string_index()); | |
427 } | |
428 | |
429 | |
430 const dart::String& TranslationHelper::DartGetterName(NameIndex parent, | 420 const dart::String& TranslationHelper::DartGetterName(NameIndex parent, |
431 StringIndex getter) { | 421 StringIndex getter) { |
432 dart::String& name = DartString(getter); | 422 dart::String& name = DartString(getter); |
433 ManglePrivateName(parent, &name, false); | 423 ManglePrivateName(parent, &name, false); |
434 name = dart::Field::GetterSymbol(name); | 424 name = dart::Field::GetterSymbol(name); |
435 return name; | 425 return name; |
436 } | 426 } |
437 | 427 |
438 | 428 |
439 const dart::String& TranslationHelper::DartFieldName(Name* kernel_name) { | |
440 dart::String& name = DartString(kernel_name->string_index()); | |
441 return ManglePrivateName(kernel_name->library(), &name); | |
442 } | |
443 | |
444 | |
445 const dart::String& TranslationHelper::DartFieldName(NameIndex parent, | 429 const dart::String& TranslationHelper::DartFieldName(NameIndex parent, |
446 StringIndex field) { | 430 StringIndex field) { |
447 dart::String& name = DartString(field); | 431 dart::String& name = DartString(field); |
448 return ManglePrivateName(parent, &name); | 432 return ManglePrivateName(parent, &name); |
449 } | 433 } |
450 | 434 |
451 | 435 |
452 const dart::String& TranslationHelper::DartInitializerName(Name* kernel_name) { | |
453 // The [DartFieldName] will take care of mangling the name. | |
454 dart::String& name = | |
455 dart::String::Handle(Z, DartFieldName(kernel_name).raw()); | |
456 name = Symbols::FromConcat(thread_, Symbols::InitPrefix(), name); | |
457 return name; | |
458 } | |
459 | |
460 | |
461 const dart::String& TranslationHelper::DartMethodName(NameIndex method) { | 436 const dart::String& TranslationHelper::DartMethodName(NameIndex method) { |
462 return DartMethodName(CanonicalNameParent(method), | 437 return DartMethodName(CanonicalNameParent(method), |
463 CanonicalNameString(method)); | 438 CanonicalNameString(method)); |
464 } | 439 } |
465 | 440 |
466 | 441 |
467 const dart::String& TranslationHelper::DartMethodName(Name* method_name) { | |
468 return DartMethodName(method_name->library(), method_name->string_index()); | |
469 } | |
470 | |
471 | |
472 const dart::String& TranslationHelper::DartMethodName(NameIndex parent, | 442 const dart::String& TranslationHelper::DartMethodName(NameIndex parent, |
473 StringIndex method) { | 443 StringIndex method) { |
474 dart::String& name = DartString(method); | 444 dart::String& name = DartString(method); |
475 return ManglePrivateName(parent, &name); | 445 return ManglePrivateName(parent, &name); |
476 } | 446 } |
477 | 447 |
478 | 448 |
479 const dart::String& TranslationHelper::DartFactoryName(NameIndex factory) { | 449 const dart::String& TranslationHelper::DartFactoryName(NameIndex factory) { |
480 ASSERT(IsConstructor(factory) || IsFactory(factory)); | 450 ASSERT(IsConstructor(factory) || IsFactory(factory)); |
481 GrowableHandlePtrArray<const dart::String> pieces(Z, 3); | 451 GrowableHandlePtrArray<const dart::String> pieces(Z, 3); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 const dart::Library& library = | 609 const dart::Library& library = |
640 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(parent)); | 610 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(parent)); |
641 *name_to_modify = library.PrivateName(*name_to_modify); | 611 *name_to_modify = library.PrivateName(*name_to_modify); |
642 } else if (symbolize) { | 612 } else if (symbolize) { |
643 *name_to_modify = Symbols::New(thread_, *name_to_modify); | 613 *name_to_modify = Symbols::New(thread_, *name_to_modify); |
644 } | 614 } |
645 return *name_to_modify; | 615 return *name_to_modify; |
646 } | 616 } |
647 | 617 |
648 | 618 |
649 const Array& TranslationHelper::ArgumentNames(List<NamedExpression>* named) { | |
650 if (named->length() == 0) return Array::ZoneHandle(Z); | |
651 | |
652 const Array& names = | |
653 Array::ZoneHandle(Z, Array::New(named->length(), Heap::kOld)); | |
654 for (intptr_t i = 0; i < named->length(); ++i) { | |
655 names.SetAt(i, DartSymbol((*named)[i]->name())); | |
656 } | |
657 return names; | |
658 } | |
659 | |
660 | |
661 FlowGraphBuilder::FlowGraphBuilder( | 619 FlowGraphBuilder::FlowGraphBuilder( |
662 intptr_t kernel_offset, | 620 intptr_t kernel_offset, |
663 ParsedFunction* parsed_function, | 621 ParsedFunction* parsed_function, |
664 const ZoneGrowableArray<const ICData*>& ic_data_array, | 622 const ZoneGrowableArray<const ICData*>& ic_data_array, |
665 ZoneGrowableArray<intptr_t>* context_level_array, | 623 ZoneGrowableArray<intptr_t>* context_level_array, |
666 InlineExitCollector* exit_collector, | 624 InlineExitCollector* exit_collector, |
667 intptr_t osr_id, | 625 intptr_t osr_id, |
668 intptr_t first_block_id) | 626 intptr_t first_block_id) |
669 : translation_helper_(Thread::Current()), | 627 : translation_helper_(Thread::Current()), |
670 thread_(translation_helper_.thread()), | 628 thread_(translation_helper_.thread()), |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 Fragment FlowGraphBuilder::IntConstant(int64_t value) { | 1106 Fragment FlowGraphBuilder::IntConstant(int64_t value) { |
1149 return Fragment( | 1107 return Fragment( |
1150 Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld)))); | 1108 Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld)))); |
1151 } | 1109 } |
1152 | 1110 |
1153 | 1111 |
1154 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, | 1112 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, |
1155 const dart::String& name, | 1113 const dart::String& name, |
1156 Token::Kind kind, | 1114 Token::Kind kind, |
1157 intptr_t argument_count, | 1115 intptr_t argument_count, |
1158 intptr_t num_args_checked) { | 1116 intptr_t checked_argument_count) { |
1159 return InstanceCall(position, name, kind, argument_count, Array::null_array(), | 1117 return InstanceCall(position, name, kind, argument_count, Array::null_array(), |
1160 num_args_checked); | 1118 checked_argument_count); |
1161 } | 1119 } |
1162 | 1120 |
1163 | 1121 |
1164 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, | 1122 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, |
1165 const dart::String& name, | 1123 const dart::String& name, |
1166 Token::Kind kind, | 1124 Token::Kind kind, |
1167 intptr_t argument_count, | 1125 intptr_t argument_count, |
1168 const Array& argument_names, | 1126 const Array& argument_names, |
1169 intptr_t num_args_checked) { | 1127 intptr_t checked_argument_count) { |
1170 ArgumentArray arguments = GetArguments(argument_count); | 1128 ArgumentArray arguments = GetArguments(argument_count); |
1171 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported. | 1129 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported. |
1172 InstanceCallInstr* call = new (Z) InstanceCallInstr( | 1130 InstanceCallInstr* call = new (Z) InstanceCallInstr( |
1173 position, name, kind, arguments, kTypeArgsLen, argument_names, | 1131 position, name, kind, arguments, kTypeArgsLen, argument_names, |
1174 num_args_checked, ic_data_array_, GetNextDeoptId()); | 1132 checked_argument_count, ic_data_array_, GetNextDeoptId()); |
1175 Push(call); | 1133 Push(call); |
1176 return Fragment(call); | 1134 return Fragment(call); |
1177 } | 1135 } |
1178 | 1136 |
1179 | 1137 |
1180 Fragment FlowGraphBuilder::ClosureCall(intptr_t type_args_len, | 1138 Fragment FlowGraphBuilder::ClosureCall(intptr_t type_args_len, |
1181 intptr_t argument_count, | 1139 intptr_t argument_count, |
1182 const Array& argument_names) { | 1140 const Array& argument_names) { |
1183 Value* function = Pop(); | 1141 Value* function = Pop(); |
1184 const intptr_t total_count = argument_count + (type_args_len > 0 ? 1 : 0); | 1142 const intptr_t total_count = argument_count + (type_args_len > 0 ? 1 : 0); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 | 1621 |
1664 intptr_t FlowGraphBuilder::CurrentTryIndex() { | 1622 intptr_t FlowGraphBuilder::CurrentTryIndex() { |
1665 if (try_catch_block_ == NULL) { | 1623 if (try_catch_block_ == NULL) { |
1666 return CatchClauseNode::kInvalidTryIndex; | 1624 return CatchClauseNode::kInvalidTryIndex; |
1667 } else { | 1625 } else { |
1668 return try_catch_block_->try_index(); | 1626 return try_catch_block_->try_index(); |
1669 } | 1627 } |
1670 } | 1628 } |
1671 | 1629 |
1672 | 1630 |
1673 LocalVariable* FlowGraphBuilder::LookupVariable(VariableDeclaration* var) { | |
1674 LocalVariable* local = scopes_->locals.Lookup(var->kernel_offset_no_tag()); | |
1675 ASSERT(local != NULL); | |
1676 return local; | |
1677 } | |
1678 | |
1679 | |
1680 dart::LocalVariable* FlowGraphBuilder::LookupVariable(intptr_t kernel_offset) { | 1631 dart::LocalVariable* FlowGraphBuilder::LookupVariable(intptr_t kernel_offset) { |
1681 LocalVariable* local = scopes_->locals.Lookup(kernel_offset); | 1632 LocalVariable* local = scopes_->locals.Lookup(kernel_offset); |
1682 ASSERT(local != NULL); | 1633 ASSERT(local != NULL); |
1683 return local; | 1634 return local; |
1684 } | 1635 } |
1685 | 1636 |
1686 | 1637 |
1687 void FlowGraphBuilder::SetTempIndex(Definition* definition) { | 1638 void FlowGraphBuilder::SetTempIndex(Definition* definition) { |
1688 definition->set_temp_index( | 1639 definition->set_temp_index( |
1689 stack_ == NULL ? 0 : stack_->definition()->temp_index() + 1); | 1640 stack_ == NULL ? 0 : stack_->definition()->temp_index() + 1); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2439 function.kernel_offset()); | 2390 function.kernel_offset()); |
2440 } else { | 2391 } else { |
2441 Thread* thread = Thread::Current(); | 2392 Thread* thread = Thread::Current(); |
2442 Error& error = Error::Handle(); | 2393 Error& error = Error::Handle(); |
2443 error = thread->sticky_error(); | 2394 error = thread->sticky_error(); |
2444 thread->clear_sticky_error(); | 2395 thread->clear_sticky_error(); |
2445 return error.raw(); | 2396 return error.raw(); |
2446 } | 2397 } |
2447 } | 2398 } |
2448 | 2399 |
| 2400 static int LowestFirst(const intptr_t* a, const intptr_t* b) { |
| 2401 return *a - *b; |
| 2402 } |
| 2403 |
| 2404 /** |
| 2405 * If index exists as sublist in list, sort the sublist from lowest to highest, |
| 2406 * then copy it, as Smis and without duplicates, |
| 2407 * to a new Array in Heap::kOld which is returned. |
| 2408 * Note that the source list is both sorted and de-duplicated as well, but will |
| 2409 * possibly contain duplicate and unsorted data at the end. |
| 2410 * Otherwise (when sublist doesn't exist in list) return new empty array. |
| 2411 */ |
| 2412 static RawArray* AsSortedDuplicateFreeArray(GrowableArray<intptr_t>* source) { |
| 2413 intptr_t size = source->length(); |
| 2414 if (size == 0) { |
| 2415 return Array::New(0); |
| 2416 } |
| 2417 |
| 2418 source->Sort(LowestFirst); |
| 2419 |
| 2420 intptr_t last = 0; |
| 2421 for (intptr_t current = 1; current < size; ++current) { |
| 2422 if (source->At(last) != source->At(current)) { |
| 2423 (*source)[++last] = source->At(current); |
| 2424 } |
| 2425 } |
| 2426 Array& array_object = Array::Handle(); |
| 2427 array_object = Array::New(last + 1, Heap::kOld); |
| 2428 Smi& smi_value = Smi::Handle(); |
| 2429 for (intptr_t i = 0; i <= last; ++i) { |
| 2430 smi_value = Smi::New(source->At(i)); |
| 2431 array_object.SetAt(i, smi_value); |
| 2432 } |
| 2433 return array_object.raw(); |
| 2434 } |
| 2435 |
| 2436 void CollectTokenPositionsFor(const Script& const_script) { |
| 2437 Thread* thread = Thread::Current(); |
| 2438 Zone* zone_ = thread->zone(); |
| 2439 Script& script = Script::Handle(Z, const_script.raw()); |
| 2440 TranslationHelper helper(thread); |
| 2441 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); |
| 2442 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
| 2443 helper.SetCanonicalNames( |
| 2444 TypedData::Handle(Z, script.kernel_canonical_names())); |
| 2445 |
| 2446 GrowableArray<intptr_t> token_positions(10); |
| 2447 GrowableArray<intptr_t> yield_positions(1); |
| 2448 StreamingFlowGraphBuilder streaming_flow_graph_builder( |
| 2449 &helper, zone_, script.kernel_data(), script.kernel_data_size()); |
| 2450 streaming_flow_graph_builder.CollectTokenPositionsFor( |
| 2451 script.kernel_script_index(), &token_positions, &yield_positions); |
| 2452 Array& array_object = Array::Handle(Z); |
| 2453 array_object = AsSortedDuplicateFreeArray(&token_positions); |
| 2454 script.set_debug_positions(array_object); |
| 2455 array_object = AsSortedDuplicateFreeArray(&yield_positions); |
| 2456 script.set_yield_positions(array_object); |
| 2457 } |
| 2458 |
| 2459 String& GetSourceFor(const Script& const_script) { |
| 2460 Thread* thread = Thread::Current(); |
| 2461 Zone* zone_ = thread->zone(); |
| 2462 Script& script = Script::Handle(Z, const_script.raw()); |
| 2463 TranslationHelper helper(thread); |
| 2464 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); |
| 2465 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
| 2466 helper.SetCanonicalNames( |
| 2467 TypedData::Handle(Z, script.kernel_canonical_names())); |
| 2468 |
| 2469 StreamingFlowGraphBuilder streaming_flow_graph_builder( |
| 2470 &helper, zone_, script.kernel_data(), script.kernel_data_size()); |
| 2471 return streaming_flow_graph_builder.GetSourceFor( |
| 2472 script.kernel_script_index()); |
| 2473 } |
| 2474 |
| 2475 Array& GetLineStartsFor(const Script& const_script) { |
| 2476 Thread* thread = Thread::Current(); |
| 2477 Zone* zone_ = thread->zone(); |
| 2478 Script& script = Script::Handle(Z, const_script.raw()); |
| 2479 TranslationHelper helper(thread); |
| 2480 helper.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); |
| 2481 helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
| 2482 helper.SetCanonicalNames( |
| 2483 TypedData::Handle(Z, script.kernel_canonical_names())); |
| 2484 |
| 2485 StreamingFlowGraphBuilder streaming_flow_graph_builder( |
| 2486 &helper, zone_, script.kernel_data(), script.kernel_data_size()); |
| 2487 return streaming_flow_graph_builder.GetLineStartsFor( |
| 2488 script.kernel_script_index()); |
| 2489 } |
2449 | 2490 |
2450 } // namespace kernel | 2491 } // namespace kernel |
2451 } // namespace dart | 2492 } // namespace dart |
2452 | 2493 |
2453 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 2494 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |