Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1571)

Side by Side Diff: runtime/vm/kernel_binary.cc

Issue 2632183002: Debugging in kernel shaping up. (Closed)
Patch Set: Changed to TokenPosition::kMaxSourcePos Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/kernel.cc ('k') | runtime/vm/kernel_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if !defined(DART_PRECOMPILED_RUNTIME) 4 #if !defined(DART_PRECOMPILED_RUNTIME)
5 5
6 #include "platform/globals.h" 6 #include "platform/globals.h"
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/growable_array.h" 8 #include "vm/growable_array.h"
9 #include "vm/kernel.h" 9 #include "vm/kernel.h"
10 #include "vm/kernel_to_il.h" 10 #include "vm/kernel_to_il.h"
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // 11... 362 // 11...
363 ASSERT(offset_ + 4 <= size_); 363 ASSERT(offset_ + 4 <= size_);
364 uint32_t value = ((byte0 & ~0xc0) << 24) | (buffer_[offset_ + 1] << 16) | 364 uint32_t value = ((byte0 & ~0xc0) << 24) | (buffer_[offset_ + 1] << 16) |
365 (buffer_[offset_ + 2] << 8) | 365 (buffer_[offset_ + 2] << 8) |
366 (buffer_[offset_ + 3] << 0); 366 (buffer_[offset_ + 3] << 0);
367 offset_ += 4; 367 offset_ += 4;
368 return value; 368 return value;
369 } 369 }
370 } 370 }
371 371
372 void add_token_position(
373 MallocGrowableArray<MallocGrowableArray<intptr_t>*>* list,
374 TokenPosition position) {
375 intptr_t size = list->length();
376 while (size <= current_script_id_) {
377 MallocGrowableArray<intptr_t>* tmp = new MallocGrowableArray<intptr_t>();
378 list->Add(tmp);
379 size = list->length();
380 }
381 list->At(current_script_id_)->Add(position.value());
382 }
383
384 void record_token_position(TokenPosition position) {
385 if (position.IsReal()) {
386 add_token_position(&helper()->program()->valid_token_positions, position);
387 }
388 }
389
390 void record_yield_token_position(TokenPosition position) {
391 add_token_position(&helper()->program()->yield_token_positions, position);
392 }
393
372 /** 394 /**
373 * Read and return a TokenPosition from this reader. 395 * Read and return a TokenPosition from this reader.
396 * @param record specifies whether or not the read position is saved as a
397 * valid token position in the current script.
398 * If not be sure to record it later by calling record_token_position (after
399 * setting the correct current_script_id).
374 */ 400 */
375 TokenPosition ReadPosition() { 401 TokenPosition ReadPosition(bool record = true) {
376 // Position is saved as unsigned, 402 // Position is saved as unsigned,
377 // but actually ranges from -1 and up (thus the -1) 403 // but actually ranges from -1 and up (thus the -1)
378 intptr_t value = ReadUInt() - 1; 404 intptr_t value = ReadUInt() - 1;
379 TokenPosition result = TokenPosition(value); 405 TokenPosition result = TokenPosition(value);
380 max_position_ = Utils::Maximum(max_position_, result); 406 max_position_ = Utils::Maximum(max_position_, result);
381 if (min_position_.IsNoSource()) { 407 if (min_position_.IsNoSource()) {
382 min_position_ = result; 408 min_position_ = result;
383 } else if (result.IsReal()) { 409 } else if (result.IsReal()) {
384 min_position_ = Utils::Minimum(min_position_, result); 410 min_position_ = Utils::Minimum(min_position_, result);
385 } 411 }
386 412
413 if (record) {
414 record_token_position(result);
415 }
387 return result; 416 return result;
388 } 417 }
389 418
390 intptr_t ReadListLength() { return ReadUInt(); } 419 intptr_t ReadListLength() { return ReadUInt(); }
391 420
392 uint8_t ReadByte() { return buffer_[offset_++]; } 421 uint8_t ReadByte() { return buffer_[offset_++]; }
393 422
394 bool ReadBool() { return (ReadByte() & 1) == 1; } 423 bool ReadBool() { return (ReadByte() & 1) == 1; }
395 424
396 word ReadFlags() { return ReadByte(); } 425 word ReadFlags() { return ReadByte(); }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 694
666 fields().ReadFrom<Field>(reader, this); 695 fields().ReadFrom<Field>(reader, this);
667 procedures().ReadFrom<Procedure>(reader, this); 696 procedures().ReadFrom<Procedure>(reader, this);
668 return this; 697 return this;
669 } 698 }
670 699
671 700
672 Class* Class::ReadFrom(Reader* reader) { 701 Class* Class::ReadFrom(Reader* reader) {
673 TRACE_READ_OFFSET(); 702 TRACE_READ_OFFSET();
674 703
675 position_ = reader->ReadPosition(); 704 position_ = reader->ReadPosition(false);
676 is_abstract_ = reader->ReadBool(); 705 is_abstract_ = reader->ReadBool();
677 name_ = Reference::ReadStringFrom(reader); 706 name_ = Reference::ReadStringFrom(reader);
678 source_uri_index_ = reader->ReadUInt(); 707 source_uri_index_ = reader->ReadUInt();
679 reader->set_current_script_id(source_uri_index_); 708 reader->set_current_script_id(source_uri_index_);
709 reader->record_token_position(position_);
680 annotations_.ReadFromStatic<Expression>(reader); 710 annotations_.ReadFromStatic<Expression>(reader);
681 711
682 return this; 712 return this;
683 } 713 }
684 714
685 715
686 NormalClass* NormalClass::ReadFrom(Reader* reader) { 716 NormalClass* NormalClass::ReadFrom(Reader* reader) {
687 TRACE_READ_OFFSET(); 717 TRACE_READ_OFFSET();
688 Class::ReadFrom(reader); 718 Class::ReadFrom(reader);
689 TypeParameterScope<ReaderHelper> scope(reader->helper()); 719 TypeParameterScope<ReaderHelper> scope(reader->helper());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 int index = reader->ReadUInt(); 830 int index = reader->ReadUInt();
801 return reader->helper()->program()->string_table().strings()[index]; 831 return reader->helper()->program()->string_table().strings()[index];
802 } 832 }
803 833
804 834
805 Field* Field::ReadFrom(Reader* reader) { 835 Field* Field::ReadFrom(Reader* reader) {
806 TRACE_READ_OFFSET(); 836 TRACE_READ_OFFSET();
807 Tag tag = reader->ReadTag(); 837 Tag tag = reader->ReadTag();
808 ASSERT(tag == kField); 838 ASSERT(tag == kField);
809 839
810 position_ = reader->ReadPosition(); 840 position_ = reader->ReadPosition(false);
811 end_position_ = reader->ReadPosition(); 841 end_position_ = reader->ReadPosition(false);
812 flags_ = reader->ReadFlags(); 842 flags_ = reader->ReadFlags();
813 name_ = Name::ReadFrom(reader); 843 name_ = Name::ReadFrom(reader);
814 source_uri_index_ = reader->ReadUInt(); 844 source_uri_index_ = reader->ReadUInt();
815 reader->set_current_script_id(source_uri_index_); 845 reader->set_current_script_id(source_uri_index_);
846 reader->record_token_position(position_);
847 reader->record_token_position(end_position_);
816 annotations_.ReadFromStatic<Expression>(reader); 848 annotations_.ReadFromStatic<Expression>(reader);
817 type_ = DartType::ReadFrom(reader); 849 type_ = DartType::ReadFrom(reader);
818 inferred_value_ = reader->ReadOptional<InferredValue>(); 850 inferred_value_ = reader->ReadOptional<InferredValue>();
819 initializer_ = reader->ReadOptional<Expression>(); 851 initializer_ = reader->ReadOptional<Expression>();
820 return this; 852 return this;
821 } 853 }
822 854
823 855
824 Constructor* Constructor::ReadFrom(Reader* reader) { 856 Constructor* Constructor::ReadFrom(Reader* reader) {
825 TRACE_READ_OFFSET(); 857 TRACE_READ_OFFSET();
(...skipping 11 matching lines...) Expand all
837 return this; 869 return this;
838 } 870 }
839 871
840 872
841 Procedure* Procedure::ReadFrom(Reader* reader) { 873 Procedure* Procedure::ReadFrom(Reader* reader) {
842 TRACE_READ_OFFSET(); 874 TRACE_READ_OFFSET();
843 Tag tag = reader->ReadTag(); 875 Tag tag = reader->ReadTag();
844 ASSERT(tag == kProcedure); 876 ASSERT(tag == kProcedure);
845 877
846 VariableScope<ReaderHelper> parameters(reader->helper()); 878 VariableScope<ReaderHelper> parameters(reader->helper());
847 position_ = reader->ReadPosition(); 879 position_ = reader->ReadPosition(false);
848 end_position_ = reader->ReadPosition(); 880 end_position_ = reader->ReadPosition(false);
849 kind_ = static_cast<ProcedureKind>(reader->ReadByte()); 881 kind_ = static_cast<ProcedureKind>(reader->ReadByte());
850 flags_ = reader->ReadFlags(); 882 flags_ = reader->ReadFlags();
851 name_ = Name::ReadFrom(reader); 883 name_ = Name::ReadFrom(reader);
852 source_uri_index_ = reader->ReadUInt(); 884 source_uri_index_ = reader->ReadUInt();
853 reader->set_current_script_id(source_uri_index_); 885 reader->set_current_script_id(source_uri_index_);
886 reader->record_token_position(position_);
887 reader->record_token_position(end_position_);
854 annotations_.ReadFromStatic<Expression>(reader); 888 annotations_.ReadFromStatic<Expression>(reader);
855 function_ = reader->ReadOptional<FunctionNode>(); 889 function_ = reader->ReadOptional<FunctionNode>();
856 return this; 890 return this;
857 } 891 }
858 892
859 893
860 Initializer* Initializer::ReadFrom(Reader* reader) { 894 Initializer* Initializer::ReadFrom(Reader* reader) {
861 TRACE_READ_OFFSET(); 895 TRACE_READ_OFFSET();
862 Tag tag = reader->ReadTag(); 896 Tag tag = reader->ReadTag();
863 switch (tag) { 897 switch (tag) {
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 tf->body_ = Statement::ReadFrom(reader); 1687 tf->body_ = Statement::ReadFrom(reader);
1654 tf->finalizer_ = Statement::ReadFrom(reader); 1688 tf->finalizer_ = Statement::ReadFrom(reader);
1655 return tf; 1689 return tf;
1656 } 1690 }
1657 1691
1658 1692
1659 YieldStatement* YieldStatement::ReadFrom(Reader* reader) { 1693 YieldStatement* YieldStatement::ReadFrom(Reader* reader) {
1660 TRACE_READ_OFFSET(); 1694 TRACE_READ_OFFSET();
1661 YieldStatement* stmt = new YieldStatement(); 1695 YieldStatement* stmt = new YieldStatement();
1662 stmt->position_ = reader->ReadPosition(); 1696 stmt->position_ = reader->ReadPosition();
1697 reader->record_yield_token_position(stmt->position_);
1663 stmt->flags_ = reader->ReadByte(); 1698 stmt->flags_ = reader->ReadByte();
1664 stmt->expression_ = Expression::ReadFrom(reader); 1699 stmt->expression_ = Expression::ReadFrom(reader);
1665 return stmt; 1700 return stmt;
1666 } 1701 }
1667 1702
1668 1703
1669 VariableDeclaration* VariableDeclaration::ReadFrom(Reader* reader) { 1704 VariableDeclaration* VariableDeclaration::ReadFrom(Reader* reader) {
1670 TRACE_READ_OFFSET(); 1705 TRACE_READ_OFFSET();
1671 Tag tag = reader->ReadTag(); 1706 Tag tag = reader->ReadTag();
1672 ASSERT(tag == kVariableDeclaration); 1707 ASSERT(tag == kVariableDeclaration);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 1927
1893 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, 1928 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer,
1894 intptr_t buffer_length) { 1929 intptr_t buffer_length) {
1895 kernel::Reader reader(buffer, buffer_length); 1930 kernel::Reader reader(buffer, buffer_length);
1896 return kernel::Program::ReadFrom(&reader); 1931 return kernel::Program::ReadFrom(&reader);
1897 } 1932 }
1898 1933
1899 1934
1900 } // namespace dart 1935 } // namespace dart
1901 #endif // !defined(DART_PRECOMPILED_RUNTIME) 1936 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel.cc ('k') | runtime/vm/kernel_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698