clang 20.0.0git
CommandLineArgs.cpp
Go to the documentation of this file.
1//===--- CommandLineArgs.cpp ----------------------------------------------===//
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
10#include "llvm/MC/TargetRegistry.h"
11#include "llvm/Support/ErrorHandling.h"
12
13namespace clang {
14std::vector<TestLanguage> getCOrLater(const int MinimumStd) {
15 std::vector<TestLanguage> Result{};
16
17#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
18 if (version >= MinimumStd) \
19 Result.push_back(Lang_##lang##version);
20#include "clang/Testing/TestLanguage.def"
21
22 return Result;
23}
24std::vector<TestLanguage> getCXXOrLater(const int MinimumStd) {
25 std::vector<TestLanguage> Result{};
26
27#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
28 if (version >= MinimumStd) \
29 Result.push_back(Lang_##lang##version);
30#include "clang/Testing/TestLanguage.def"
31
32 return Result;
33}
34
35std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang) {
36 // Test with basic arguments.
37 switch (Lang) {
38#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
39 case Lang_##lang##version: \
40 return { "-x", "c", "-std=" #std_flag };
41#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
42 case Lang_##lang##version: \
43 return { "-std=" #std_flag, "-frtti" };
44#include "clang/Testing/TestLanguage.def"
45
46 case Lang_OBJC:
47 return {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
48 case Lang_OBJCXX:
49 return {"-x", "objective-c++", "-frtti"};
50 case Lang_OpenCL:
51 llvm_unreachable("Unhandled TestLanguage enum");
52 }
53 llvm_unreachable("Unhandled TestLanguage enum");
54}
55
56std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang) {
57 switch (Lang) {
58#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
59 case Lang_##lang##version: \
60 return { "-xc", "-std=" #std_flag };
61#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
62 case Lang_##lang##version: \
63 return { "-std=" #std_flag };
64#include "clang/Testing/TestLanguage.def"
65
66 case Lang_OBJC:
67 return {"-xobjective-c"};
68 break;
69 case Lang_OBJCXX:
70 return {"-xobjective-c++"};
71 break;
72 case Lang_OpenCL:
73 llvm_unreachable("Unhandled TestLanguage enum");
74 }
75 llvm_unreachable("Unhandled TestLanguage enum");
76}
77
79 switch (Lang) {
80#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \
81 case Lang_##lang##version: \
82 return "input.c";
83#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index) \
84 case Lang_##lang##version: \
85 return "input.cc";
86#include "clang/Testing/TestLanguage.def"
87
88 case Lang_OpenCL:
89 return "input.cl";
90
91 case Lang_OBJC:
92 return "input.m";
93
94 case Lang_OBJCXX:
95 return "input.mm";
96 }
97 llvm_unreachable("Unhandled TestLanguage enum");
98}
99
101 for (const auto &Target : llvm::TargetRegistry::targets()) {
102 std::string Error;
103 StringRef TargetName(Target.getName());
104 if (TargetName == "x86-64")
105 TargetName = "x86_64";
106 if (llvm::TargetRegistry::lookupTarget(std::string(TargetName), Error) ==
107 &Target) {
108 return std::string(TargetName);
109 }
110 }
111 return "";
112}
113
114} // end namespace clang
llvm::MachO::Target Target
Definition: MachO.h:51
The JSON file list parser is used to communicate input to InstallAPI.
std::string getAnyTargetForTesting()
Find a target name such that looking for it in TargetRegistry by that name returns the same target.
std::vector< std::string > getCC1ArgsForTesting(TestLanguage Lang)
std::vector< TestLanguage > getCOrLater(int MinimumStd)
std::vector< TestLanguage > getCXXOrLater(int MinimumStd)
@ Result
The result type of a method or function.
StringRef getFilenameForTesting(TestLanguage Lang)
std::vector< std::string > getCommandLineArgsForTesting(TestLanguage Lang)