LCOV - code coverage report
Current view: top level - src - signature.h (source / functions) Hit Total Coverage
Test: app.info Lines: 21 21 100.0 %
Date: 2019-04-17 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright 2015 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_SIGNATURE_H_
       6             : #define V8_SIGNATURE_H_
       7             : 
       8             : #include "src/base/functional.h"
       9             : #include "src/base/iterator.h"
      10             : #include "src/machine-type.h"
      11             : #include "src/zone/zone.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : // Describes the inputs and outputs of a function or call.
      17             : template <typename T>
      18             : class Signature : public ZoneObject {
      19             :  public:
      20             :   constexpr Signature(size_t return_count, size_t parameter_count,
      21             :                       const T* reps)
      22             :       : return_count_(return_count),
      23             :         parameter_count_(parameter_count),
      24    12049700 :         reps_(reps) {}
      25             : 
      26             :   size_t return_count() const { return return_count_; }
      27             :   size_t parameter_count() const { return parameter_count_; }
      28             : 
      29             :   T GetParam(size_t index) const {
      30             :     DCHECK_LT(index, parameter_count_);
      31   195177936 :     return reps_[return_count_ + index];
      32             :   }
      33             : 
      34             :   T GetReturn(size_t index = 0) const {
      35             :     DCHECK_LT(index, return_count_);
      36    15746525 :     return reps_[index];
      37             :   }
      38             : 
      39             :   // Iteration support.
      40             :   base::iterator_range<const T*> parameters() const {
      41     1836070 :     return {reps_ + return_count_, reps_ + return_count_ + parameter_count_};
      42             :   }
      43             :   base::iterator_range<const T*> returns() const {
      44      160817 :     return {reps_, reps_ + return_count_};
      45             :   }
      46             :   base::iterator_range<const T*> all() const {
      47     3436145 :     return {reps_, reps_ + return_count_ + parameter_count_};
      48             :   }
      49             : 
      50      362675 :   bool operator==(const Signature& other) const {
      51      362675 :     if (this == &other) return true;
      52      362675 :     if (parameter_count() != other.parameter_count()) return false;
      53      362192 :     if (return_count() != other.return_count()) return false;
      54             :     return std::equal(all().begin(), all().end(), other.all().begin());
      55             :   }
      56      107280 :   bool operator!=(const Signature& other) const { return !(*this == other); }
      57             : 
      58             :   // For incrementally building signatures.
      59             :   class Builder {
      60             :    public:
      61             :     Builder(Zone* zone, size_t return_count, size_t parameter_count)
      62             :         : return_count_(return_count),
      63             :           parameter_count_(parameter_count),
      64             :           zone_(zone),
      65             :           rcursor_(0),
      66             :           pcursor_(0),
      67             :           buffer_(zone->NewArray<T>(
      68    12480528 :               static_cast<int>(return_count + parameter_count))) {}
      69             : 
      70             :     const size_t return_count_;
      71             :     const size_t parameter_count_;
      72             : 
      73             :     void AddReturn(T val) {
      74             :       DCHECK_LT(rcursor_, return_count_);
      75     9628478 :       buffer_[rcursor_++] = val;
      76             :     }
      77             : 
      78             :     void AddParam(T val) {
      79             :       DCHECK_LT(pcursor_, parameter_count_);
      80    21989390 :       buffer_[return_count_ + pcursor_++] = val;
      81             :     }
      82             : 
      83             :     void AddParamAt(size_t index, T val) {
      84             :       DCHECK_LT(index, parameter_count_);
      85      954376 :       buffer_[return_count_ + index] = val;
      86     1908752 :       pcursor_ = std::max(pcursor_, index + 1);
      87             :     }
      88             : 
      89             :     Signature<T>* Build() {
      90             :       DCHECK_EQ(rcursor_, return_count_);
      91             :       DCHECK_EQ(pcursor_, parameter_count_);
      92     5042301 :       return new (zone_) Signature<T>(return_count_, parameter_count_, buffer_);
      93             :     }
      94             : 
      95             :    private:
      96             :     Zone* zone_;
      97             :     size_t rcursor_;
      98             :     size_t pcursor_;
      99             :     T* buffer_;
     100             :   };
     101             : 
     102             :  protected:
     103             :   size_t return_count_;
     104             :   size_t parameter_count_;
     105             :   const T* reps_;
     106             : };
     107             : 
     108             : typedef Signature<MachineType> MachineSignature;
     109             : 
     110             : template <typename T>
     111     1396435 : size_t hash_value(const Signature<T>& sig) {
     112     1396435 :   size_t hash = base::hash_combine(sig.parameter_count(), sig.return_count());
     113     5860960 :   for (const T& t : sig.all()) hash = base::hash_combine(hash, t);
     114     1396441 :   return hash;
     115             : }
     116             : 
     117             : }  // namespace internal
     118             : }  // namespace v8
     119             : 
     120             : #endif  // V8_SIGNATURE_H_

Generated by: LCOV version 1.10