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 "vm/kernel_binary_flowgraph.h" | 5 #include "vm/kernel_binary_flowgraph.h" |
6 | 6 |
7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
8 | 8 |
9 #if !defined(DART_PRECOMPILED_RUNTIME) | 9 #if !defined(DART_PRECOMPILED_RUNTIME) |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 result_ = closure_function.ImplicitStaticClosure(); | 86 result_ = closure_function.ImplicitStaticClosure(); |
87 result_ = H.Canonicalize(result_); | 87 result_ = H.Canonicalize(result_); |
88 } else if (H.IsGetter(target)) { | 88 } else if (H.IsGetter(target)) { |
89 UNIMPLEMENTED(); | 89 UNIMPLEMENTED(); |
90 } else { | 90 } else { |
91 UNIMPLEMENTED(); | 91 UNIMPLEMENTED(); |
92 } | 92 } |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
| 96 |
96 void StreamingConstantEvaluator::EvaluateSymbolLiteral() { | 97 void StreamingConstantEvaluator::EvaluateSymbolLiteral() { |
97 int str_index = builder_->ReadUInt(); | 98 int str_index = builder_->ReadUInt(); |
98 const dart::String& symbol_value = builder_->DartSymbol(str_index); | 99 const dart::String& symbol_value = H.DartSymbol(str_index); |
99 | 100 |
100 const dart::Class& symbol_class = | 101 const dart::Class& symbol_class = |
101 dart::Class::ZoneHandle(Z, I->object_store()->symbol_class()); | 102 dart::Class::ZoneHandle(Z, I->object_store()->symbol_class()); |
102 ASSERT(!symbol_class.IsNull()); | 103 ASSERT(!symbol_class.IsNull()); |
103 const dart::Function& symbol_constructor = Function::ZoneHandle( | 104 const dart::Function& symbol_constructor = Function::ZoneHandle( |
104 Z, symbol_class.LookupConstructor(Symbols::SymbolCtor())); | 105 Z, symbol_class.LookupConstructor(Symbols::SymbolCtor())); |
105 ASSERT(!symbol_constructor.IsNull()); | 106 ASSERT(!symbol_constructor.IsNull()); |
106 result_ ^= EvaluateConstConstructorCall( | 107 result_ ^= EvaluateConstConstructorCall( |
107 symbol_class, TypeArguments::Handle(Z), symbol_constructor, symbol_value); | 108 symbol_class, TypeArguments::Handle(Z), symbol_constructor, symbol_value); |
108 } | 109 } |
109 | 110 |
| 111 |
110 void StreamingConstantEvaluator::EvaluateDoubleLiteral() { | 112 void StreamingConstantEvaluator::EvaluateDoubleLiteral() { |
111 int str_index = builder_->ReadUInt(); | 113 int str_index = builder_->ReadUInt(); |
112 result_ = dart::Double::New(builder_->DartString(str_index), Heap::kOld); | 114 result_ = dart::Double::New(H.DartString(str_index), Heap::kOld); |
113 result_ = H.Canonicalize(result_); | 115 result_ = H.Canonicalize(result_); |
114 } | 116 } |
115 | 117 |
| 118 |
116 RawObject* StreamingConstantEvaluator::EvaluateConstConstructorCall( | 119 RawObject* StreamingConstantEvaluator::EvaluateConstConstructorCall( |
117 const dart::Class& type_class, | 120 const dart::Class& type_class, |
118 const TypeArguments& type_arguments, | 121 const TypeArguments& type_arguments, |
119 const Function& constructor, | 122 const Function& constructor, |
120 const Object& argument) { | 123 const Object& argument) { |
121 // Factories have one extra argument: the type arguments. | 124 // Factories have one extra argument: the type arguments. |
122 // Constructors have 1 extra arguments: receiver. | 125 // Constructors have 1 extra arguments: receiver. |
123 const int kNumArgs = 1; | 126 const int kNumArgs = 1; |
124 const int kNumExtraArgs = 1; | 127 const int kNumExtraArgs = 1; |
125 const int num_arguments = kNumArgs + kNumExtraArgs; | 128 const int num_arguments = kNumArgs + kNumExtraArgs; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 case kNullLiteral: | 304 case kNullLiteral: |
302 return BuildNullLiteral(); | 305 return BuildNullLiteral(); |
303 default: | 306 default: |
304 UNREACHABLE(); | 307 UNREACHABLE(); |
305 } | 308 } |
306 | 309 |
307 return Fragment(); | 310 return Fragment(); |
308 } | 311 } |
309 | 312 |
310 | 313 |
311 intptr_t StreamingFlowGraphBuilder::GetStringOffset(intptr_t index) { | |
312 if (string_offsets_ == NULL) { | |
313 intptr_t saved_offset = ReaderOffset(); | |
314 reader_->set_offset(4); // Skip kMagicProgramFile to the string table. | |
315 string_offset_count_ = ReadListLength() + 1; | |
316 string_offsets_ = new intptr_t[string_offset_count_]; | |
317 | |
318 // Build a table of the 0-based string start and end offsets. | |
319 string_offsets_[0] = 0; | |
320 for (intptr_t i = 1; i < string_offset_count_; ++i) { | |
321 string_offsets_[i] = ReadUInt(); | |
322 } | |
323 // Mark the start of the string data to use for decoding strings. | |
324 reader_->MarkStringDataOffset(); | |
325 SetOffset(saved_offset); | |
326 } | |
327 return string_offsets_[index]; | |
328 } | |
329 | |
330 | |
331 CanonicalName* StreamingFlowGraphBuilder::GetCanonicalName(intptr_t index) { | 314 CanonicalName* StreamingFlowGraphBuilder::GetCanonicalName(intptr_t index) { |
332 if (index == 0) return NULL; | 315 if (index == 0) return NULL; |
333 --index; | 316 --index; |
334 | 317 |
335 if (canonical_names_ != NULL && canonical_names_entries_read_ > index) { | 318 if (canonical_names_ != NULL && canonical_names_entries_read_ > index) { |
336 return canonical_names_[index]; | 319 return canonical_names_[index]; |
337 } | 320 } |
338 | 321 |
339 intptr_t saved_offset = ReaderOffset(); | 322 intptr_t saved_offset = ReaderOffset(); |
340 if (canonical_names_ == NULL) { | 323 if (canonical_names_ == NULL) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 parent = canonical_names_[biased_parent_index - 1]; | 371 parent = canonical_names_[biased_parent_index - 1]; |
389 } else { | 372 } else { |
390 if (canonical_names_entries_read_ == 0) { | 373 if (canonical_names_entries_read_ == 0) { |
391 parent = CanonicalName::NewRoot(); | 374 parent = CanonicalName::NewRoot(); |
392 } else { | 375 } else { |
393 parent = canonical_names_[0]->parent(); | 376 parent = canonical_names_[0]->parent(); |
394 } | 377 } |
395 } | 378 } |
396 ASSERT(parent != NULL); | 379 ASSERT(parent != NULL); |
397 intptr_t name_index = ReadUInt(); | 380 intptr_t name_index = ReadUInt(); |
398 String* name = KernelString(name_index); | 381 CanonicalName* canonical_name = parent->AddChild(name_index); |
399 CanonicalName* canonical_name = parent->AddChild(name); | |
400 canonical_names_[canonical_names_entries_read_] = canonical_name; | 382 canonical_names_[canonical_names_entries_read_] = canonical_name; |
401 } | 383 } |
402 | 384 |
403 canonical_names_next_offset_ = ReaderOffset(); | 385 canonical_names_next_offset_ = ReaderOffset(); |
404 | 386 |
405 SetOffset(saved_offset); | 387 SetOffset(saved_offset); |
406 return canonical_names_[index]; | 388 return canonical_names_[index]; |
407 } | 389 } |
408 | 390 |
409 | 391 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 ScopeBuildingResult* StreamingFlowGraphBuilder::scopes() { | 432 ScopeBuildingResult* StreamingFlowGraphBuilder::scopes() { |
451 return flow_graph_builder_->scopes_; | 433 return flow_graph_builder_->scopes_; |
452 } | 434 } |
453 | 435 |
454 | 436 |
455 ParsedFunction* StreamingFlowGraphBuilder::parsed_function() { | 437 ParsedFunction* StreamingFlowGraphBuilder::parsed_function() { |
456 return flow_graph_builder_->parsed_function_; | 438 return flow_graph_builder_->parsed_function_; |
457 } | 439 } |
458 | 440 |
459 | 441 |
460 dart::String& StreamingFlowGraphBuilder::DartSymbol(intptr_t index) { | |
461 intptr_t start = GetStringOffset(index); | |
462 intptr_t end = GetStringOffset(index + 1); | |
463 return H.DartSymbol(reader_->buffer() + reader_->string_data_offset() + start, | |
464 end - start); | |
465 } | |
466 | |
467 | |
468 dart::String& StreamingFlowGraphBuilder::DartString(intptr_t index) { | |
469 intptr_t start = GetStringOffset(index); | |
470 intptr_t end = GetStringOffset(index + 1); | |
471 return H.DartString(reader_->buffer() + reader_->string_data_offset() + start, | |
472 end - start); | |
473 } | |
474 | |
475 | |
476 String* StreamingFlowGraphBuilder::KernelString(intptr_t index) { | |
477 intptr_t start = GetStringOffset(index); | |
478 intptr_t end = GetStringOffset(index + 1); | |
479 return new String(start, end - start); | |
480 } | |
481 | |
482 | |
483 Fragment StreamingFlowGraphBuilder::DebugStepCheck(TokenPosition position) { | 442 Fragment StreamingFlowGraphBuilder::DebugStepCheck(TokenPosition position) { |
484 return flow_graph_builder_->DebugStepCheck(position); | 443 return flow_graph_builder_->DebugStepCheck(position); |
485 } | 444 } |
486 | 445 |
487 | 446 |
488 Fragment StreamingFlowGraphBuilder::LoadLocal(LocalVariable* variable) { | 447 Fragment StreamingFlowGraphBuilder::LoadLocal(LocalVariable* variable) { |
489 return flow_graph_builder_->LoadLocal(variable); | 448 return flow_graph_builder_->LoadLocal(variable); |
490 } | 449 } |
491 | 450 |
492 | 451 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 instructions += PushArgument(); | 555 instructions += PushArgument(); |
597 instructions += LoadLocal(catch_block()->stack_trace_var()); | 556 instructions += LoadLocal(catch_block()->stack_trace_var()); |
598 instructions += PushArgument(); | 557 instructions += PushArgument(); |
599 instructions += RethrowException(position, catch_block()->catch_try_index()); | 558 instructions += RethrowException(position, catch_block()->catch_try_index()); |
600 | 559 |
601 return instructions; | 560 return instructions; |
602 } | 561 } |
603 | 562 |
604 | 563 |
605 Fragment StreamingFlowGraphBuilder::BuildBigIntLiteral() { | 564 Fragment StreamingFlowGraphBuilder::BuildBigIntLiteral() { |
606 const dart::String& value = DartString(ReadUInt()); | 565 const dart::String& value = H.DartString(ReadUInt()); |
607 return Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld))); | 566 return Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld))); |
608 } | 567 } |
609 | 568 |
610 | 569 |
611 Fragment StreamingFlowGraphBuilder::BuildStringLiteral() { | 570 Fragment StreamingFlowGraphBuilder::BuildStringLiteral() { |
612 intptr_t str_index = ReadUInt(); | 571 intptr_t str_index = ReadUInt(); |
613 return Constant(DartSymbol(str_index)); | 572 return Constant(H.DartSymbol(str_index)); |
614 } | 573 } |
615 | 574 |
616 | 575 |
617 Fragment StreamingFlowGraphBuilder::BuildIntLiteral(uint8_t payload) { | 576 Fragment StreamingFlowGraphBuilder::BuildIntLiteral(uint8_t payload) { |
618 int64_t value = static_cast<int32_t>(payload) - SpecializedIntLiteralBias; | 577 int64_t value = static_cast<int32_t>(payload) - SpecializedIntLiteralBias; |
619 return IntConstant(value); | 578 return IntConstant(value); |
620 } | 579 } |
621 | 580 |
622 | 581 |
623 Fragment StreamingFlowGraphBuilder::BuildIntLiteral(bool is_negative) { | 582 Fragment StreamingFlowGraphBuilder::BuildIntLiteral(bool is_negative) { |
(...skipping 15 matching lines...) Expand all Loading... |
639 | 598 |
640 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { | 599 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { |
641 return Constant(Instance::ZoneHandle(Z, Instance::null())); | 600 return Constant(Instance::ZoneHandle(Z, Instance::null())); |
642 } | 601 } |
643 | 602 |
644 | 603 |
645 } // namespace kernel | 604 } // namespace kernel |
646 } // namespace dart | 605 } // namespace dart |
647 | 606 |
648 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 607 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |