MCTargetOptionsCommandFlags.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include "llvm/MC/MCTargetOptionsCommandFlags.h"
  15. #include "llvm/MC/MCTargetOptions.h"
  16. #include "llvm/Support/CommandLine.h"
  17. using namespace llvm;
  18. #define MCOPT(TY, NAME) \
  19. static cl::opt<TY> *NAME##View; \
  20. TY llvm::mc::get##NAME() { \
  21. assert(NAME##View && "RegisterMCTargetOptionsFlags not created."); \
  22. return *NAME##View; \
  23. }
  24. #define MCOPT_EXP(TY, NAME) \
  25. MCOPT(TY, NAME) \
  26. Optional<TY> llvm::mc::getExplicit##NAME() { \
  27. if (NAME##View->getNumOccurrences()) { \
  28. TY res = *NAME##View; \
  29. return res; \
  30. } \
  31. return None; \
  32. }
  33. MCOPT_EXP(bool, RelaxAll)
  34. MCOPT(bool, IncrementalLinkerCompatible)
  35. MCOPT(int, DwarfVersion)
  36. MCOPT(bool, Dwarf64)
  37. MCOPT(bool, ShowMCInst)
  38. MCOPT(bool, FatalWarnings)
  39. MCOPT(bool, NoWarn)
  40. MCOPT(bool, NoDeprecatedWarn)
  41. MCOPT(std::string, ABIName)
  42. llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
  43. #define MCBINDOPT(NAME) \
  44. do { \
  45. NAME##View = std::addressof(NAME); \
  46. } while (0)
  47. static cl::opt<bool> RelaxAll(
  48. "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
  49. "in the emitted object file"));
  50. MCBINDOPT(RelaxAll);
  51. static cl::opt<bool> IncrementalLinkerCompatible(
  52. "incremental-linker-compatible",
  53. cl::desc(
  54. "When used with filetype=obj, "
  55. "emit an object file which can be used with an incremental linker"));
  56. MCBINDOPT(IncrementalLinkerCompatible);
  57. static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
  58. cl::init(0));
  59. MCBINDOPT(DwarfVersion);
  60. static cl::opt<bool> Dwarf64(
  61. "dwarf64",
  62. cl::desc("Generate debugging info in the 64-bit DWARF format"));
  63. MCBINDOPT(Dwarf64);
  64. static cl::opt<bool> ShowMCInst(
  65. "asm-show-inst",
  66. cl::desc("Emit internal instruction representation to assembly file"));
  67. MCBINDOPT(ShowMCInst);
  68. static cl::opt<bool> FatalWarnings("fatal-warnings",
  69. cl::desc("Treat warnings as errors"));
  70. MCBINDOPT(FatalWarnings);
  71. static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
  72. static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
  73. cl::aliasopt(NoWarn));
  74. MCBINDOPT(NoWarn);
  75. static cl::opt<bool> NoDeprecatedWarn(
  76. "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
  77. MCBINDOPT(NoDeprecatedWarn);
  78. static cl::opt<std::string> ABIName(
  79. "target-abi", cl::Hidden,
  80. cl::desc("The name of the ABI to be targeted from the backend."),
  81. cl::init(""));
  82. MCBINDOPT(ABIName);
  83. #undef MCBINDOPT
  84. }
  85. MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
  86. MCTargetOptions Options;
  87. Options.MCRelaxAll = getRelaxAll();
  88. Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
  89. Options.Dwarf64 = getDwarf64();
  90. Options.DwarfVersion = getDwarfVersion();
  91. Options.ShowMCInst = getShowMCInst();
  92. Options.ABIName = getABIName();
  93. Options.MCFatalWarnings = getFatalWarnings();
  94. Options.MCNoWarn = getNoWarn();
  95. Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
  96. return Options;
  97. }