diff options
Diffstat (limited to 'deps/v8/src/codegen/signature.h')
-rw-r--r-- | deps/v8/src/codegen/signature.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/deps/v8/src/codegen/signature.h b/deps/v8/src/codegen/signature.h index bba3a1b13d..2c4ca3e0d9 100644 --- a/deps/v8/src/codegen/signature.h +++ b/deps/v8/src/codegen/signature.h @@ -124,6 +124,60 @@ size_t hash_value(const Signature<T>& sig) { return hash; } +template <typename T, size_t kNumReturns = 0, size_t kNumParams = 0> +class FixedSizeSignature : public Signature<T> { + public: + // Add return types to this signature (only allowed if there are none yet). + template <typename... ReturnTypes> + auto Returns(ReturnTypes... return_types) const { + static_assert(kNumReturns == 0, "Please specify all return types at once"); + return FixedSizeSignature<T, sizeof...(ReturnTypes), kNumParams>{ + std::initializer_list<T>{return_types...}.begin(), reps_}; + } + + // Add parameters to this signature (only allowed if there are none yet). + template <typename... ParamTypes> + auto Params(ParamTypes... param_types) const { + static_assert(kNumParams == 0, "Please specify all parameters at once"); + return FixedSizeSignature<T, kNumReturns, sizeof...(ParamTypes)>{ + reps_, std::initializer_list<T>{param_types...}.begin()}; + } + + private: + // Other template instantiations can call the private constructor. + template <typename T2, size_t kNumReturns2, size_t kNumParams2> + friend class FixedSizeSignature; + + FixedSizeSignature(const T* returns, const T* params) + : Signature<T>(kNumReturns, kNumParams, reps_) { + std::copy(returns, returns + kNumReturns, reps_); + std::copy(params, params + kNumParams, reps_ + kNumReturns); + } + + T reps_[kNumReturns + kNumParams]; +}; + +// Specialization for zero-sized signatures. +template <typename T> +class FixedSizeSignature<T, 0, 0> : public Signature<T> { + public: + constexpr FixedSizeSignature() : Signature<T>(0, 0, nullptr) {} + + // Add return types. + template <typename... ReturnTypes> + static auto Returns(ReturnTypes... return_types) { + return FixedSizeSignature<T, sizeof...(ReturnTypes), 0>{ + std::initializer_list<T>{return_types...}.begin(), nullptr}; + } + + // Add parameters. + template <typename... ParamTypes> + static auto Params(ParamTypes... param_types) { + return FixedSizeSignature<T, 0, sizeof...(ParamTypes)>{ + nullptr, std::initializer_list<T>{param_types...}.begin()}; + } +}; + } // namespace internal } // namespace v8 |