aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Testing/CommandLineArgs.cpp
blob: e9da72f71c5991c83712a66f62826efc3759f5bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//===--- CommandLineArgs.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "clang/Testing/CommandLineArgs.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/ErrorHandling.h"

namespace clang {
std::vector<TestLanguage> getCOrLater(const int MinimumStd) {
  std::vector<TestLanguage> Result{};

#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
  if (version >= MinimumStd)                                                   \
    Result.push_back(Lang_##lang##version);
#include "clang/Testing/TestLanguage.def"

  return Result;
}
std::vector<TestLanguage> getCXXOrLater(const int MinimumStd) {
  std::vector<TestLanguage> Result{};

#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
  if (version >= MinimumStd)                                                   \
    Result.push_back(Lang_##lang##version);
#include "clang/Testing/TestLanguage.def"

  return Result;
}

std::vector<std::string> getCommandLineArgsForTesting(TestLanguage Lang) {
  // Test with basic arguments.
  switch (Lang) {
#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
  case Lang_##lang##version:                                                   \
    return { "-x", "c", "-std=" #std_flag };
#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
  case Lang_##lang##version:                                                   \
    return { "-std=" #std_flag, "-frtti" };
#include "clang/Testing/TestLanguage.def"

  case Lang_OBJC:
    return {"-x", "objective-c", "-frtti", "-fobjc-nonfragile-abi"};
  case Lang_OBJCXX:
    return {"-x", "objective-c++", "-frtti"};
  case Lang_OpenCL:
    llvm_unreachable("Unhandled TestLanguage enum");
  }
  llvm_unreachable("Unhandled TestLanguage enum");
}

std::vector<std::string> getCC1ArgsForTesting(TestLanguage Lang) {
  switch (Lang) {
#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
  case Lang_##lang##version:                                                   \
    return { "-xc", "-std=" #std_flag };
#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
  case Lang_##lang##version:                                                   \
    return { "-std=" #std_flag };
#include "clang/Testing/TestLanguage.def"

  case Lang_OBJC:
    return {"-xobjective-c"};
    break;
  case Lang_OBJCXX:
    return {"-xobjective-c++"};
    break;
  case Lang_OpenCL:
    llvm_unreachable("Unhandled TestLanguage enum");
  }
  llvm_unreachable("Unhandled TestLanguage enum");
}

StringRef getFilenameForTesting(TestLanguage Lang) {
  switch (Lang) {
#define TESTLANGUAGE_C(lang, version, std_flag, version_index)                 \
  case Lang_##lang##version:                                                   \
    return "input.c";
#define TESTLANGUAGE_CXX(lang, version, std_flag, version_index)               \
  case Lang_##lang##version:                                                   \
    return "input.cc";
#include "clang/Testing/TestLanguage.def"

  case Lang_OpenCL:
    return "input.cl";

  case Lang_OBJC:
    return "input.m";

  case Lang_OBJCXX:
    return "input.mm";
  }
  llvm_unreachable("Unhandled TestLanguage enum");
}

std::string getAnyTargetForTesting() {
  for (const auto &Target : llvm::TargetRegistry::targets()) {
    std::string Error;
    StringRef TargetName(Target.getName());
    if (TargetName == "x86-64")
      TargetName = "x86_64";
    if (llvm::TargetRegistry::lookupTarget(TargetName, Error) == &Target) {
      return std::string(TargetName);
    }
  }
  return "";
}

} // end namespace clang