Line data Source code
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_CODE_COMMENTS_H_
6 : #define V8_CODE_COMMENTS_H_
7 :
8 : #include <ostream>
9 : #include <string>
10 : #include <vector>
11 :
12 : #include "include/v8-internal.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 : class Assembler;
18 :
19 : // Code comments section layout:
20 : // byte count content
21 : // ------------------------------------------------------------------------
22 : // 4 size as uint32_t
23 : // [Inline array of CodeCommentEntry in increasing pc_offset order]
24 : // ┌ 4 pc_offset of entry as uint32_t
25 : // ├ 4 length of the comment including terminating '\0'
26 : // └ <variable length> characters of the comment including terminating '\0'
27 :
28 10070 : struct CodeCommentEntry {
29 : uint32_t pc_offset;
30 : std::string comment;
31 : uint32_t comment_length() const;
32 : uint32_t size() const;
33 : };
34 :
35 12955927 : class CodeCommentsWriter {
36 : public:
37 : void Add(uint32_t pc_offset, std::string comment);
38 : void Emit(Assembler* assm);
39 : size_t entry_count() const;
40 : uint32_t section_size() const;
41 :
42 : private:
43 : uint32_t byte_count_ = 0;
44 : std::vector<CodeCommentEntry> comments_;
45 : };
46 :
47 : class CodeCommentsIterator {
48 : public:
49 : // Address can be kNullAddress. In this case HasCurrent() will return false.
50 : explicit CodeCommentsIterator(Address code_comments_start);
51 : uint32_t size() const;
52 : const char* GetComment() const;
53 : uint32_t GetCommentSize() const;
54 : uint32_t GetPCOffset() const;
55 : void Next();
56 : bool HasCurrent() const;
57 :
58 : private:
59 : Address code_comments_start_;
60 : Address current_entry_;
61 : };
62 :
63 : void PrintCodeCommentsSection(std::ostream& out, Address code_comments_start);
64 :
65 : } // namespace internal
66 : } // namespace v8
67 :
68 : #endif // V8_CODE_COMMENTS_H_
|