v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
code-comments.cc
Go to the documentation of this file.
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#include <cstring>
6#include <iomanip>
7
10
11namespace v8 {
12namespace internal {
13
14namespace {
15static constexpr uint8_t kOffsetToFirstCommentEntry = kUInt32Size;
16static constexpr uint8_t kOffsetToPCOffset = 0;
17static constexpr uint8_t kOffsetToCommentSize = kOffsetToPCOffset + kUInt32Size;
18static constexpr uint8_t kOffsetToCommentString =
19 kOffsetToCommentSize + kUInt32Size;
20} // namespace
21
23 return static_cast<uint32_t>(comment.size() + 1);
24}
25
26uint32_t CodeCommentEntry::size() const {
27 return kOffsetToCommentString + comment_length();
28}
29
31 uint32_t code_comments_size)
32 : code_comments_start_(code_comments_start),
33 code_comments_size_(code_comments_size),
34 current_entry_(code_comments_start + kOffsetToFirstCommentEntry) {
35 DCHECK_NE(kNullAddress, code_comments_start);
36 DCHECK_IMPLIES(code_comments_size,
37 code_comments_size ==
39}
40
42
44 const char* comment_string =
45 reinterpret_cast<const char*>(current_entry_ + kOffsetToCommentString);
46 CHECK_EQ(GetCommentSize(), strlen(comment_string) + 1);
47 return comment_string;
48}
49
51 return ReadUnalignedValue<uint32_t>(current_entry_ + kOffsetToCommentSize);
52}
53
55 return ReadUnalignedValue<uint32_t>(current_entry_ + kOffsetToPCOffset);
56}
57
59 current_entry_ += kOffsetToCommentString + GetCommentSize();
60}
61
65
67 assm->dd(section_size());
68 for (auto i = comments_.begin(); i != comments_.end(); ++i) {
69 assm->dd(i->pc_offset);
70 assm->dd(i->comment_length());
71 for (char c : i->comment) {
72 EnsureSpace ensure_space(assm);
73 assm->db(c);
74 }
75 assm->db('\0');
76 }
77}
78
79void CodeCommentsWriter::Add(uint32_t pc_offset, std::string comment) {
80 CodeCommentEntry entry = {pc_offset, std::move(comment)};
81 byte_count_ += entry.size();
82 comments_.push_back(std::move(entry));
83}
84
85size_t CodeCommentsWriter::entry_count() const { return comments_.size(); }
87 return kOffsetToFirstCommentEntry + static_cast<uint32_t>(byte_count_);
88}
89
90} // namespace internal
91} // namespace v8
CodeCommentsIterator(Address code_comments_start, uint32_t code_comments_size)
V8_EXPORT_PRIVATE void Add(uint32_t pc_offset, std::string comment)
std::vector< CodeCommentEntry > comments_
int pc_offset
static V ReadUnalignedValue(Address p)
Definition memory.h:28
constexpr int kUInt32Size
Definition globals.h:403
static constexpr Address kNullAddress
Definition v8-internal.h:53
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define CHECK_EQ(lhs, rhs)