1 //===-- MCTargetOptionsCommandFlags.cpp -----------------------*- 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 // This file contains machine code-specific flags that are shared between
10 // different command line tools.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
15 #include "llvm/MC/MCTargetOptions.h"
16 #include "llvm/Support/CommandLine.h"
17 
18 using namespace llvm;
19 
20 #define MCOPT(TY, NAME)                                                        \
21   static cl::opt<TY> *NAME##View;                                              \
22   TY llvm::mc::get##NAME() {                                                   \
23     assert(NAME##View && "RegisterMCTargetOptionsFlags not created.");         \
24     return *NAME##View;                                                        \
25   }
26 
27 #define MCOPT_EXP(TY, NAME)                                                    \
28   MCOPT(TY, NAME)                                                              \
29   std::optional<TY> llvm::mc::getExplicit##NAME() {                            \
30     if (NAME##View->getNumOccurrences()) {                                     \
31       TY res = *NAME##View;                                                    \
32       return res;                                                              \
33     }                                                                          \
34     return std::nullopt;                                                       \
35   }
36 
37 MCOPT_EXP(bool, RelaxAll)
38 MCOPT(bool, IncrementalLinkerCompatible)
39 MCOPT(int, DwarfVersion)
40 MCOPT(bool, Dwarf64)
41 MCOPT(EmitDwarfUnwindType, EmitDwarfUnwind)
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 MCOPT(std::string, AsSecureLogFile)
49 
50 llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
51 #define MCBINDOPT(NAME)                                                        \
52   do {                                                                         \
53     NAME##View = std::addressof(NAME);                                         \
54   } while (0)
55 
56   static cl::opt<bool> RelaxAll(
57       "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
58                                "in the emitted object file"));
59   MCBINDOPT(RelaxAll);
60 
61   static cl::opt<bool> IncrementalLinkerCompatible(
62       "incremental-linker-compatible",
63       cl::desc(
64           "When used with filetype=obj, "
65           "emit an object file which can be used with an incremental linker"));
66   MCBINDOPT(IncrementalLinkerCompatible);
67 
68   static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
69                                    cl::init(0));
70   MCBINDOPT(DwarfVersion);
71 
72   static cl::opt<bool> Dwarf64(
73       "dwarf64",
74       cl::desc("Generate debugging info in the 64-bit DWARF format"));
75   MCBINDOPT(Dwarf64);
76 
77   static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind(
78       "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),
79       cl::init(EmitDwarfUnwindType::Default),
80       cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always",
81                             "Always emit EH frame entries"),
82                  clEnumValN(EmitDwarfUnwindType::NoCompactUnwind,
83                             "no-compact-unwind",
84                             "Only emit EH frame entries when compact unwind is "
85                             "not available"),
86                  clEnumValN(EmitDwarfUnwindType::Default, "default",
87                             "Use target platform default")));
88   MCBINDOPT(EmitDwarfUnwind);
89 
90   static cl::opt<bool> ShowMCInst(
91       "asm-show-inst",
92       cl::desc("Emit internal instruction representation to assembly file"));
93   MCBINDOPT(ShowMCInst);
94 
95   static cl::opt<bool> FatalWarnings("fatal-warnings",
96                                      cl::desc("Treat warnings as errors"));
97   MCBINDOPT(FatalWarnings);
98 
99   static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
100   static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
101                            cl::aliasopt(NoWarn));
102   MCBINDOPT(NoWarn);
103 
104   static cl::opt<bool> NoDeprecatedWarn(
105       "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
106   MCBINDOPT(NoDeprecatedWarn);
107 
108   static cl::opt<bool> NoTypeCheck(
109       "no-type-check", cl::desc("Suppress type errors (Wasm)"));
110   MCBINDOPT(NoTypeCheck);
111 
112   static cl::opt<std::string> ABIName(
113       "target-abi", cl::Hidden,
114       cl::desc("The name of the ABI to be targeted from the backend."),
115       cl::init(""));
116   MCBINDOPT(ABIName);
117 
118   static cl::opt<std::string> AsSecureLogFile(
119       "as-secure-log-file", cl::desc("As secure log file name"), cl::Hidden);
120   MCBINDOPT(AsSecureLogFile);
121 
122 #undef MCBINDOPT
123 }
124 
125 MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
126   MCTargetOptions Options;
127   Options.MCRelaxAll = getRelaxAll();
128   Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
129   Options.Dwarf64 = getDwarf64();
130   Options.DwarfVersion = getDwarfVersion();
131   Options.ShowMCInst = getShowMCInst();
132   Options.ABIName = getABIName();
133   Options.MCFatalWarnings = getFatalWarnings();
134   Options.MCNoWarn = getNoWarn();
135   Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
136   Options.MCNoTypeCheck = getNoTypeCheck();
137   Options.EmitDwarfUnwind = getEmitDwarfUnwind();
138   Options.AsSecureLogFile = getAsSecureLogFile();
139 
140   return Options;
141 }
142