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 13 namespace clang { 14 15 std::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_OBJC: 41 Args = {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"}; 42 break; 43 case Lang_OBJCXX: 44 Args = {"-x", "objective-c++", "-frtti"}; 45 break; 46 case Lang_OpenCL: 47 llvm_unreachable("Not implemented yet!"); 48 } 49 return Args; 50 } 51 52 std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang) { 53 std::vector<std::string> Args; 54 switch (Lang) { 55 case Lang_C89: 56 Args = {"-xc", "-std=c89"}; 57 break; 58 case Lang_C99: 59 Args = {"-xc", "-std=c99"}; 60 break; 61 case Lang_CXX03: 62 Args = {"-std=c++03"}; 63 break; 64 case Lang_CXX11: 65 Args = {"-std=c++11"}; 66 break; 67 case Lang_CXX14: 68 Args = {"-std=c++14"}; 69 break; 70 case Lang_CXX17: 71 Args = {"-std=c++17"}; 72 break; 73 case Lang_CXX20: 74 Args = {"-std=c++20"}; 75 break; 76 case Lang_OBJC: 77 Args = {"-xobjective-c"}; 78 break; 79 case Lang_OBJCXX: 80 Args = {"-xobjective-c++"}; 81 break; 82 case Lang_OpenCL: 83 llvm_unreachable("Not implemented yet!"); 84 } 85 return Args; 86 } 87 88 StringRef getFilenameForTesting(TestLanguage Lang) { 89 switch (Lang) { 90 case Lang_C89: 91 case Lang_C99: 92 return "input.c"; 93 94 case Lang_CXX03: 95 case Lang_CXX11: 96 case Lang_CXX14: 97 case Lang_CXX17: 98 case Lang_CXX20: 99 return "input.cc"; 100 101 case Lang_OpenCL: 102 return "input.cl"; 103 104 case Lang_OBJC: 105 return "input.m"; 106 107 case Lang_OBJCXX: 108 return "input.mm"; 109 } 110 llvm_unreachable("Unhandled TestLanguage enum"); 111 } 112 113 std::string getAnyTargetForTesting() { 114 for (const auto &Target : llvm::TargetRegistry::targets()) { 115 std::string Error; 116 StringRef TargetName(Target.getName()); 117 if (TargetName == "x86-64") 118 TargetName = "x86_64"; 119 if (llvm::TargetRegistry::lookupTarget(std::string(TargetName), Error) == 120 &Target) { 121 return std::string(TargetName); 122 } 123 } 124 return ""; 125 } 126 127 } // end namespace clang 128