LangStandards.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===--- LangStandards.cpp - Language Standard Definitions ----------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "clang/Basic/LangStandard.h"
  9. #include "clang/Config/config.h"
  10. #include "llvm/ADT/StringSwitch.h"
  11. #include "llvm/ADT/Triple.h"
  12. #include "llvm/Support/ErrorHandling.h"
  13. using namespace clang;
  14. #define LANGSTANDARD(id, name, lang, desc, features) \
  15. static const LangStandard Lang_##id = {name, desc, features, Language::lang};
  16. #include "clang/Basic/LangStandards.def"
  17. const LangStandard &LangStandard::getLangStandardForKind(Kind K) {
  18. switch (K) {
  19. case lang_unspecified:
  20. llvm::report_fatal_error("getLangStandardForKind() on unspecified kind");
  21. #define LANGSTANDARD(id, name, lang, desc, features) \
  22. case lang_##id: return Lang_##id;
  23. #include "clang/Basic/LangStandards.def"
  24. }
  25. llvm_unreachable("Invalid language kind!");
  26. }
  27. LangStandard::Kind LangStandard::getLangKind(StringRef Name) {
  28. return llvm::StringSwitch<Kind>(Name)
  29. #define LANGSTANDARD(id, name, lang, desc, features) .Case(name, lang_##id)
  30. #define LANGSTANDARD_ALIAS(id, alias) .Case(alias, lang_##id)
  31. #include "clang/Basic/LangStandards.def"
  32. .Default(lang_unspecified);
  33. }
  34. const LangStandard *LangStandard::getLangStandardForName(StringRef Name) {
  35. Kind K = getLangKind(Name);
  36. if (K == lang_unspecified)
  37. return nullptr;
  38. return &getLangStandardForKind(K);
  39. }
  40. LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang,
  41. const llvm::Triple &T) {
  42. switch (Lang) {
  43. case Language::Unknown:
  44. case Language::LLVM_IR:
  45. llvm_unreachable("Invalid input kind!");
  46. case Language::OpenCL:
  47. return LangStandard::lang_opencl12;
  48. case Language::OpenCLCXX:
  49. return LangStandard::lang_openclcpp10;
  50. case Language::CUDA:
  51. return LangStandard::lang_cuda;
  52. case Language::Asm:
  53. case Language::C:
  54. // The PS4 uses C99 as the default C standard.
  55. if (T.isPS4())
  56. return LangStandard::lang_gnu99;
  57. return LangStandard::lang_gnu17;
  58. case Language::ObjC:
  59. return LangStandard::lang_gnu11;
  60. case Language::CXX:
  61. case Language::ObjCXX:
  62. if (T.isPS())
  63. return LangStandard::lang_gnucxx14;
  64. return LangStandard::lang_gnucxx17;
  65. case Language::RenderScript:
  66. return LangStandard::lang_c99;
  67. case Language::HIP:
  68. return LangStandard::lang_hip;
  69. case Language::HLSL:
  70. return LangStandard::lang_hlsl2021;
  71. }
  72. llvm_unreachable("unhandled Language kind!");
  73. }