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 Optional<TY> llvm::mc::getExplicit##NAME() { \
30 if (NAME##View->getNumOccurrences()) { \
31 TY res = *NAME##View; \
32 return res; \
33 } \
34 return None; \
35 }
36
MCOPT_EXP(bool,RelaxAll)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
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<EmitDwarfUnwindType> EmitDwarfUnwind(
77 "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),
78 cl::init(EmitDwarfUnwindType::Default),
79 cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always",
80 "Always emit EH frame entries"),
81 clEnumValN(EmitDwarfUnwindType::NoCompactUnwind,
82 "no-compact-unwind",
83 "Only emit EH frame entries when compact unwind is "
84 "not available"),
85 clEnumValN(EmitDwarfUnwindType::Default, "default",
86 "Use target platform default")));
87 MCBINDOPT(EmitDwarfUnwind);
88
89 static cl::opt<bool> ShowMCInst(
90 "asm-show-inst",
91 cl::desc("Emit internal instruction representation to assembly file"));
92 MCBINDOPT(ShowMCInst);
93
94 static cl::opt<bool> FatalWarnings("fatal-warnings",
95 cl::desc("Treat warnings as errors"));
96 MCBINDOPT(FatalWarnings);
97
98 static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
99 static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
100 cl::aliasopt(NoWarn));
101 MCBINDOPT(NoWarn);
102
103 static cl::opt<bool> NoDeprecatedWarn(
104 "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
105 MCBINDOPT(NoDeprecatedWarn);
106
107 static cl::opt<bool> NoTypeCheck(
108 "no-type-check", cl::desc("Suppress type errors (Wasm)"));
109 MCBINDOPT(NoTypeCheck);
110
111 static cl::opt<std::string> ABIName(
112 "target-abi", cl::Hidden,
113 cl::desc("The name of the ABI to be targeted from the backend."),
114 cl::init(""));
115 MCBINDOPT(ABIName);
116
117 #undef MCBINDOPT
118 }
119
InitMCTargetOptionsFromFlags()120 MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
121 MCTargetOptions Options;
122 Options.MCRelaxAll = getRelaxAll();
123 Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
124 Options.Dwarf64 = getDwarf64();
125 Options.DwarfVersion = getDwarfVersion();
126 Options.ShowMCInst = getShowMCInst();
127 Options.ABIName = getABIName();
128 Options.MCFatalWarnings = getFatalWarnings();
129 Options.MCNoWarn = getNoWarn();
130 Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
131 Options.MCNoTypeCheck = getNoTypeCheck();
132 Options.EmitDwarfUnwind = getEmitDwarfUnwind();
133
134 return Options;
135 }
136