LCOV - code coverage report
Current view: top level - src - code-comments.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 32 49 65.3 %
Date: 2019-02-19 Functions: 9 16 56.2 %

          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             : #include <cstring>
       6             : #include <iomanip>
       7             : 
       8             : #include "src/assembler-inl.h"
       9             : #include "src/code-comments.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : 
      14             : namespace {
      15             : static constexpr uint8_t kOffsetToFirstCommentEntry = kUInt32Size;
      16             : static constexpr uint8_t kOffsetToPCOffset = 0;
      17             : static constexpr uint8_t kOffsetToCommentSize = kOffsetToPCOffset + kUInt32Size;
      18             : static constexpr uint8_t kOffsetToCommentString =
      19             :     kOffsetToCommentSize + kUInt32Size;
      20             : }  // namespace
      21             : 
      22           0 : uint32_t CodeCommentEntry::comment_length() const {
      23        9330 :   return static_cast<uint32_t>(comment.size() + 1);
      24             : }
      25             : 
      26           0 : uint32_t CodeCommentEntry::size() const {
      27        4679 :   return kOffsetToCommentString + comment_length();
      28             : }
      29             : 
      30           4 : CodeCommentsIterator::CodeCommentsIterator(Address code_comments_start)
      31             :     : code_comments_start_(code_comments_start),
      32           4 :       current_entry_(code_comments_start + kOffsetToFirstCommentEntry) {}
      33             : 
      34           0 : uint32_t CodeCommentsIterator::size() const {
      35           0 :   return code_comments_start_ != kNullAddress
      36             :              ? *reinterpret_cast<uint32_t*>(code_comments_start_)
      37          24 :              : 0;
      38             : }
      39             : 
      40          16 : const char* CodeCommentsIterator::GetComment() const {
      41             :   const char* comment_string =
      42          16 :       reinterpret_cast<const char*>(current_entry_ + kOffsetToCommentString);
      43          32 :   CHECK_EQ(GetCommentSize(), strlen(comment_string) + 1);
      44          16 :   return comment_string;
      45             : }
      46             : 
      47           0 : uint32_t CodeCommentsIterator::GetCommentSize() const {
      48          32 :   return ReadUnalignedValue<uint32_t>(current_entry_ + kOffsetToCommentSize);
      49             : }
      50             : 
      51           0 : uint32_t CodeCommentsIterator::GetPCOffset() const {
      52           0 :   return ReadUnalignedValue<uint32_t>(current_entry_ + kOffsetToPCOffset);
      53             : }
      54             : 
      55          16 : void CodeCommentsIterator::Next() {
      56          16 :   current_entry_ += kOffsetToCommentString + GetCommentSize();
      57          16 : }
      58             : 
      59          24 : bool CodeCommentsIterator::HasCurrent() const {
      60          48 :   return current_entry_ < code_comments_start_ + size();
      61             : }
      62             : 
      63          73 : void CodeCommentsWriter::Emit(Assembler* assm) {
      64          73 :   assm->dd(section_size());
      65        4797 :   for (auto i = comments_.begin(); i != comments_.end(); ++i) {
      66        4651 :     assm->dd(i->pc_offset);
      67        4651 :     assm->dd(i->comment_length());
      68      204805 :     for (char c : i->comment) {
      69             :       EnsureSpace ensure_space(assm);
      70      190852 :       assm->db(c);
      71             :     }
      72        4651 :     assm->db('\0');
      73             :   }
      74          73 : }
      75             : 
      76        4679 : void CodeCommentsWriter::Add(uint32_t pc_offset, std::string comment) {
      77        4679 :   CodeCommentEntry entry = {pc_offset, std::move(comment)};
      78        4679 :   byte_count_ += entry.size();
      79        4679 :   comments_.push_back(std::move(entry));
      80        4679 : }
      81             : 
      82         176 : size_t CodeCommentsWriter::entry_count() const { return comments_.size(); }
      83           0 : uint32_t CodeCommentsWriter::section_size() const {
      84          73 :   return kOffsetToFirstCommentEntry + static_cast<uint32_t>(byte_count_);
      85             : }
      86             : 
      87           0 : void PrintCodeCommentsSection(std::ostream& out, Address code_comments_start) {
      88             :   CodeCommentsIterator it(code_comments_start);
      89           0 :   out << "CodeComments (size = " << it.size() << ")\n";
      90           0 :   if (it.HasCurrent()) {
      91           0 :     out << std::setw(6) << "pc" << std::setw(6) << "len"
      92           0 :         << " comment\n";
      93             :   }
      94           0 :   for (; it.HasCurrent(); it.Next()) {
      95             :     out << std::hex << std::setw(6) << it.GetPCOffset() << std::dec
      96           0 :         << std::setw(6) << it.GetCommentSize() << " (" << it.GetComment()
      97           0 :         << ")\n";
      98             :   }
      99           0 : }
     100             : 
     101             : }  // namespace internal
     102      178779 : }  // namespace v8

Generated by: LCOV version 1.10