llvm-project
122 строки · 3.7 Кб
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
9#include "clang/Basic/LangStandard.h"10#include "clang/Config/config.h"11#include "llvm/ADT/StringSwitch.h"12#include "llvm/Support/ErrorHandling.h"13#include "llvm/TargetParser/Triple.h"14using namespace clang;15
16StringRef clang::languageToString(Language L) {17switch (L) {18case Language::Unknown:19return "Unknown";20case Language::Asm:21return "Asm";22case Language::LLVM_IR:23return "LLVM IR";24case Language::CIR:25return "ClangIR";26case Language::C:27return "C";28case Language::CXX:29return "C++";30case Language::ObjC:31return "Objective-C";32case Language::ObjCXX:33return "Objective-C++";34case Language::OpenCL:35return "OpenCL";36case Language::OpenCLCXX:37return "OpenCLC++";38case Language::CUDA:39return "CUDA";40case Language::RenderScript:41return "RenderScript";42case Language::HIP:43return "HIP";44case Language::HLSL:45return "HLSL";46}47
48llvm_unreachable("unhandled language kind");49}
50
51#define LANGSTANDARD(id, name, lang, desc, features) \52static const LangStandard Lang_##id = {name, desc, features, Language::lang};53#include "clang/Basic/LangStandards.def"54
55const LangStandard &LangStandard::getLangStandardForKind(Kind K) {56switch (K) {57case lang_unspecified:58llvm::report_fatal_error("getLangStandardForKind() on unspecified kind");59#define LANGSTANDARD(id, name, lang, desc, features) \60case lang_##id: return Lang_##id;61#include "clang/Basic/LangStandards.def"62}63llvm_unreachable("Invalid language kind!");64}
65
66LangStandard::Kind LangStandard::getLangKind(StringRef Name) {67return llvm::StringSwitch<Kind>(Name)68#define LANGSTANDARD(id, name, lang, desc, features) .Case(name, lang_##id)69#define LANGSTANDARD_ALIAS(id, alias) .Case(alias, lang_##id)70#include "clang/Basic/LangStandards.def"71.Default(lang_unspecified);72}
73
74LangStandard::Kind LangStandard::getHLSLLangKind(StringRef Name) {75return llvm::StringSwitch<LangStandard::Kind>(Name)76.Case("2016", LangStandard::lang_hlsl2016)77.Case("2017", LangStandard::lang_hlsl2017)78.Case("2018", LangStandard::lang_hlsl2018)79.Case("2021", LangStandard::lang_hlsl2021)80.Case("202x", LangStandard::lang_hlsl202x)81.Default(LangStandard::lang_unspecified);82}
83
84const LangStandard *LangStandard::getLangStandardForName(StringRef Name) {85Kind K = getLangKind(Name);86if (K == lang_unspecified)87return nullptr;88
89return &getLangStandardForKind(K);90}
91
92LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang,93const llvm::Triple &T) {94switch (Lang) {95case Language::Unknown:96case Language::LLVM_IR:97case Language::CIR:98llvm_unreachable("Invalid input kind!");99case Language::OpenCL:100return LangStandard::lang_opencl12;101case Language::OpenCLCXX:102return LangStandard::lang_openclcpp10;103case Language::Asm:104case Language::C:105// The PS4 uses C99 as the default C standard.106if (T.isPS4())107return LangStandard::lang_gnu99;108return LangStandard::lang_gnu17;109case Language::ObjC:110return LangStandard::lang_gnu11;111case Language::CXX:112case Language::ObjCXX:113case Language::CUDA:114case Language::HIP:115return LangStandard::lang_gnucxx17;116case Language::RenderScript:117return LangStandard::lang_c99;118case Language::HLSL:119return LangStandard::lang_hlsl2021;120}121llvm_unreachable("unhandled Language kind!");122}
123