mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
IntrinsicTable: De-duplicate returned Intrinsics
Much like sem::Type, it greatly simplifies downstream logic if we can compare sem::Intrinsic pointers to know if they refer to the same intrinsic overload. Change-Id: If236247cd3979bbde821d9294f304ab85ba4938e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58061 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "src/sem/node.h"
|
||||
#include "src/sem/parameter_usage.h"
|
||||
#include "src/sem/sampler_type.h"
|
||||
#include "src/utils/hash.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
@@ -37,11 +38,16 @@ struct Parameter {
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Parameter parameter);
|
||||
|
||||
/// Comparison operator for Parameters
|
||||
/// Equality operator for Parameters
|
||||
static inline bool operator==(const Parameter& a, const Parameter& b) {
|
||||
return a.type == b.type && a.usage == b.usage;
|
||||
}
|
||||
|
||||
/// Inequality operator for Parameters
|
||||
static inline bool operator!=(const Parameter& a, const Parameter& b) {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
/// ParameterList is a list of Parameter
|
||||
using ParameterList = std::vector<Parameter>;
|
||||
|
||||
@@ -59,6 +65,9 @@ class CallTarget : public Castable<CallTarget, Node> {
|
||||
/// @param parameters the parameters for the call target
|
||||
CallTarget(sem::Type* return_type, const ParameterList& parameters);
|
||||
|
||||
/// Copy constructor
|
||||
CallTarget(const CallTarget&);
|
||||
|
||||
/// @return the return type of the call target
|
||||
sem::Type* ReturnType() const { return return_type_; }
|
||||
|
||||
@@ -76,4 +85,19 @@ class CallTarget : public Castable<CallTarget, Node> {
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
namespace std {
|
||||
|
||||
/// Custom std::hash specialization for tint::sem::Parameter
|
||||
template <>
|
||||
class hash<tint::sem::Parameter> {
|
||||
public:
|
||||
/// @param p the tint::sem::Parameter to create a hash for
|
||||
/// @return the hash value
|
||||
inline std::size_t operator()(const tint::sem::Parameter& p) const {
|
||||
return tint::utils::Hash(p.type, p.usage);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // SRC_SEM_CALL_TARGET_H_
|
||||
|
||||
Reference in New Issue
Block a user