builtin_function_kind.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_
  6. #include <cstdint>
  7. #include "common/enum_base.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::SemIR {
  10. class File;
  11. CARBON_DEFINE_RAW_ENUM_CLASS(BuiltinFunctionKind, std::uint8_t) {
  12. #define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
  13. CARBON_RAW_ENUM_ENUMERATOR(Name)
  14. #include "toolchain/sem_ir/builtin_function_kind.def"
  15. };
  16. // A kind of builtin function.
  17. class BuiltinFunctionKind : public CARBON_ENUM_BASE(BuiltinFunctionKind) {
  18. public:
  19. #define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
  20. CARBON_ENUM_CONSTANT_DECL(Name)
  21. #include "toolchain/sem_ir/builtin_function_kind.def"
  22. // Returns the builtin function kind with the given name, or None if the name
  23. // is unknown.
  24. static auto ForBuiltinName(llvm::StringRef name) -> BuiltinFunctionKind;
  25. // Returns the builtin function kind corresponding to the given function
  26. // callee, or None if the callee is not known to be a builtin.
  27. static auto ForCallee(const File& sem_ir, InstId callee_id)
  28. -> BuiltinFunctionKind;
  29. // Determines whether this builtin function kind can have the specified
  30. // function type.
  31. auto IsValidType(const File& sem_ir, llvm::ArrayRef<TypeId> arg_types,
  32. TypeId return_type) const -> bool;
  33. };
  34. #define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
  35. CARBON_ENUM_CONSTANT_DEFINITION(BuiltinFunctionKind, Name)
  36. #include "toolchain/sem_ir/builtin_function_kind.def"
  37. } // namespace Carbon::SemIR
  38. #endif // CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_