Chromium Code Reviews| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 | 53 |
| 54 CacheConstantValue(offset, result_); | 54 CacheConstantValue(offset, result_); |
| 55 } | 55 } |
| 56 // We return a new `ZoneHandle` here on purpose: The intermediate language | 56 // We return a new `ZoneHandle` here on purpose: The intermediate language |
| 57 // instructions do not make a copy of the handle, so we do it. | 57 // instructions do not make a copy of the handle, so we do it. |
| 58 return dart::Instance::ZoneHandle(Z, result_.raw()); | 58 return dart::Instance::ZoneHandle(Z, result_.raw()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void StreamingConstantEvaluator::EvaluateStaticGet() { | 61 void StreamingConstantEvaluator::EvaluateStaticGet() { |
| 62 builder_->ReadPosition(); | 62 builder_->ReadPosition(); |
| 63 int canonical_name_index = builder_->ReadUInt(); | 63 intptr_t target = builder_->ReadUInt() - 1; |
|
Vyacheslav Egorov (Google)
2017/05/03 06:28:48
might be worth having a helper called ReadCanonica
| |
| 64 CanonicalName* target = builder_->GetCanonicalName(canonical_name_index); | |
| 65 | 64 |
| 66 if (H.IsField(target)) { | 65 if (H.IsField(target)) { |
| 67 const dart::Field& field = | 66 const dart::Field& field = |
| 68 dart::Field::Handle(Z, H.LookupFieldByKernelField(target)); | 67 dart::Field::Handle(Z, H.LookupFieldByKernelField(target)); |
| 69 if (field.StaticValue() == Object::sentinel().raw() || | 68 if (field.StaticValue() == Object::sentinel().raw() || |
| 70 field.StaticValue() == Object::transition_sentinel().raw()) { | 69 field.StaticValue() == Object::transition_sentinel().raw()) { |
| 71 field.EvaluateInitializer(); | 70 field.EvaluateInitializer(); |
| 72 result_ = field.StaticValue(); | 71 result_ = field.StaticValue(); |
| 73 result_ = H.Canonicalize(result_); | 72 result_ = H.Canonicalize(result_); |
| 74 field.SetStaticValue(result_, true); | 73 field.SetStaticValue(result_, true); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 case kNullLiteral: | 303 case kNullLiteral: |
| 305 return BuildNullLiteral(); | 304 return BuildNullLiteral(); |
| 306 default: | 305 default: |
| 307 UNREACHABLE(); | 306 UNREACHABLE(); |
| 308 } | 307 } |
| 309 | 308 |
| 310 return Fragment(); | 309 return Fragment(); |
| 311 } | 310 } |
| 312 | 311 |
| 313 | 312 |
| 314 CanonicalName* StreamingFlowGraphBuilder::GetCanonicalName(intptr_t index) { | |
| 315 if (index == 0) return NULL; | |
| 316 --index; | |
| 317 | |
| 318 if (canonical_names_ != NULL && canonical_names_entries_read_ > index) { | |
| 319 return canonical_names_[index]; | |
| 320 } | |
| 321 | |
| 322 intptr_t saved_offset = ReaderOffset(); | |
| 323 if (canonical_names_ == NULL) { | |
| 324 // Find offset from where to read canonical names table. | |
| 325 | |
| 326 // Skip the magic number. | |
| 327 reader_->set_offset(4); | |
| 328 | |
| 329 // Skip the string table. The last offset is the end offset of the last | |
| 330 // string which gives the length of the string data. | |
| 331 intptr_t list_length = ReadListLength(); | |
| 332 intptr_t end_offset = 0; | |
| 333 for (intptr_t i = 0; i < list_length; ++i) { | |
| 334 end_offset = ReadUInt(); | |
| 335 } | |
| 336 SkipBytes(end_offset); | |
| 337 | |
| 338 // There is another string table for the source URIs. Skip it as well. | |
| 339 list_length = ReadListLength(); | |
| 340 end_offset = 0; | |
| 341 for (intptr_t i = 0; i < list_length; ++i) { | |
| 342 end_offset = ReadUInt(); | |
| 343 } | |
| 344 SkipBytes(end_offset); | |
| 345 | |
| 346 // Source code table | |
| 347 for (intptr_t i = 0; i < list_length; ++i) { | |
| 348 // Source code | |
| 349 intptr_t bytes = ReadUInt(); | |
| 350 SkipBytes(bytes); | |
| 351 | |
| 352 // Line starts table | |
| 353 intptr_t line_count = ReadUInt(); | |
| 354 for (intptr_t j = 0; j < line_count; ++j) { | |
| 355 ReadUInt(); | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 // Now at canonical names table. | |
| 360 canonical_names_size_ = ReadUInt(); | |
| 361 canonical_names_ = new CanonicalName*[canonical_names_size_]; | |
| 362 canonical_names_next_offset_ = ReaderOffset(); | |
| 363 } | |
| 364 | |
| 365 SetOffset(canonical_names_next_offset_); | |
| 366 for (; canonical_names_entries_read_ <= index; | |
| 367 ++canonical_names_entries_read_) { | |
| 368 intptr_t biased_parent_index = ReadUInt(); | |
| 369 CanonicalName* parent; | |
| 370 if (biased_parent_index != 0) { | |
| 371 parent = canonical_names_[biased_parent_index - 1]; | |
| 372 } else { | |
| 373 if (canonical_names_entries_read_ == 0) { | |
| 374 parent = CanonicalName::NewRoot(); | |
| 375 } else { | |
| 376 parent = canonical_names_[0]->parent(); | |
| 377 } | |
| 378 } | |
| 379 ASSERT(parent != NULL); | |
| 380 intptr_t name_index = ReadUInt(); | |
| 381 CanonicalName* canonical_name = parent->AddChild(name_index); | |
| 382 canonical_names_[canonical_names_entries_read_] = canonical_name; | |
| 383 } | |
| 384 | |
| 385 canonical_names_next_offset_ = ReaderOffset(); | |
| 386 | |
| 387 SetOffset(saved_offset); | |
| 388 return canonical_names_[index]; | |
| 389 } | |
| 390 | |
| 391 | |
| 392 intptr_t StreamingFlowGraphBuilder::ReaderOffset() { | 313 intptr_t StreamingFlowGraphBuilder::ReaderOffset() { |
| 393 return reader_->offset(); | 314 return reader_->offset(); |
| 394 } | 315 } |
| 395 | 316 |
| 396 | 317 |
| 397 void StreamingFlowGraphBuilder::SetOffset(intptr_t offset) { | 318 void StreamingFlowGraphBuilder::SetOffset(intptr_t offset) { |
| 398 reader_->set_offset(offset); | 319 reader_->set_offset(offset); |
| 399 } | 320 } |
| 400 | 321 |
| 401 | 322 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 // The frontend will take care of emitting normal errors (like | 412 // The frontend will take care of emitting normal errors (like |
| 492 // [NoSuchMethodError]s) and only emit [InvalidExpression]s in very special | 413 // [NoSuchMethodError]s) and only emit [InvalidExpression]s in very special |
| 493 // situations (e.g. an invalid annotation). | 414 // situations (e.g. an invalid annotation). |
| 494 return ThrowNoSuchMethodError(); | 415 return ThrowNoSuchMethodError(); |
| 495 } | 416 } |
| 496 | 417 |
| 497 | 418 |
| 498 Fragment StreamingFlowGraphBuilder::BuildStaticGet() { | 419 Fragment StreamingFlowGraphBuilder::BuildStaticGet() { |
| 499 intptr_t saved_offset = ReaderOffset() - 1; // Include the tag. | 420 intptr_t saved_offset = ReaderOffset() - 1; // Include the tag. |
| 500 TokenPosition position = ReadPosition(); | 421 TokenPosition position = ReadPosition(); |
| 501 int canonical_name_index = ReadUInt(); | 422 intptr_t target = ReadUInt() - 1; |
|
Vyacheslav Egorov (Google)
2017/05/03 06:28:48
ditto
| |
| 502 CanonicalName* target = GetCanonicalName(canonical_name_index); | |
| 503 | 423 |
| 504 if (H.IsField(target)) { | 424 if (H.IsField(target)) { |
| 505 const dart::Field& field = | 425 const dart::Field& field = |
| 506 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); | 426 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); |
| 507 if (field.is_const()) { | 427 if (field.is_const()) { |
| 508 SetOffset(saved_offset); // EvaluateExpression needs the tag. | 428 SetOffset(saved_offset); // EvaluateExpression needs the tag. |
| 509 return Constant(constant_evaluator_.EvaluateExpression()); | 429 return Constant(constant_evaluator_.EvaluateExpression()); |
| 510 } else { | 430 } else { |
| 511 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); | 431 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); |
| 512 const dart::String& getter_name = H.DartGetterName(target); | 432 const dart::String& getter_name = H.DartGetterName(target); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 | 518 |
| 599 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { | 519 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { |
| 600 return Constant(Instance::ZoneHandle(Z, Instance::null())); | 520 return Constant(Instance::ZoneHandle(Z, Instance::null())); |
| 601 } | 521 } |
| 602 | 522 |
| 603 | 523 |
| 604 } // namespace kernel | 524 } // namespace kernel |
| 605 } // namespace dart | 525 } // namespace dart |
| 606 | 526 |
| 607 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 527 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |