1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_CODEGEN_CODE_COMMENTS_H_ 6 #define V8_CODEGEN_CODE_COMMENTS_H_ 7 8 #include <ostream> 9 #include <string> 10 #include <vector> 11 12 #include "include/v8-internal.h" 13 #include "src/base/macros.h" 14 15 namespace v8 { 16 namespace internal { 17 18 class Assembler; 19 20 // Code comments section layout: 21 // byte count content 22 // ------------------------------------------------------------------------ 23 // 4 size as uint32_t (only for a check) 24 // [Inline array of CodeCommentEntry in increasing pc_offset order] 25 // ┌ 4 pc_offset of entry as uint32_t 26 // ├ 4 length of the comment including terminating '\0' 27 // └ <variable length> characters of the comment including terminating '\0' 28 29 struct CodeCommentEntry { 30 uint32_t pc_offset; 31 std::string comment; 32 uint32_t comment_length() const; 33 uint32_t size() const; 34 }; 35 36 class CodeCommentsWriter { 37 public: 38 V8_EXPORT_PRIVATE void Add(uint32_t pc_offset, std::string comment); 39 void Emit(Assembler* assm); 40 size_t entry_count() const; 41 uint32_t section_size() const; 42 43 private: 44 uint32_t byte_count_ = 0; 45 std::vector<CodeCommentEntry> comments_; 46 }; 47 48 class V8_EXPORT_PRIVATE CodeCommentsIterator { 49 public: 50 CodeCommentsIterator(Address code_comments_start, 51 uint32_t code_comments_size); 52 uint32_t size() const; 53 const char* GetComment() const; 54 uint32_t GetCommentSize() const; 55 uint32_t GetPCOffset() const; 56 void Next(); 57 bool HasCurrent() const; 58 59 private: 60 Address code_comments_start_; 61 uint32_t code_comments_size_; 62 Address current_entry_; 63 }; 64 65 void PrintCodeCommentsSection(std::ostream& out, Address code_comments_start, 66 uint32_t code_comments_size); 67 68 } // namespace internal 69 } // namespace v8 70 71 #endif // V8_CODEGEN_CODE_COMMENTS_H_ 72