MCAsmInfo.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //===-- MCAsmInfo.cpp - Asm Info -------------------------------------------==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines target asm properties related what form asm statements
  11. // should take.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/MC/MCAsmInfo.h"
  15. #include "llvm/MC/MCContext.h"
  16. #include "llvm/MC/MCExpr.h"
  17. #include "llvm/MC/MCStreamer.h"
  18. #include "llvm/Support/DataTypes.h"
  19. #include "llvm/Support/Dwarf.h"
  20. #include <cctype>
  21. #include <cstring>
  22. using namespace llvm;
  23. MCAsmInfo::MCAsmInfo() {
  24. PointerSize = 4;
  25. CalleeSaveStackSlotSize = 4;
  26. IsLittleEndian = true;
  27. StackGrowsUp = false;
  28. HasSubsectionsViaSymbols = false;
  29. HasMachoZeroFillDirective = false;
  30. HasMachoTBSSDirective = false;
  31. HasStaticCtorDtorReferenceInStaticMode = false;
  32. MaxInstLength = 4;
  33. MinInstAlignment = 1;
  34. DollarIsPC = false;
  35. SeparatorString = ";";
  36. CommentString = "#";
  37. LabelSuffix = ":";
  38. UseAssignmentForEHBegin = false;
  39. NeedsLocalForSize = false;
  40. PrivateGlobalPrefix = "L";
  41. PrivateLabelPrefix = PrivateGlobalPrefix;
  42. LinkerPrivateGlobalPrefix = "";
  43. InlineAsmStart = "APP";
  44. InlineAsmEnd = "NO_APP";
  45. Code16Directive = ".code16";
  46. Code32Directive = ".code32";
  47. Code64Directive = ".code64";
  48. AssemblerDialect = 0;
  49. AllowAtInName = false;
  50. SupportsQuotedNames = true;
  51. UseDataRegionDirectives = false;
  52. ZeroDirective = "\t.zero\t";
  53. AsciiDirective = "\t.ascii\t";
  54. AscizDirective = "\t.asciz\t";
  55. Data8bitsDirective = "\t.byte\t";
  56. Data16bitsDirective = "\t.short\t";
  57. Data32bitsDirective = "\t.long\t";
  58. Data64bitsDirective = "\t.quad\t";
  59. SunStyleELFSectionSwitchSyntax = false;
  60. UsesELFSectionDirectiveForBSS = false;
  61. AlignmentIsInBytes = true;
  62. TextAlignFillValue = 0;
  63. GPRel64Directive = nullptr;
  64. GPRel32Directive = nullptr;
  65. GlobalDirective = "\t.globl\t";
  66. SetDirectiveSuppressesReloc = false;
  67. HasAggressiveSymbolFolding = true;
  68. COMMDirectiveAlignmentIsInBytes = true;
  69. LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
  70. HasFunctionAlignment = true;
  71. HasDotTypeDotSizeDirective = true;
  72. HasSingleParameterDotFile = true;
  73. HasIdentDirective = false;
  74. HasNoDeadStrip = false;
  75. WeakDirective = "\t.weak\t";
  76. WeakRefDirective = nullptr;
  77. HasWeakDefDirective = false;
  78. HasWeakDefCanBeHiddenDirective = false;
  79. HasLinkOnceDirective = false;
  80. HiddenVisibilityAttr = MCSA_Hidden;
  81. HiddenDeclarationVisibilityAttr = MCSA_Hidden;
  82. ProtectedVisibilityAttr = MCSA_Protected;
  83. SupportsDebugInformation = false;
  84. ExceptionsType = ExceptionHandling::None;
  85. WinEHEncodingType = WinEH::EncodingType::Invalid;
  86. DwarfUsesRelocationsAcrossSections = true;
  87. DwarfFDESymbolsUseAbsDiff = false;
  88. DwarfRegNumForCFI = false;
  89. NeedsDwarfSectionOffsetDirective = false;
  90. UseParensForSymbolVariant = false;
  91. UseLogicalShr = true;
  92. // FIXME: Clang's logic should be synced with the logic used to initialize
  93. // this member and the two implementations should be merged.
  94. // For reference:
  95. // - Solaris always enables the integrated assembler by default
  96. // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
  97. // - Windows always enables the integrated assembler by default
  98. // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
  99. // - MachO targets always enables the integrated assembler by default
  100. // - MCAsmInfoDarwin is handling this case
  101. // - Generic_GCC toolchains enable the integrated assembler on a per
  102. // architecture basis.
  103. // - The target subclasses for AArch64, ARM, and X86 handle these cases
  104. UseIntegratedAssembler = false;
  105. CompressDebugSections = false;
  106. }
  107. MCAsmInfo::~MCAsmInfo() {
  108. }
  109. bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
  110. return false;
  111. }
  112. const MCExpr *
  113. MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
  114. unsigned Encoding,
  115. MCStreamer &Streamer) const {
  116. return getExprForFDESymbol(Sym, Encoding, Streamer);
  117. }
  118. const MCExpr *
  119. MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
  120. unsigned Encoding,
  121. MCStreamer &Streamer) const {
  122. if (!(Encoding & dwarf::DW_EH_PE_pcrel))
  123. return MCSymbolRefExpr::create(Sym, Streamer.getContext());
  124. MCContext &Context = Streamer.getContext();
  125. const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
  126. MCSymbol *PCSym = Context.createTempSymbol();
  127. Streamer.EmitLabel(PCSym);
  128. const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
  129. return MCBinaryExpr::createSub(Res, PC, Context);
  130. }
  131. static bool isAcceptableChar(char C) {
  132. return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
  133. (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
  134. }
  135. bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
  136. if (Name.empty())
  137. return false;
  138. // If any of the characters in the string is an unacceptable character, force
  139. // quotes.
  140. for (char C : Name) {
  141. if (!isAcceptableChar(C))
  142. return false;
  143. }
  144. return true;
  145. }