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 #include "llvm/MC/MCTargetOptions.h"
17 #include "llvm/Support/CommandLine.h"
18 
19 using namespace llvm;
20 
21 #define MCOPT(TY, NAME)                                                        \
22   static cl::opt<TY> *NAME##View;                                              \
23   TY llvm::mc::get##NAME() {                                                   \
24     assert(NAME##View && "RegisterMCTargetOptionsFlags not created.");         \
25     return *NAME##View;                                                        \
26   }
27 
28 #define MCOPT_EXP(TY, NAME)                                                    \
29   MCOPT(TY, NAME)                                                              \
30   Optional<TY> llvm::mc::getExplicit##NAME() {                                 \
31     if (NAME##View->getNumOccurrences()) {                                     \
32       TY res = *NAME##View;                                                    \
33       return res;                                                              \
34     }                                                                          \
35     return None;                                                               \
36   }
37 
38 MCOPT_EXP(bool, RelaxAll)
39 MCOPT(bool, IncrementalLinkerCompatible)
40 MCOPT(int, DwarfVersion)
41 MCOPT(bool, ShowMCInst)
42 MCOPT(bool, FatalWarnings)
43 MCOPT(bool, NoWarn)
44 MCOPT(bool, NoDeprecatedWarn)
45 MCOPT(std::string, ABIName)
46 
47 llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
48 #define MCBINDOPT(NAME)                                                        \
49   do {                                                                         \
50     NAME##View = std::addressof(NAME);                                         \
51   } while (0)
52 
53   static cl::opt<bool> RelaxAll(
54       "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
55                                "in the emitted object file"));
56   MCBINDOPT(RelaxAll);
57 
58   static cl::opt<bool> IncrementalLinkerCompatible(
59       "incremental-linker-compatible",
60       cl::desc(
61           "When used with filetype=obj, "
62           "emit an object file which can be used with an incremental linker"));
63   MCBINDOPT(IncrementalLinkerCompatible);
64 
65   static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
66                                    cl::init(0));
67   MCBINDOPT(DwarfVersion);
68 
69   static cl::opt<bool> ShowMCInst(
70       "asm-show-inst",
71       cl::desc("Emit internal instruction representation to assembly file"));
72   MCBINDOPT(ShowMCInst);
73 
74   static cl::opt<bool> FatalWarnings("fatal-warnings",
75                                      cl::desc("Treat warnings as errors"));
76   MCBINDOPT(FatalWarnings);
77 
78   static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
79   static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
80                            cl::aliasopt(NoWarn));
81   MCBINDOPT(NoWarn);
82 
83   static cl::opt<bool> NoDeprecatedWarn(
84       "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
85   MCBINDOPT(NoDeprecatedWarn);
86 
87   static cl::opt<std::string> ABIName(
88       "target-abi", cl::Hidden,
89       cl::desc("The name of the ABI to be targeted from the backend."),
90       cl::init(""));
91   MCBINDOPT(ABIName);
92 
93 #undef MCBINDOPT
94 }
95 
96 MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
97   MCTargetOptions Options;
98   Options.MCRelaxAll = getRelaxAll();
99   Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
100   Options.DwarfVersion = getDwarfVersion();
101   Options.ShowMCInst = getShowMCInst();
102   Options.ABIName = getABIName();
103   Options.MCFatalWarnings = getFatalWarnings();
104   Options.MCNoWarn = getNoWarn();
105   Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
106   return Options;
107 }
108