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 intptr_t target = builder_->ReadUInt() - 1; | 63 NameIndex target = builder_->ReadCanonicalNameReference(); |
64 | 64 |
65 if (H.IsField(target)) { | 65 if (H.IsField(target)) { |
66 const dart::Field& field = | 66 const dart::Field& field = |
67 dart::Field::Handle(Z, H.LookupFieldByKernelField(target)); | 67 dart::Field::Handle(Z, H.LookupFieldByKernelField(target)); |
68 if (field.StaticValue() == Object::sentinel().raw() || | 68 if (field.StaticValue() == Object::sentinel().raw() || |
69 field.StaticValue() == Object::transition_sentinel().raw()) { | 69 field.StaticValue() == Object::transition_sentinel().raw()) { |
70 field.EvaluateInitializer(); | 70 field.EvaluateInitializer(); |
71 result_ = field.StaticValue(); | 71 result_ = field.StaticValue(); |
72 result_ = H.Canonicalize(result_); | 72 result_ = H.Canonicalize(result_); |
73 field.SetStaticValue(result_, true); | 73 field.SetStaticValue(result_, true); |
(...skipping 13 matching lines...) Expand all Loading... |
87 } else if (H.IsGetter(target)) { | 87 } else if (H.IsGetter(target)) { |
88 UNIMPLEMENTED(); | 88 UNIMPLEMENTED(); |
89 } else { | 89 } else { |
90 UNIMPLEMENTED(); | 90 UNIMPLEMENTED(); |
91 } | 91 } |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 | 95 |
96 void StreamingConstantEvaluator::EvaluateSymbolLiteral() { | 96 void StreamingConstantEvaluator::EvaluateSymbolLiteral() { |
97 int str_index = builder_->ReadUInt(); | 97 StringIndex str_index(builder_->ReadUInt()); |
98 const dart::String& symbol_value = H.DartSymbol(str_index); | 98 const dart::String& symbol_value = H.DartSymbol(str_index); |
99 | 99 |
100 const dart::Class& symbol_class = | 100 const dart::Class& symbol_class = |
101 dart::Class::ZoneHandle(Z, I->object_store()->symbol_class()); | 101 dart::Class::ZoneHandle(Z, I->object_store()->symbol_class()); |
102 ASSERT(!symbol_class.IsNull()); | 102 ASSERT(!symbol_class.IsNull()); |
103 const dart::Function& symbol_constructor = Function::ZoneHandle( | 103 const dart::Function& symbol_constructor = Function::ZoneHandle( |
104 Z, symbol_class.LookupConstructor(Symbols::SymbolCtor())); | 104 Z, symbol_class.LookupConstructor(Symbols::SymbolCtor())); |
105 ASSERT(!symbol_constructor.IsNull()); | 105 ASSERT(!symbol_constructor.IsNull()); |
106 result_ ^= EvaluateConstConstructorCall( | 106 result_ ^= EvaluateConstConstructorCall( |
107 symbol_class, TypeArguments::Handle(Z), symbol_constructor, symbol_value); | 107 symbol_class, TypeArguments::Handle(Z), symbol_constructor, symbol_value); |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 void StreamingConstantEvaluator::EvaluateDoubleLiteral() { | 111 void StreamingConstantEvaluator::EvaluateDoubleLiteral() { |
112 int str_index = builder_->ReadUInt(); | 112 StringIndex str_index(builder_->ReadUInt()); |
113 result_ = dart::Double::New(H.DartString(str_index), Heap::kOld); | 113 result_ = dart::Double::New(H.DartString(str_index), Heap::kOld); |
114 result_ = H.Canonicalize(result_); | 114 result_ = H.Canonicalize(result_); |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 RawObject* StreamingConstantEvaluator::EvaluateConstConstructorCall( | 118 RawObject* StreamingConstantEvaluator::EvaluateConstConstructorCall( |
119 const dart::Class& type_class, | 119 const dart::Class& type_class, |
120 const TypeArguments& type_arguments, | 120 const TypeArguments& type_arguments, |
121 const Function& constructor, | 121 const Function& constructor, |
122 const Object& argument) { | 122 const Object& argument) { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 uint32_t StreamingFlowGraphBuilder::ReadUInt() { | 328 uint32_t StreamingFlowGraphBuilder::ReadUInt() { |
329 return reader_->ReadUInt(); | 329 return reader_->ReadUInt(); |
330 } | 330 } |
331 | 331 |
332 | 332 |
333 intptr_t StreamingFlowGraphBuilder::ReadListLength() { | 333 intptr_t StreamingFlowGraphBuilder::ReadListLength() { |
334 return reader_->ReadListLength(); | 334 return reader_->ReadListLength(); |
335 } | 335 } |
336 | 336 |
337 | 337 |
| 338 NameIndex StreamingFlowGraphBuilder::ReadCanonicalNameReference() { |
| 339 return reader_->ReadCanonicalNameReference(); |
| 340 } |
| 341 |
| 342 |
338 TokenPosition StreamingFlowGraphBuilder::ReadPosition(bool record) { | 343 TokenPosition StreamingFlowGraphBuilder::ReadPosition(bool record) { |
339 return reader_->ReadPosition(record); | 344 return reader_->ReadPosition(record); |
340 } | 345 } |
341 | 346 |
342 | 347 |
343 Tag StreamingFlowGraphBuilder::ReadTag(uint8_t* payload) { | 348 Tag StreamingFlowGraphBuilder::ReadTag(uint8_t* payload) { |
344 return reader_->ReadTag(payload); | 349 return reader_->ReadTag(payload); |
345 } | 350 } |
346 | 351 |
347 | 352 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // The frontend will take care of emitting normal errors (like | 417 // The frontend will take care of emitting normal errors (like |
413 // [NoSuchMethodError]s) and only emit [InvalidExpression]s in very special | 418 // [NoSuchMethodError]s) and only emit [InvalidExpression]s in very special |
414 // situations (e.g. an invalid annotation). | 419 // situations (e.g. an invalid annotation). |
415 return ThrowNoSuchMethodError(); | 420 return ThrowNoSuchMethodError(); |
416 } | 421 } |
417 | 422 |
418 | 423 |
419 Fragment StreamingFlowGraphBuilder::BuildStaticGet() { | 424 Fragment StreamingFlowGraphBuilder::BuildStaticGet() { |
420 intptr_t saved_offset = ReaderOffset() - 1; // Include the tag. | 425 intptr_t saved_offset = ReaderOffset() - 1; // Include the tag. |
421 TokenPosition position = ReadPosition(); | 426 TokenPosition position = ReadPosition(); |
422 intptr_t target = ReadUInt() - 1; | 427 NameIndex target = ReadCanonicalNameReference(); |
423 | 428 |
424 if (H.IsField(target)) { | 429 if (H.IsField(target)) { |
425 const dart::Field& field = | 430 const dart::Field& field = |
426 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); | 431 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(target)); |
427 if (field.is_const()) { | 432 if (field.is_const()) { |
428 SetOffset(saved_offset); // EvaluateExpression needs the tag. | 433 SetOffset(saved_offset); // EvaluateExpression needs the tag. |
429 return Constant(constant_evaluator_.EvaluateExpression()); | 434 return Constant(constant_evaluator_.EvaluateExpression()); |
430 } else { | 435 } else { |
431 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); | 436 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); |
432 const dart::String& getter_name = H.DartGetterName(target); | 437 const dart::String& getter_name = H.DartGetterName(target); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 instructions += PushArgument(); | 480 instructions += PushArgument(); |
476 instructions += LoadLocal(catch_block()->stack_trace_var()); | 481 instructions += LoadLocal(catch_block()->stack_trace_var()); |
477 instructions += PushArgument(); | 482 instructions += PushArgument(); |
478 instructions += RethrowException(position, catch_block()->catch_try_index()); | 483 instructions += RethrowException(position, catch_block()->catch_try_index()); |
479 | 484 |
480 return instructions; | 485 return instructions; |
481 } | 486 } |
482 | 487 |
483 | 488 |
484 Fragment StreamingFlowGraphBuilder::BuildBigIntLiteral() { | 489 Fragment StreamingFlowGraphBuilder::BuildBigIntLiteral() { |
485 const dart::String& value = H.DartString(ReadUInt()); | 490 const dart::String& value = H.DartString(StringIndex(ReadUInt())); |
486 return Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld))); | 491 return Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld))); |
487 } | 492 } |
488 | 493 |
489 | 494 |
490 Fragment StreamingFlowGraphBuilder::BuildStringLiteral() { | 495 Fragment StreamingFlowGraphBuilder::BuildStringLiteral() { |
491 intptr_t str_index = ReadUInt(); | 496 StringIndex str_index(ReadUInt()); |
492 return Constant(H.DartSymbol(str_index)); | 497 return Constant(H.DartSymbol(str_index)); |
493 } | 498 } |
494 | 499 |
495 | 500 |
496 Fragment StreamingFlowGraphBuilder::BuildIntLiteral(uint8_t payload) { | 501 Fragment StreamingFlowGraphBuilder::BuildIntLiteral(uint8_t payload) { |
497 int64_t value = static_cast<int32_t>(payload) - SpecializedIntLiteralBias; | 502 int64_t value = static_cast<int32_t>(payload) - SpecializedIntLiteralBias; |
498 return IntConstant(value); | 503 return IntConstant(value); |
499 } | 504 } |
500 | 505 |
501 | 506 |
(...skipping 16 matching lines...) Expand all Loading... |
518 | 523 |
519 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { | 524 Fragment StreamingFlowGraphBuilder::BuildNullLiteral() { |
520 return Constant(Instance::ZoneHandle(Z, Instance::null())); | 525 return Constant(Instance::ZoneHandle(Z, Instance::null())); |
521 } | 526 } |
522 | 527 |
523 | 528 |
524 } // namespace kernel | 529 } // namespace kernel |
525 } // namespace dart | 530 } // namespace dart |
526 | 531 |
527 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 532 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |