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