1 //===-- MCTargetOptionsCommandFlags.cpp --------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains machine code-specific flags that are shared between
11 // different command line tools.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
16 
17 using namespace llvm;
18 
19 #define MCOPT(TY, NAME)                                                        \
20   static cl::opt<TY> *NAME##View;                                              \
21   TY llvm::mc::get##NAME() {                                                   \
22     assert(NAME##View && "RegisterMCTargetOptionsFlags not created.");         \
23     return *NAME##View;                                                        \
24   }
25 
26 #define MCOPT_EXP(TY, NAME)                                                    \
27   MCOPT(TY, NAME)                                                              \
28   Optional<TY> llvm::mc::getExplicit##NAME() {                                 \
29     if (NAME##View->getNumOccurrences()) {                                     \
30       TY res = *NAME##View;                                                    \
31       return res;                                                              \
32     }                                                                          \
33     return None;                                                               \
34   }
35 
36 MCOPT_EXP(bool, RelaxAll)
37 MCOPT(bool, IncrementalLinkerCompatible)
38 MCOPT(int, DwarfVersion)
39 MCOPT(bool, ShowMCInst)
40 MCOPT(bool, FatalWarnings)
41 MCOPT(bool, NoWarn)
42 MCOPT(bool, NoDeprecatedWarn)
43 MCOPT(std::string, ABIName)
44 
45 llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
46 #define MCBINDOPT(NAME)                                                        \
47   do {                                                                         \
48     NAME##View = std::addressof(NAME);                                         \
49   } while (0)
50 
51   static cl::opt<bool> RelaxAll(
52       "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
53                                "in the emitted object file"));
54   MCBINDOPT(RelaxAll);
55 
56   static cl::opt<bool> IncrementalLinkerCompatible(
57       "incremental-linker-compatible",
58       cl::desc(
59           "When used with filetype=obj, "
60           "emit an object file which can be used with an incremental linker"));
61   MCBINDOPT(IncrementalLinkerCompatible);
62 
63   static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
64                                    cl::init(0));
65   MCBINDOPT(DwarfVersion);
66 
67   static cl::opt<bool> ShowMCInst(
68       "asm-show-inst",
69       cl::desc("Emit internal instruction representation to assembly file"));
70   MCBINDOPT(ShowMCInst);
71 
72   static cl::opt<bool> FatalWarnings("fatal-warnings",
73                                      cl::desc("Treat warnings as errors"));
74   MCBINDOPT(FatalWarnings);
75 
76   static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
77   static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
78                            cl::aliasopt(NoWarn));
79   MCBINDOPT(NoWarn);
80 
81   static cl::opt<bool> NoDeprecatedWarn(
82       "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
83   MCBINDOPT(NoDeprecatedWarn);
84 
85   static cl::opt<std::string> ABIName(
86       "target-abi", cl::Hidden,
87       cl::desc("The name of the ABI to be targeted from the backend."),
88       cl::init(""));
89   MCBINDOPT(ABIName);
90 
91 #undef MCBINDOPT
92 }
93 
94 MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
95   MCTargetOptions Options;
96   Options.MCRelaxAll = getRelaxAll();
97   Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
98   Options.DwarfVersion = getDwarfVersion();
99   Options.ShowMCInst = getShowMCInst();
100   Options.ABIName = getABIName();
101   Options.MCFatalWarnings = getFatalWarnings();
102   Options.MCNoWarn = getNoWarn();
103   Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
104   return Options;
105 }
106