clang  6.0.0svn
WebAssembly.cpp
Go to the documentation of this file.
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"
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 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
33  return llvm::StringSwitch<bool>(Feature)
34  .Case("simd128", SIMDLevel >= SIMD128)
35  .Case("nontrapping-fptoint", HasNontrappingFPToInt)
36  .Default(false);
37 }
38 
39 bool WebAssemblyTargetInfo::isValidCPUName(StringRef Name) const {
40  return llvm::StringSwitch<bool>(Name)
41  .Case("mvp", true)
42  .Case("bleeding-edge", true)
43  .Case("generic", true)
44  .Default(false);
45 }
46 
48  MacroBuilder &Builder) const {
49  defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
50  if (SIMDLevel >= SIMD128)
51  Builder.defineMacro("__wasm_simd128__");
52 }
53 
54 bool WebAssemblyTargetInfo::handleTargetFeatures(
55  std::vector<std::string> &Features, DiagnosticsEngine &Diags) {
56  for (const auto &Feature : Features) {
57  if (Feature == "+simd128") {
58  SIMDLevel = std::max(SIMDLevel, SIMD128);
59  continue;
60  }
61  if (Feature == "-simd128") {
62  SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
63  continue;
64  }
65  if (Feature == "+nontrapping-fptoint") {
66  HasNontrappingFPToInt = true;
67  continue;
68  }
69  if (Feature == "-nontrapping-fptoint") {
70  HasNontrappingFPToInt = false;
71  continue;
72  }
73 
74  Diags.Report(diag::err_opt_not_valid_with_opt)
75  << Feature << "-target-feature";
76  return false;
77  }
78  return true;
79 }
80 
81 ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
82  return llvm::makeArrayRef(BuiltinInfo, clang::WebAssembly::LastTSBuiltin -
84 }
85 
87  MacroBuilder &Builder) const {
89  defineCPUMacros(Builder, "wasm32", /*Tuning=*/false);
90 }
91 
93  MacroBuilder &Builder) const {
95  defineCPUMacros(Builder, "wasm64", /*Tuning=*/false);
96 }
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1207
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
Defines the Diagnostic-related interfaces.
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Dataflow Directional Tag Classes.
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: WebAssembly.cpp:86
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: WebAssembly.cpp:92
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: WebAssembly.cpp:47
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
Definition: Targets.cpp:69
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:30
Defines enum values for all the target-independent builtin functions.