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, Dwarf64)
42 MCOPT(bool, ShowMCInst)
43 MCOPT(bool, FatalWarnings)
44 MCOPT(bool, NoWarn)
45 MCOPT(bool, NoDeprecatedWarn)
46 MCOPT(bool, NoTypeCheck)
47 MCOPT(std::string, ABIName)
48 
49 llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
50 #define MCBINDOPT(NAME)                                                        \
51   do {                                                                         \
52     NAME##View = std::addressof(NAME);                                         \
53   } while (0)
54 
55   static cl::opt<bool> RelaxAll(
56       "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
57                                "in the emitted object file"));
58   MCBINDOPT(RelaxAll);
59 
60   static cl::opt<bool> IncrementalLinkerCompatible(
61       "incremental-linker-compatible",
62       cl::desc(
63           "When used with filetype=obj, "
64           "emit an object file which can be used with an incremental linker"));
65   MCBINDOPT(IncrementalLinkerCompatible);
66 
67   static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
68                                    cl::init(0));
69   MCBINDOPT(DwarfVersion);
70 
71   static cl::opt<bool> Dwarf64(
72       "dwarf64",
73       cl::desc("Generate debugging info in the 64-bit DWARF format"));
74   MCBINDOPT(Dwarf64);
75 
76   static cl::opt<bool> ShowMCInst(
77       "asm-show-inst",
78       cl::desc("Emit internal instruction representation to assembly file"));
79   MCBINDOPT(ShowMCInst);
80 
81   static cl::opt<bool> FatalWarnings("fatal-warnings",
82                                      cl::desc("Treat warnings as errors"));
83   MCBINDOPT(FatalWarnings);
84 
85   static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
86   static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
87                            cl::aliasopt(NoWarn));
88   MCBINDOPT(NoWarn);
89 
90   static cl::opt<bool> NoDeprecatedWarn(
91       "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
92   MCBINDOPT(NoDeprecatedWarn);
93 
94   static cl::opt<bool> NoTypeCheck(
95       "no-type-check", cl::desc("Suppress type errors (Wasm)"));
96   MCBINDOPT(NoTypeCheck);
97 
98   static cl::opt<std::string> ABIName(
99       "target-abi", cl::Hidden,
100       cl::desc("The name of the ABI to be targeted from the backend."),
101       cl::init(""));
102   MCBINDOPT(ABIName);
103 
104 #undef MCBINDOPT
105 }
106 
107 MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
108   MCTargetOptions Options;
109   Options.MCRelaxAll = getRelaxAll();
110   Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
111   Options.Dwarf64 = getDwarf64();
112   Options.DwarfVersion = getDwarfVersion();
113   Options.ShowMCInst = getShowMCInst();
114   Options.ABIName = getABIName();
115   Options.MCFatalWarnings = getFatalWarnings();
116   Options.MCNoWarn = getNoWarn();
117   Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
118   Options.MCNoTypeCheck = getNoTypeCheck();
119   return Options;
120 }
121