5 #ifndef V8_SIGNATURE_H_ 6 #define V8_SIGNATURE_H_ 8 #include "src/base/functional.h" 9 #include "src/base/iterator.h" 10 #include "src/machine-type.h" 11 #include "src/zone/zone.h" 18 class Signature :
public ZoneObject {
20 constexpr Signature(
size_t return_count,
size_t parameter_count,
22 : return_count_(return_count),
23 parameter_count_(parameter_count),
26 size_t return_count()
const {
return return_count_; }
27 size_t parameter_count()
const {
return parameter_count_; }
29 T GetParam(
size_t index)
const {
30 DCHECK(index < parameter_count_);
31 return reps_[return_count_ + index];
34 T GetReturn(
size_t index = 0)
const {
35 DCHECK(index < return_count_);
40 base::iterator_range<const T*> parameters()
const {
41 return {reps_ + return_count_, reps_ + return_count_ + parameter_count_};
43 base::iterator_range<const T*> returns()
const {
44 return {reps_, reps_ + return_count_};
46 base::iterator_range<const T*> all()
const {
47 return {reps_, reps_ + return_count_ + parameter_count_};
50 bool operator==(
const Signature& other)
const {
51 if (
this == &other)
return true;
52 if (parameter_count() != other.parameter_count())
return false;
53 if (return_count() != other.return_count())
return false;
54 return std::equal(all().begin(), all().end(), other.all().begin());
56 bool operator!=(
const Signature& other)
const {
return !(*
this == other); }
61 Builder(
Zone* zone,
size_t return_count,
size_t parameter_count)
62 : return_count_(return_count),
63 parameter_count_(parameter_count),
67 buffer_(zone->NewArray<
T>(
68 static_cast<int>(return_count + parameter_count))) {}
70 const size_t return_count_;
71 const size_t parameter_count_;
73 void AddReturn(
T val) {
74 DCHECK(rcursor_ < return_count_);
75 buffer_[rcursor_++] = val;
77 void AddParam(
T val) {
78 DCHECK(pcursor_ < parameter_count_);
79 buffer_[return_count_ + pcursor_++] = val;
82 DCHECK(rcursor_ == return_count_);
83 DCHECK(pcursor_ == parameter_count_);
84 return new (zone_)
Signature<T>(return_count_, parameter_count_, buffer_);
96 size_t parameter_count_;
102 template <
typename T>
104 size_t hash = base::hash_combine(sig.parameter_count(), sig.return_count());
105 for (
const T& t : sig.all()) hash = base::hash_combine(hash, t);
112 #endif // V8_SIGNATURE_H_