OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 #ifndef RUNTIME_VM_KERNEL_BINARY_H_ | 5 #ifndef RUNTIME_VM_KERNEL_BINARY_H_ |
6 #define RUNTIME_VM_KERNEL_BINARY_H_ | 6 #define RUNTIME_VM_KERNEL_BINARY_H_ |
7 | 7 |
8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 BlockStack<VariableDeclaration> scope_; | 324 BlockStack<VariableDeclaration> scope_; |
325 BlockStack<TypeParameter> type_parameters_; | 325 BlockStack<TypeParameter> type_parameters_; |
326 BlockStack<SwitchCase> switch_cases_; | 326 BlockStack<SwitchCase> switch_cases_; |
327 BlockStack<LabeledStatement>* labels_; | 327 BlockStack<LabeledStatement>* labels_; |
328 }; | 328 }; |
329 | 329 |
330 | 330 |
331 class Reader { | 331 class Reader { |
332 public: | 332 public: |
333 Reader(const uint8_t* buffer, intptr_t size) | 333 Reader(const uint8_t* buffer, intptr_t size) |
334 : buffer_(buffer), size_(size), offset_(0), string_data_offset_(-1) {} | 334 : buffer_(buffer), |
| 335 size_(size), |
| 336 offset_(0), |
| 337 string_table_offset_(-1), |
| 338 string_data_offset_(-1), |
| 339 string_offsets_(NULL) {} |
| 340 |
| 341 ~Reader() { delete[] string_offsets_; } |
335 | 342 |
336 uint32_t ReadUInt32() { | 343 uint32_t ReadUInt32() { |
337 ASSERT(offset_ + 4 <= size_); | 344 ASSERT(offset_ + 4 <= size_); |
338 | 345 |
339 uint32_t value = (buffer_[offset_ + 0] << 24) | | 346 uint32_t value = (buffer_[offset_ + 0] << 24) | |
340 (buffer_[offset_ + 1] << 16) | | 347 (buffer_[offset_ + 1] << 16) | |
341 (buffer_[offset_ + 2] << 8) | (buffer_[offset_ + 3] << 0); | 348 (buffer_[offset_ + 2] << 8) | (buffer_[offset_ + 3] << 0); |
342 offset_ += 4; | 349 offset_ += 4; |
343 return value; | 350 return value; |
344 } | 351 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 ASSERT(name != NULL); | 504 ASSERT(name != NULL); |
498 return name; | 505 return name; |
499 } | 506 } |
500 | 507 |
501 intptr_t offset() { return offset_; } | 508 intptr_t offset() { return offset_; } |
502 void set_offset(intptr_t offset) { offset_ = offset; } | 509 void set_offset(intptr_t offset) { offset_ = offset; } |
503 intptr_t size() { return size_; } | 510 intptr_t size() { return size_; } |
504 | 511 |
505 const uint8_t* buffer() { return buffer_; } | 512 const uint8_t* buffer() { return buffer_; } |
506 | 513 |
| 514 intptr_t string_table_offset() { return string_table_offset_; } |
| 515 void MarkStringTableOffset() { |
| 516 ASSERT(string_table_offset_ == -1); |
| 517 string_table_offset_ = offset_; |
| 518 } |
| 519 |
507 intptr_t string_data_offset() { return string_data_offset_; } | 520 intptr_t string_data_offset() { return string_data_offset_; } |
508 void MarkStringDataOffset() { | 521 void MarkStringDataOffset() { |
509 ASSERT(string_data_offset_ == -1); | 522 ASSERT(string_data_offset_ == -1); |
510 string_data_offset_ = offset_; | 523 string_data_offset_ = offset_; |
511 } | 524 } |
512 | 525 |
513 uint8_t CharacterAt(String* str, intptr_t index) { | 526 intptr_t StringLength(intptr_t string_index) { |
514 ASSERT(index < str->size()); | 527 return string_offsets_[string_index + 1] - string_offsets_[string_index]; |
515 return buffer_[string_data_offset_ + str->offset() + index]; | 528 } |
| 529 |
| 530 uint8_t CharacterAt(intptr_t string_index, intptr_t index) { |
| 531 ASSERT(index < StringLength(string_index)); |
| 532 return buffer_[string_data_offset_ + string_offsets_[string_index] + index]; |
516 } | 533 } |
517 | 534 |
518 private: | 535 private: |
519 const uint8_t* buffer_; | 536 const uint8_t* buffer_; |
520 intptr_t size_; | 537 intptr_t size_; |
521 intptr_t offset_; | 538 intptr_t offset_; |
522 ReaderHelper builder_; | 539 ReaderHelper builder_; |
523 TokenPosition max_position_; | 540 TokenPosition max_position_; |
524 TokenPosition min_position_; | 541 TokenPosition min_position_; |
525 intptr_t current_script_id_; | 542 intptr_t current_script_id_; |
526 | 543 |
| 544 // When the binary is deserialized the offset of the start of the string table |
| 545 // (the length) and the offset of the start of the string data are recorded. |
| 546 intptr_t string_table_offset_; |
527 intptr_t string_data_offset_; | 547 intptr_t string_data_offset_; |
528 | 548 |
| 549 // The string offsets are decoded to support efficient access to string UTF-8 |
| 550 // encodings. |
| 551 intptr_t* string_offsets_; |
| 552 |
529 friend class PositionScope; | 553 friend class PositionScope; |
| 554 friend class Program; |
530 }; | 555 }; |
531 | 556 |
532 | 557 |
533 // A helper class that resets the readers min and max positions both upon | 558 // A helper class that resets the readers min and max positions both upon |
534 // initialization and upon destruction, i.e. when created the min an max | 559 // initialization and upon destruction, i.e. when created the min an max |
535 // positions will be reset to "noSource", when destructing the min and max will | 560 // positions will be reset to "noSource", when destructing the min and max will |
536 // be reset to have they value they would have had, if they hadn't been reset in | 561 // be reset to have they value they would have had, if they hadn't been reset in |
537 // the first place. | 562 // the first place. |
538 class PositionScope { | 563 class PositionScope { |
539 public: | 564 public: |
(...skipping 17 matching lines...) Expand all Loading... |
557 Reader* reader_; | 582 Reader* reader_; |
558 TokenPosition min_; | 583 TokenPosition min_; |
559 TokenPosition max_; | 584 TokenPosition max_; |
560 }; | 585 }; |
561 | 586 |
562 } // namespace kernel | 587 } // namespace kernel |
563 } // namespace dart | 588 } // namespace dart |
564 | 589 |
565 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 590 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
566 #endif // RUNTIME_VM_KERNEL_BINARY_H_ | 591 #endif // RUNTIME_VM_KERNEL_BINARY_H_ |
OLD | NEW |