xref: /freebsd/contrib/llvm-project/clang/lib/Testing/CommandLineArgs.cpp (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
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/Support/ErrorHandling.h"
11 
12 namespace clang {
13 
14 std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang) {
15   std::vector<std::string> Args;
16   // Test with basic arguments.
17   switch (Lang) {
18   case Lang_C89:
19     Args = {"-x", "c", "-std=c89"};
20     break;
21   case Lang_C99:
22     Args = {"-x", "c", "-std=c99"};
23     break;
24   case Lang_CXX03:
25     Args = {"-std=c++03", "-frtti"};
26     break;
27   case Lang_CXX11:
28     Args = {"-std=c++11", "-frtti"};
29     break;
30   case Lang_CXX14:
31     Args = {"-std=c++14", "-frtti"};
32     break;
33   case Lang_CXX17:
34     Args = {"-std=c++17", "-frtti"};
35     break;
36   case Lang_CXX20:
37     Args = {"-std=c++20", "-frtti"};
38     break;
39   case Lang_OBJC:
40     Args = {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
41     break;
42   case Lang_OBJCXX:
43     Args = {"-x", "objective-c++", "-frtti"};
44     break;
45   case Lang_OpenCL:
46     llvm_unreachable("Not implemented yet!");
47   }
48   return Args;
49 }
50 
51 std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang) {
52   std::vector<std::string> Args;
53   switch (Lang) {
54   case Lang_C89:
55     Args = {"-xc", "-std=c89"};
56     break;
57   case Lang_C99:
58     Args = {"-xc", "-std=c99"};
59     break;
60   case Lang_CXX03:
61     Args = {"-std=c++03"};
62     break;
63   case Lang_CXX11:
64     Args = {"-std=c++11"};
65     break;
66   case Lang_CXX14:
67     Args = {"-std=c++14"};
68     break;
69   case Lang_CXX17:
70     Args = {"-std=c++17"};
71     break;
72   case Lang_CXX20:
73     Args = {"-std=c++20"};
74     break;
75   case Lang_OBJC:
76     Args = {"-xobjective-c"};
77     break;
78   case Lang_OBJCXX:
79     Args = {"-xobjective-c++"};
80     break;
81   case Lang_OpenCL:
82     llvm_unreachable("Not implemented yet!");
83   }
84   return Args;
85 }
86 
87 StringRef getFilenameForTesting(TestLanguage Lang) {
88   switch (Lang) {
89   case Lang_C89:
90   case Lang_C99:
91     return "input.c";
92 
93   case Lang_CXX03:
94   case Lang_CXX11:
95   case Lang_CXX14:
96   case Lang_CXX17:
97   case Lang_CXX20:
98     return "input.cc";
99 
100   case Lang_OpenCL:
101     return "input.cl";
102 
103   case Lang_OBJC:
104     return "input.m";
105 
106   case Lang_OBJCXX:
107     return "input.mm";
108   }
109   llvm_unreachable("Unhandled TestLanguage enum");
110 }
111 
112 } // end namespace clang
113