1 //===-- MCTargetOptionsCommandFlags.cpp -----------------------*- C++ //-*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains machine code-specific flags that are shared between
10 // different command line tools.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
15 #include "llvm/MC/MCTargetOptions.h"
16 #include "llvm/Support/CommandLine.h"
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."); \
27 #define MCOPT_EXP(TY, NAME) \
29 std::optional<TY> llvm::mc::getExplicit##NAME() { \
30 if (NAME##View->getNumOccurrences()) { \
31 TY res = *NAME##View; \
34 return std::nullopt; \
37 MCOPT_EXP(bool, RelaxAll
)
38 MCOPT(bool, IncrementalLinkerCompatible
)
39 MCOPT(int, DwarfVersion
)
41 MCOPT(EmitDwarfUnwindType
, EmitDwarfUnwind
)
42 MCOPT(bool, EmitCompactUnwindNonCanonical
)
43 MCOPT(bool, ShowMCInst
)
44 MCOPT(bool, FatalWarnings
)
46 MCOPT(bool, NoDeprecatedWarn
)
47 MCOPT(bool, NoTypeCheck
)
48 MCOPT(std::string
, ABIName
)
49 MCOPT(std::string
, AsSecureLogFile
)
51 llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
52 #define MCBINDOPT(NAME) \
54 NAME##View = std::addressof(NAME); \
57 static cl::opt
<bool> RelaxAll(
58 "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
59 "in the emitted object file"));
62 static cl::opt
<bool> IncrementalLinkerCompatible(
63 "incremental-linker-compatible",
65 "When used with filetype=obj, "
66 "emit an object file which can be used with an incremental linker"));
67 MCBINDOPT(IncrementalLinkerCompatible
);
69 static cl::opt
<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
71 MCBINDOPT(DwarfVersion
);
73 static cl::opt
<bool> Dwarf64(
75 cl::desc("Generate debugging info in the 64-bit DWARF format"));
78 static cl::opt
<EmitDwarfUnwindType
> EmitDwarfUnwind(
79 "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),
80 cl::init(EmitDwarfUnwindType::Default
),
81 cl::values(clEnumValN(EmitDwarfUnwindType::Always
, "always",
82 "Always emit EH frame entries"),
83 clEnumValN(EmitDwarfUnwindType::NoCompactUnwind
,
85 "Only emit EH frame entries when compact unwind is "
87 clEnumValN(EmitDwarfUnwindType::Default
, "default",
88 "Use target platform default")));
89 MCBINDOPT(EmitDwarfUnwind
);
91 static cl::opt
<bool> EmitCompactUnwindNonCanonical(
92 "emit-compact-unwind-non-canonical",
94 "Whether to try to emit Compact Unwind for non canonical entries."),
96 false)); // By default, use DWARF for non-canonical personalities.
97 MCBINDOPT(EmitCompactUnwindNonCanonical
);
99 static cl::opt
<bool> ShowMCInst(
101 cl::desc("Emit internal instruction representation to assembly file"));
102 MCBINDOPT(ShowMCInst
);
104 static cl::opt
<bool> FatalWarnings("fatal-warnings",
105 cl::desc("Treat warnings as errors"));
106 MCBINDOPT(FatalWarnings
);
108 static cl::opt
<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
109 static cl::alias
NoWarnW("W", cl::desc("Alias for --no-warn"),
110 cl::aliasopt(NoWarn
));
113 static cl::opt
<bool> NoDeprecatedWarn(
114 "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
115 MCBINDOPT(NoDeprecatedWarn
);
117 static cl::opt
<bool> NoTypeCheck(
118 "no-type-check", cl::desc("Suppress type errors (Wasm)"));
119 MCBINDOPT(NoTypeCheck
);
121 static cl::opt
<std::string
> ABIName(
122 "target-abi", cl::Hidden
,
123 cl::desc("The name of the ABI to be targeted from the backend."),
127 static cl::opt
<std::string
> AsSecureLogFile(
128 "as-secure-log-file", cl::desc("As secure log file name"), cl::Hidden
);
129 MCBINDOPT(AsSecureLogFile
);
134 MCTargetOptions
llvm::mc::InitMCTargetOptionsFromFlags() {
135 MCTargetOptions Options
;
136 Options
.MCRelaxAll
= getRelaxAll();
137 Options
.MCIncrementalLinkerCompatible
= getIncrementalLinkerCompatible();
138 Options
.Dwarf64
= getDwarf64();
139 Options
.DwarfVersion
= getDwarfVersion();
140 Options
.ShowMCInst
= getShowMCInst();
141 Options
.ABIName
= getABIName();
142 Options
.MCFatalWarnings
= getFatalWarnings();
143 Options
.MCNoWarn
= getNoWarn();
144 Options
.MCNoDeprecatedWarn
= getNoDeprecatedWarn();
145 Options
.MCNoTypeCheck
= getNoTypeCheck();
146 Options
.EmitDwarfUnwind
= getEmitDwarfUnwind();
147 Options
.EmitCompactUnwindNonCanonical
= getEmitCompactUnwindNonCanonical();
148 Options
.AsSecureLogFile
= getAsSecureLogFile();