Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/Arch/M68k.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- M68k.cpp - M68k Helpers for Tools -------------------*- C++-*-===//
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 "M68k.h"
10
#include "ToolChains/CommonArgs.h"
11
#include "clang/Driver/Driver.h"
12
#include "clang/Driver/DriverDiagnostic.h"
13
#include "clang/Driver/Options.h"
14
#include "llvm/ADT/SmallVector.h"
15
#include "llvm/ADT/StringSwitch.h"
16
#include "llvm/Option/ArgList.h"
17
#include "llvm/Support/Host.h"
18
#include "llvm/Support/Regex.h"
19
#include <sstream>
20
21
using namespace clang::driver;
22
using namespace clang::driver::tools;
23
using namespace clang;
24
using namespace llvm::opt;
25
26
/// getM68kTargetCPU - Get the (LLVM) name of the 68000 cpu we are targeting.
27
30
std::string m68k::getM68kTargetCPU(const ArgList &Args) {
28
30
  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
29
    // The canonical CPU name is captalize. However, we allow
30
    // starting with lower case or numbers only
31
18
    StringRef CPUName = A->getValue();
32
33
18
    if (CPUName == "native") {
34
0
      std::string CPU = std::string(llvm::sys::getHostCPUName());
35
0
      if (!CPU.empty() && CPU != "generic")
36
0
        return CPU;
37
0
    }
38
39
18
    if (CPUName == "common")
40
0
      return "generic";
41
42
18
    return llvm::StringSwitch<std::string>(CPUName)
43
18
        .Cases("m68000", "68000", "M68000")
44
18
        .Cases("m68010", "68010", "M68010")
45
18
        .Cases("m68020", "68020", "M68020")
46
18
        .Cases("m68030", "68030", "M68030")
47
18
        .Cases("m68040", "68040", "M68040")
48
18
        .Cases("m68060", "68060", "M68060")
49
18
        .Default(CPUName.str());
50
18
  }
51
  // FIXME: Throw error when multiple sub-architecture flag exist
52
12
  if (Args.hasArg(clang::driver::options::OPT_m68000))
53
2
    return "M68000";
54
10
  if (Args.hasArg(clang::driver::options::OPT_m68010))
55
2
    return "M68010";
56
8
  if (Args.hasArg(clang::driver::options::OPT_m68020))
57
2
    return "M68020";
58
6
  if (Args.hasArg(clang::driver::options::OPT_m68030))
59
2
    return "M68030";
60
4
  if (Args.hasArg(clang::driver::options::OPT_m68040))
61
2
    return "M68040";
62
2
  if (Args.hasArg(clang::driver::options::OPT_m68060))
63
2
    return "M68060";
64
65
0
  return "";
66
2
}
67
68
void m68k::getM68kTargetFeatures(const Driver &D, const llvm::Triple &Triple,
69
                                 const ArgList &Args,
70
30
                                 std::vector<StringRef> &Features) {
71
72
30
  m68k::FloatABI FloatABI = m68k::getM68kFloatABI(D, Args);
73
30
  if (FloatABI == m68k::FloatABI::Soft)
74
0
    Features.push_back("-hard-float");
75
76
  // Handle '-ffixed-<register>' flags
77
30
  if (Args.hasArg(options::OPT_ffixed_a0))
78
0
    Features.push_back("+reserve-a0");
79
30
  if (Args.hasArg(options::OPT_ffixed_a1))
80
0
    Features.push_back("+reserve-a1");
81
30
  if (Args.hasArg(options::OPT_ffixed_a2))
82
0
    Features.push_back("+reserve-a2");
83
30
  if (Args.hasArg(options::OPT_ffixed_a3))
84
0
    Features.push_back("+reserve-a3");
85
30
  if (Args.hasArg(options::OPT_ffixed_a4))
86
0
    Features.push_back("+reserve-a4");
87
30
  if (Args.hasArg(options::OPT_ffixed_a5))
88
0
    Features.push_back("+reserve-a5");
89
30
  if (Args.hasArg(options::OPT_ffixed_a6))
90
0
    Features.push_back("+reserve-a6");
91
30
  if (Args.hasArg(options::OPT_ffixed_d0))
92
0
    Features.push_back("+reserve-d0");
93
30
  if (Args.hasArg(options::OPT_ffixed_d1))
94
0
    Features.push_back("+reserve-d1");
95
30
  if (Args.hasArg(options::OPT_ffixed_d2))
96
0
    Features.push_back("+reserve-d2");
97
30
  if (Args.hasArg(options::OPT_ffixed_d3))
98
0
    Features.push_back("+reserve-d3");
99
30
  if (Args.hasArg(options::OPT_ffixed_d4))
100
0
    Features.push_back("+reserve-d4");
101
30
  if (Args.hasArg(options::OPT_ffixed_d5))
102
0
    Features.push_back("+reserve-d5");
103
30
  if (Args.hasArg(options::OPT_ffixed_d6))
104
0
    Features.push_back("+reserve-d6");
105
30
  if (Args.hasArg(options::OPT_ffixed_d7))
106
0
    Features.push_back("+reserve-d7");
107
30
}
108
109
30
m68k::FloatABI m68k::getM68kFloatABI(const Driver &D, const ArgList &Args) {
110
30
  m68k::FloatABI ABI = m68k::FloatABI::Invalid;
111
30
  if (Arg *A =
112
30
          Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float)) {
113
114
0
    if (A->getOption().matches(options::OPT_msoft_float))
115
0
      ABI = m68k::FloatABI::Soft;
116
0
    else if (A->getOption().matches(options::OPT_mhard_float))
117
0
      ABI = m68k::FloatABI::Hard;
118
0
  }
119
120
  // If unspecified, choose the default based on the platform.
121
30
  if (ABI == m68k::FloatABI::Invalid)
122
30
    ABI = m68k::FloatABI::Hard;
123
124
30
  return ABI;
125
30
}