/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/clang/lib/Basic/Targets/WebAssembly.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- WebAssembly.cpp - Implement WebAssembly target feature support ---===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file implements WebAssembly TargetInfo objects. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "WebAssembly.h" |
15 | | #include "Targets.h" |
16 | | #include "clang/Basic/Builtins.h" |
17 | | #include "clang/Basic/Diagnostic.h" |
18 | | #include "clang/Basic/TargetBuiltins.h" |
19 | | #include "llvm/ADT/StringSwitch.h" |
20 | | |
21 | | using namespace clang; |
22 | | using namespace clang::targets; |
23 | | |
24 | | const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = { |
25 | | #define BUILTIN(ID, TYPE, ATTRS) \ |
26 | | {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, |
27 | | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \ |
28 | | {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr}, |
29 | | #include "clang/Basic/BuiltinsWebAssembly.def" |
30 | | }; |
31 | | |
32 | 0 | bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const { |
33 | 0 | return llvm::StringSwitch<bool>(Feature) |
34 | 0 | .Case("simd128", SIMDLevel >= SIMD128) |
35 | 0 | .Default(false); |
36 | 0 | } |
37 | | |
38 | 12 | bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name) const { |
39 | 12 | return llvm::StringSwitch<bool>(Name) |
40 | 12 | .Case("mvp", true) |
41 | 12 | .Case("bleeding-edge", true) |
42 | 12 | .Case("generic", true) |
43 | 12 | .Default(false); |
44 | 12 | } |
45 | | |
46 | | void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, |
47 | 34 | MacroBuilder &Builder) const { |
48 | 34 | defineCPUMacros(Builder, "wasm", /*Tuning=*/false); |
49 | 34 | if (SIMDLevel >= SIMD128) |
50 | 4 | Builder.defineMacro("__wasm_simd128__"); |
51 | 34 | } |
52 | | |
53 | | bool WebAssemblyTargetInfo::handleTargetFeatures( |
54 | 34 | std::vector<std::string> &Features, DiagnosticsEngine &Diags) { |
55 | 6 | for (const auto &Feature : Features) { |
56 | 6 | if (Feature == "+simd128"6 ) { |
57 | 4 | SIMDLevel = std::max(SIMDLevel, SIMD128); |
58 | 4 | continue; |
59 | 4 | } |
60 | 2 | if (2 Feature == "-simd128"2 ) { |
61 | 2 | SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1)); |
62 | 2 | continue; |
63 | 2 | } |
64 | 0 |
|
65 | 0 | Diags.Report(diag::err_opt_not_valid_with_opt) |
66 | 0 | << Feature << "-target-feature"; |
67 | 0 | return false; |
68 | 0 | } |
69 | 34 | return true; |
70 | 34 | } |
71 | | |
72 | 34 | ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const { |
73 | 34 | return llvm::makeArrayRef(BuiltinInfo, clang::WebAssembly::LastTSBuiltin - |
74 | 34 | Builtin::FirstTSBuiltin); |
75 | 34 | } |
76 | | |
77 | | void WebAssembly32TargetInfo::getTargetDefines(const LangOptions &Opts, |
78 | 19 | MacroBuilder &Builder) const { |
79 | 19 | WebAssemblyTargetInfo::getTargetDefines(Opts, Builder); |
80 | 19 | defineCPUMacros(Builder, "wasm32", /*Tuning=*/false); |
81 | 19 | } |
82 | | |
83 | | void WebAssembly64TargetInfo::getTargetDefines(const LangOptions &Opts, |
84 | 15 | MacroBuilder &Builder) const { |
85 | 15 | WebAssemblyTargetInfo::getTargetDefines(Opts, Builder); |
86 | 15 | defineCPUMacros(Builder, "wasm64", /*Tuning=*/false); |
87 | 15 | } |