1 //===--- Sparc.cpp - Tools Implementations ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "clang/Driver/Driver.h"
12 #include "clang/Driver/DriverDiagnostic.h"
13 #include "clang/Driver/Options.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/Option/ArgList.h"
17 using namespace clang::driver;
18 using namespace clang::driver::tools;
19 using namespace clang;
20 using namespace llvm::opt;
22 const char *sparc::getSparcAsmModeForCPU(StringRef Name,
23 const llvm::Triple &Triple) {
24 if (Triple.getArch() == llvm::Triple::sparcv9) {
25 return llvm::StringSwitch<const char *>(Name)
26 .Case("niagara", "-Av9b")
27 .Case("niagara2", "-Av9b")
28 .Case("niagara3", "-Av9d")
29 .Case("niagara4", "-Av9d")
32 return llvm::StringSwitch<const char *>(Name)
34 .Case("supersparc", "-Av8")
35 .Case("sparclite", "-Asparclite")
36 .Case("f934", "-Asparclite")
37 .Case("hypersparc", "-Av8")
38 .Case("sparclite86x", "-Asparclite")
39 .Case("sparclet", "-Asparclet")
40 .Case("tsc701", "-Asparclet")
41 .Case("v9", "-Av8plus")
42 .Case("ultrasparc", "-Av8plus")
43 .Case("ultrasparc3", "-Av8plus")
44 .Case("niagara", "-Av8plusb")
45 .Case("niagara2", "-Av8plusb")
46 .Case("niagara3", "-Av8plusd")
47 .Case("niagara4", "-Av8plusd")
48 .Case("leon2", "-Av8")
49 .Case("at697e", "-Av8")
50 .Case("at697f", "-Av8")
51 .Case("leon3", "-Av8")
52 .Case("ut699", "-Av8")
53 .Case("gr712rc", "-Av8")
54 .Case("leon4", "-Av8")
55 .Case("gr740", "-Av8")
60 sparc::FloatABI sparc::getSparcFloatABI(const Driver &D,
61 const ArgList &Args) {
62 sparc::FloatABI ABI = sparc::FloatABI::Invalid;
63 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
64 options::OPT_mhard_float,
65 options::OPT_mfloat_abi_EQ)) {
66 if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
67 ABI = sparc::FloatABI::Soft;
68 else if (A->getOption().matches(options::OPT_mhard_float))
69 ABI = sparc::FloatABI::Hard;
71 ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue())
72 .Case("soft", sparc::FloatABI::Soft)
73 .Case("hard", sparc::FloatABI::Hard)
74 .Default(sparc::FloatABI::Invalid);
75 if (ABI == sparc::FloatABI::Invalid &&
76 !StringRef(A->getValue()).empty()) {
77 D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
78 ABI = sparc::FloatABI::Hard;
83 // If unspecified, choose the default based on the platform.
84 // Only the hard-float ABI on Sparc is standardized, and it is the
85 // default. GCC also supports a nonstandard soft-float ABI mode, also
86 // implemented in LLVM. However as this is not standard we set the default
88 if (ABI == sparc::FloatABI::Invalid) {
89 ABI = sparc::FloatABI::Hard;
95 void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
96 std::vector<StringRef> &Features) {
97 sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
98 if (FloatABI == sparc::FloatABI::Soft)
99 Features.push_back("+soft-float");