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
9#include "clang/Testing/CommandLineArgs.h"
10#include "llvm/MC/TargetRegistry.h"
11#include "llvm/Support/ErrorHandling.h"
12
13namespace clang {
14
15std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang) {
16 std::vector<std::string> Args;
17 // Test with basic arguments.
18 switch (Lang) {
19 case Lang_C89:
20 Args = {"-x", "c", "-std=c89"};
21 break;
22 case Lang_C99:
23 Args = {"-x", "c", "-std=c99"};
24 break;
25 case Lang_CXX03:
26 Args = {"-std=c++03", "-frtti"};
27 break;
28 case Lang_CXX11:
29 Args = {"-std=c++11", "-frtti"};
30 break;
31 case Lang_CXX14:
32 Args = {"-std=c++14", "-frtti"};
33 break;
34 case Lang_CXX17:
35 Args = {"-std=c++17", "-frtti"};
36 break;
37 case Lang_CXX20:
38 Args = {"-std=c++20", "-frtti"};
39 break;
40 case Lang_CXX23:
41 Args = {"-std=c++23", "-frtti"};
42 break;
43 case Lang_OBJC:
44 Args = {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
45 break;
46 case Lang_OBJCXX:
47 Args = {"-x", "objective-c++", "-frtti"};
48 break;
49 case Lang_OpenCL:
50 llvm_unreachable("Not implemented yet!");
51 }
52 return Args;
53}
54
55std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang) {
56 std::vector<std::string> Args;
57 switch (Lang) {
58 case Lang_C89:
59 Args = {"-xc", "-std=c89"};
60 break;
61 case Lang_C99:
62 Args = {"-xc", "-std=c99"};
63 break;
64 case Lang_CXX03:
65 Args = {"-std=c++03"};
66 break;
67 case Lang_CXX11:
68 Args = {"-std=c++11"};
69 break;
70 case Lang_CXX14:
71 Args = {"-std=c++14"};
72 break;
73 case Lang_CXX17:
74 Args = {"-std=c++17"};
75 break;
76 case Lang_CXX20:
77 Args = {"-std=c++20"};
78 break;
79 case Lang_CXX23:
80 Args = {"-std=c++23"};
81 break;
82 case Lang_OBJC:
83 Args = {"-xobjective-c"};
84 break;
85 case Lang_OBJCXX:
86 Args = {"-xobjective-c++"};
87 break;
88 case Lang_OpenCL:
89 llvm_unreachable("Not implemented yet!");
90 }
91 return Args;
92}
93
94StringRef getFilenameForTesting(TestLanguage Lang) {
95 switch (Lang) {
96 case Lang_C89:
97 case Lang_C99:
98 return "input.c";
99
100 case Lang_CXX03:
101 case Lang_CXX11:
102 case Lang_CXX14:
103 case Lang_CXX17:
104 case Lang_CXX20:
105 case Lang_CXX23:
106 return "input.cc";
107
108 case Lang_OpenCL:
109 return "input.cl";
110
111 case Lang_OBJC:
112 return "input.m";
113
114 case Lang_OBJCXX:
115 return "input.mm";
116 }
117 llvm_unreachable("Unhandled TestLanguage enum");
118}
119
120std::string getAnyTargetForTesting() {
121 for (const auto &Target : llvm::TargetRegistry::targets()) {
122 std::string Error;
123 StringRef TargetName(Target.getName());
124 if (TargetName == "x86-64")
125 TargetName = "x86_64";
126 if (llvm::TargetRegistry::lookupTarget(Triple: std::string(TargetName), Error) ==
127 &Target) {
128 return std::string(TargetName);
129 }
130 }
131 return "";
132}
133
134} // end namespace clang
135

source code of clang/lib/Testing/CommandLineArgs.cpp