MCTargetOptionsCommandFlags.cpp 4.6 KB

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