MCTargetOptionsCommandFlags.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #include "llvm/MC/MCTargetOptionsCommandFlags.h"
  14. #include "llvm/MC/MCTargetOptions.h"
  15. #include "llvm/Support/CommandLine.h"
  16. using namespace llvm;
  17. #define MCOPT(TY, NAME) \
  18. static cl::opt<TY> *NAME##View; \
  19. TY llvm::mc::get##NAME() { \
  20. assert(NAME##View && "RegisterMCTargetOptionsFlags not created."); \
  21. return *NAME##View; \
  22. }
  23. #define MCOPT_EXP(TY, NAME) \
  24. MCOPT(TY, NAME) \
  25. std::optional<TY> llvm::mc::getExplicit##NAME() { \
  26. if (NAME##View->getNumOccurrences()) { \
  27. TY res = *NAME##View; \
  28. return res; \
  29. } \
  30. return std::nullopt; \
  31. }
  32. MCOPT_EXP(bool, RelaxAll)
  33. MCOPT(bool, IncrementalLinkerCompatible)
  34. MCOPT(int, DwarfVersion)
  35. MCOPT(bool, Dwarf64)
  36. MCOPT(EmitDwarfUnwindType, EmitDwarfUnwind)
  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. MCOPT(std::string, AsSecureLogFile)
  44. llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
  45. #define MCBINDOPT(NAME) \
  46. do { \
  47. NAME##View = std::addressof(NAME); \
  48. } while (0)
  49. static cl::opt<bool> RelaxAll(
  50. "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
  51. "in the emitted object file"));
  52. MCBINDOPT(RelaxAll);
  53. static cl::opt<bool> IncrementalLinkerCompatible(
  54. "incremental-linker-compatible",
  55. cl::desc(
  56. "When used with filetype=obj, "
  57. "emit an object file which can be used with an incremental linker"));
  58. MCBINDOPT(IncrementalLinkerCompatible);
  59. static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
  60. cl::init(0));
  61. MCBINDOPT(DwarfVersion);
  62. static cl::opt<bool> Dwarf64(
  63. "dwarf64",
  64. cl::desc("Generate debugging info in the 64-bit DWARF format"));
  65. MCBINDOPT(Dwarf64);
  66. static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind(
  67. "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),
  68. cl::init(EmitDwarfUnwindType::Default),
  69. cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always",
  70. "Always emit EH frame entries"),
  71. clEnumValN(EmitDwarfUnwindType::NoCompactUnwind,
  72. "no-compact-unwind",
  73. "Only emit EH frame entries when compact unwind is "
  74. "not available"),
  75. clEnumValN(EmitDwarfUnwindType::Default, "default",
  76. "Use target platform default")));
  77. MCBINDOPT(EmitDwarfUnwind);
  78. static cl::opt<bool> ShowMCInst(
  79. "asm-show-inst",
  80. cl::desc("Emit internal instruction representation to assembly file"));
  81. MCBINDOPT(ShowMCInst);
  82. static cl::opt<bool> FatalWarnings("fatal-warnings",
  83. cl::desc("Treat warnings as errors"));
  84. MCBINDOPT(FatalWarnings);
  85. static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
  86. static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
  87. cl::aliasopt(NoWarn));
  88. MCBINDOPT(NoWarn);
  89. static cl::opt<bool> NoDeprecatedWarn(
  90. "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
  91. MCBINDOPT(NoDeprecatedWarn);
  92. static cl::opt<bool> NoTypeCheck(
  93. "no-type-check", cl::desc("Suppress type errors (Wasm)"));
  94. MCBINDOPT(NoTypeCheck);
  95. static cl::opt<std::string> ABIName(
  96. "target-abi", cl::Hidden,
  97. cl::desc("The name of the ABI to be targeted from the backend."),
  98. cl::init(""));
  99. MCBINDOPT(ABIName);
  100. static cl::opt<std::string> AsSecureLogFile(
  101. "as-secure-log-file", cl::desc("As secure log file name"), cl::Hidden);
  102. MCBINDOPT(AsSecureLogFile);
  103. #undef MCBINDOPT
  104. }
  105. MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
  106. MCTargetOptions Options;
  107. Options.MCRelaxAll = getRelaxAll();
  108. Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
  109. Options.Dwarf64 = getDwarf64();
  110. Options.DwarfVersion = getDwarfVersion();
  111. Options.ShowMCInst = getShowMCInst();
  112. Options.ABIName = getABIName();
  113. Options.MCFatalWarnings = getFatalWarnings();
  114. Options.MCNoWarn = getNoWarn();
  115. Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
  116. Options.MCNoTypeCheck = getNoTypeCheck();
  117. Options.EmitDwarfUnwind = getEmitDwarfUnwind();
  118. Options.AsSecureLogFile = getAsSecureLogFile();
  119. return Options;
  120. }