11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_CODEGEN_CODE_COMMENTS_H_ 61cb0ef41Sopenharmony_ci#define V8_CODEGEN_CODE_COMMENTS_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include <ostream> 91cb0ef41Sopenharmony_ci#include <string> 101cb0ef41Sopenharmony_ci#include <vector> 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci#include "include/v8-internal.h" 131cb0ef41Sopenharmony_ci#include "src/base/macros.h" 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cinamespace v8 { 161cb0ef41Sopenharmony_cinamespace internal { 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciclass Assembler; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci// Code comments section layout: 211cb0ef41Sopenharmony_ci// byte count content 221cb0ef41Sopenharmony_ci// ------------------------------------------------------------------------ 231cb0ef41Sopenharmony_ci// 4 size as uint32_t (only for a check) 241cb0ef41Sopenharmony_ci// [Inline array of CodeCommentEntry in increasing pc_offset order] 251cb0ef41Sopenharmony_ci// ┌ 4 pc_offset of entry as uint32_t 261cb0ef41Sopenharmony_ci// ├ 4 length of the comment including terminating '\0' 271cb0ef41Sopenharmony_ci// └ <variable length> characters of the comment including terminating '\0' 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cistruct CodeCommentEntry { 301cb0ef41Sopenharmony_ci uint32_t pc_offset; 311cb0ef41Sopenharmony_ci std::string comment; 321cb0ef41Sopenharmony_ci uint32_t comment_length() const; 331cb0ef41Sopenharmony_ci uint32_t size() const; 341cb0ef41Sopenharmony_ci}; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciclass CodeCommentsWriter { 371cb0ef41Sopenharmony_ci public: 381cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE void Add(uint32_t pc_offset, std::string comment); 391cb0ef41Sopenharmony_ci void Emit(Assembler* assm); 401cb0ef41Sopenharmony_ci size_t entry_count() const; 411cb0ef41Sopenharmony_ci uint32_t section_size() const; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci private: 441cb0ef41Sopenharmony_ci uint32_t byte_count_ = 0; 451cb0ef41Sopenharmony_ci std::vector<CodeCommentEntry> comments_; 461cb0ef41Sopenharmony_ci}; 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE CodeCommentsIterator { 491cb0ef41Sopenharmony_ci public: 501cb0ef41Sopenharmony_ci CodeCommentsIterator(Address code_comments_start, 511cb0ef41Sopenharmony_ci uint32_t code_comments_size); 521cb0ef41Sopenharmony_ci uint32_t size() const; 531cb0ef41Sopenharmony_ci const char* GetComment() const; 541cb0ef41Sopenharmony_ci uint32_t GetCommentSize() const; 551cb0ef41Sopenharmony_ci uint32_t GetPCOffset() const; 561cb0ef41Sopenharmony_ci void Next(); 571cb0ef41Sopenharmony_ci bool HasCurrent() const; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci private: 601cb0ef41Sopenharmony_ci Address code_comments_start_; 611cb0ef41Sopenharmony_ci uint32_t code_comments_size_; 621cb0ef41Sopenharmony_ci Address current_entry_; 631cb0ef41Sopenharmony_ci}; 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci} // namespace internal 661cb0ef41Sopenharmony_ci} // namespace v8 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci#endif // V8_CODEGEN_CODE_COMMENTS_H_ 69