Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

580 lines
23 KiB

  1. //===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- C++ -*-===//
  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 contains a class to be used as the basis for target specific
  11. // asm writers. This class primarily takes care of global printing constants,
  12. // which are used in very similar ways across all targets.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_MC_MCASMINFO_H
  16. #define LLVM_MC_MCASMINFO_H
  17. #include "llvm/MC/MCDirectives.h"
  18. #include "llvm/MC/MachineLocation.h"
  19. #include <cassert>
  20. #include <vector>
  21. namespace llvm {
  22. class MCExpr;
  23. class MCSection;
  24. class MCStreamer;
  25. class MCSymbol;
  26. class MCContext;
  27. namespace ExceptionHandling {
  28. enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
  29. }
  30. namespace LCOMM {
  31. enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
  32. }
  33. /// MCAsmInfo - This class is intended to be used as a base class for asm
  34. /// properties and features specific to the target.
  35. class MCAsmInfo {
  36. protected:
  37. //===------------------------------------------------------------------===//
  38. // Properties to be set by the target writer, used to configure asm printer.
  39. //
  40. /// PointerSize - Pointer size in bytes.
  41. /// Default is 4.
  42. unsigned PointerSize;
  43. /// CalleeSaveStackSlotSize - Size of the stack slot reserved for
  44. /// callee-saved registers, in bytes.
  45. /// Default is same as pointer size.
  46. unsigned CalleeSaveStackSlotSize;
  47. /// IsLittleEndian - True if target is little endian.
  48. /// Default is true.
  49. bool IsLittleEndian;
  50. /// StackGrowsUp - True if target stack grow up.
  51. /// Default is false.
  52. bool StackGrowsUp;
  53. /// HasSubsectionsViaSymbols - True if this target has the MachO
  54. /// .subsections_via_symbols directive.
  55. bool HasSubsectionsViaSymbols; // Default is false.
  56. /// HasMachoZeroFillDirective - True if this is a MachO target that supports
  57. /// the macho-specific .zerofill directive for emitting BSS Symbols.
  58. bool HasMachoZeroFillDirective; // Default is false.
  59. /// HasMachoTBSSDirective - True if this is a MachO target that supports
  60. /// the macho-specific .tbss directive for emitting thread local BSS Symbols
  61. bool HasMachoTBSSDirective; // Default is false.
  62. /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
  63. /// emit a ".reference .constructors_used" or ".reference .destructors_used"
  64. /// directive after the a static ctor/dtor list. This directive is only
  65. /// emitted in Static relocation model.
  66. bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
  67. /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
  68. /// requires that the debug_line section be of a minimum size. In practice
  69. /// such a linker requires a non empty line sequence if a file is present.
  70. bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
  71. /// MaxInstLength - This is the maximum possible length of an instruction,
  72. /// which is needed to compute the size of an inline asm.
  73. unsigned MaxInstLength; // Defaults to 4.
  74. /// PCSymbol - The symbol used to represent the current PC. Used in PC
  75. /// relative expressions.
  76. const char *PCSymbol; // Defaults to "$".
  77. /// SeparatorString - This string, if specified, is used to separate
  78. /// instructions from each other when on the same line.
  79. const char *SeparatorString; // Defaults to ';'
  80. /// CommentColumn - This indicates the comment num (zero-based) at
  81. /// which asm comments should be printed.
  82. unsigned CommentColumn; // Defaults to 40
  83. /// CommentString - This indicates the comment character used by the
  84. /// assembler.
  85. const char *CommentString; // Defaults to "#"
  86. /// LabelSuffix - This is appended to emitted labels.
  87. const char *LabelSuffix; // Defaults to ":"
  88. /// LabelSuffix - This is appended to emitted labels.
  89. const char *DebugLabelSuffix; // Defaults to ":"
  90. /// GlobalPrefix - If this is set to a non-empty string, it is prepended
  91. /// onto all global symbols. This is often used for "_" or ".".
  92. const char *GlobalPrefix; // Defaults to ""
  93. /// PrivateGlobalPrefix - This prefix is used for globals like constant
  94. /// pool entries that are completely private to the .s file and should not
  95. /// have names in the .o file. This is often "." or "L".
  96. const char *PrivateGlobalPrefix; // Defaults to "."
  97. /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
  98. /// be passed through the assembler but be removed by the linker. This
  99. /// is "l" on Darwin, currently used for some ObjC metadata.
  100. const char *LinkerPrivateGlobalPrefix; // Defaults to ""
  101. /// InlineAsmStart/End - If these are nonempty, they contain a directive to
  102. /// emit before and after an inline assembly statement.
  103. const char *InlineAsmStart; // Defaults to "#APP\n"
  104. const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
  105. /// Code16Directive, Code32Directive, Code64Directive - These are assembly
  106. /// directives that tells the assembler to interpret the following
  107. /// instructions differently.
  108. const char *Code16Directive; // Defaults to ".code16"
  109. const char *Code32Directive; // Defaults to ".code32"
  110. const char *Code64Directive; // Defaults to ".code64"
  111. /// AssemblerDialect - Which dialect of an assembler variant to use.
  112. unsigned AssemblerDialect; // Defaults to 0
  113. /// AllowQuotesInName - This is true if the assembler allows for complex
  114. /// symbol names to be surrounded in quotes. This defaults to false.
  115. bool AllowQuotesInName;
  116. /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
  117. /// names to start with a digit (e.g., "0x0021"). This defaults to false.
  118. bool AllowNameToStartWithDigit;
  119. /// AllowPeriodsInName - This is true if the assembler allows periods in
  120. /// symbol names. This defaults to true.
  121. bool AllowPeriodsInName;
  122. /// AllowUTF8 - This is true if the assembler accepts UTF-8 input.
  123. // FIXME: Make this a more general encoding setting?
  124. bool AllowUTF8;
  125. /// UseDataRegionDirectives - This is true if data region markers should
  126. /// be printed as ".data_region/.end_data_region" directives. If false,
  127. /// use "$d/$a" labels instead.
  128. bool UseDataRegionDirectives;
  129. //===--- Data Emission Directives -------------------------------------===//
  130. /// ZeroDirective - this should be set to the directive used to get some
  131. /// number of zero bytes emitted to the current section. Common cases are
  132. /// "\t.zero\t" and "\t.space\t". If this is set to null, the
  133. /// Data*bitsDirective's will be used to emit zero bytes.
  134. const char *ZeroDirective; // Defaults to "\t.zero\t"
  135. /// AsciiDirective - This directive allows emission of an ascii string with
  136. /// the standard C escape characters embedded into it.
  137. const char *AsciiDirective; // Defaults to "\t.ascii\t"
  138. /// AscizDirective - If not null, this allows for special handling of
  139. /// zero terminated strings on this target. This is commonly supported as
  140. /// ".asciz". If a target doesn't support this, it can be set to null.
  141. const char *AscizDirective; // Defaults to "\t.asciz\t"
  142. /// DataDirectives - These directives are used to output some unit of
  143. /// integer data to the current section. If a data directive is set to
  144. /// null, smaller data directives will be used to emit the large sizes.
  145. const char *Data8bitsDirective; // Defaults to "\t.byte\t"
  146. const char *Data16bitsDirective; // Defaults to "\t.short\t"
  147. const char *Data32bitsDirective; // Defaults to "\t.long\t"
  148. const char *Data64bitsDirective; // Defaults to "\t.quad\t"
  149. /// GPRel64Directive - if non-null, a directive that is used to emit a word
  150. /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword
  151. /// on Mips.
  152. const char *GPRel64Directive; // Defaults to NULL.
  153. /// GPRel32Directive - if non-null, a directive that is used to emit a word
  154. /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
  155. /// on Mips or .gprel32 on Alpha.
  156. const char *GPRel32Directive; // Defaults to NULL.
  157. /// getDataASDirective - Return the directive that should be used to emit
  158. /// data of the specified size to the specified numeric address space.
  159. virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
  160. assert(AS != 0 && "Don't know the directives for default addr space");
  161. return 0;
  162. }
  163. /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
  164. /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
  165. /// normal ELF syntax (,"a,w") in .section directives.
  166. bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
  167. /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
  168. /// '.section' directive before the '.bss' one. It's used for PPC/Linux
  169. /// which doesn't support the '.bss' directive only.
  170. bool UsesELFSectionDirectiveForBSS; // Defaults to false.
  171. /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
  172. /// style mangling for functions with X86_StdCall/X86_FastCall calling
  173. /// convention.
  174. bool HasMicrosoftFastStdCallMangling; // Defaults to false.
  175. //===--- Alignment Information ----------------------------------------===//
  176. /// AlignDirective - The directive used to emit round up to an alignment
  177. /// boundary.
  178. ///
  179. const char *AlignDirective; // Defaults to "\t.align\t"
  180. /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
  181. /// emits ".align N" directives, where N is the number of bytes to align to.
  182. /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
  183. /// boundary.
  184. bool AlignmentIsInBytes; // Defaults to true
  185. /// TextAlignFillValue - If non-zero, this is used to fill the executable
  186. /// space created as the result of a alignment directive.
  187. unsigned TextAlignFillValue; // Defaults to 0
  188. //===--- Global Variable Emission Directives --------------------------===//
  189. /// GlobalDirective - This is the directive used to declare a global entity.
  190. ///
  191. const char *GlobalDirective; // Defaults to NULL.
  192. /// ExternDirective - This is the directive used to declare external
  193. /// globals.
  194. ///
  195. const char *ExternDirective; // Defaults to NULL.
  196. /// HasSetDirective - True if the assembler supports the .set directive.
  197. bool HasSetDirective; // Defaults to true.
  198. /// HasAggressiveSymbolFolding - False if the assembler requires that we use
  199. /// Lc = a - b
  200. /// .long Lc
  201. /// instead of
  202. /// .long a - b
  203. bool HasAggressiveSymbolFolding; // Defaults to true.
  204. /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
  205. /// alignment is to be specified in bytes instead of log2(n).
  206. bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
  207. /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the
  208. /// target supports an alignment argument and how it is interpreted.
  209. LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment.
  210. /// HasDotTypeDotSizeDirective - True if the target has .type and .size
  211. /// directives, this is true for most ELF targets.
  212. bool HasDotTypeDotSizeDirective; // Defaults to true.
  213. /// HasSingleParameterDotFile - True if the target has a single parameter
  214. /// .file directive, this is true for ELF targets.
  215. bool HasSingleParameterDotFile; // Defaults to true.
  216. /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
  217. /// directive.
  218. bool HasNoDeadStrip; // Defaults to false.
  219. /// HasSymbolResolver - True if this target supports the MachO
  220. /// .symbol_resolver directive.
  221. bool HasSymbolResolver; // Defaults to false.
  222. /// WeakRefDirective - This directive, if non-null, is used to declare a
  223. /// global as being a weak undefined symbol.
  224. const char *WeakRefDirective; // Defaults to NULL.
  225. /// WeakDefDirective - This directive, if non-null, is used to declare a
  226. /// global as being a weak defined symbol.
  227. const char *WeakDefDirective; // Defaults to NULL.
  228. /// LinkOnceDirective - This directive, if non-null is used to declare a
  229. /// global as being a weak defined symbol. This is used on cygwin/mingw.
  230. const char *LinkOnceDirective; // Defaults to NULL.
  231. /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
  232. /// declare a symbol as having hidden visibility.
  233. MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
  234. /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
  235. /// is used to declare an undefined symbol as having hidden visibility.
  236. MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
  237. /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
  238. /// to declare a symbol as having protected visibility.
  239. MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
  240. //===--- Dwarf Emission Directives -----------------------------------===//
  241. /// HasLEB128 - True if target asm supports leb128 directives.
  242. bool HasLEB128; // Defaults to false.
  243. /// SupportsDebugInformation - True if target supports emission of debugging
  244. /// information.
  245. bool SupportsDebugInformation; // Defaults to false.
  246. /// SupportsExceptionHandling - True if target supports exception handling.
  247. ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
  248. /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
  249. /// encode inline subroutine information.
  250. bool DwarfUsesInlineInfoSection; // Defaults to false.
  251. /// DwarfSectionOffsetDirective - Special section offset directive.
  252. const char* DwarfSectionOffsetDirective; // Defaults to NULL
  253. /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
  254. /// uses relocations for references to other .debug_* sections.
  255. bool DwarfUsesRelocationsAcrossSections;
  256. /// DwarfRegNumForCFI - True if dwarf register numbers are printed
  257. /// instead of symbolic register names in .cfi_* directives.
  258. bool DwarfRegNumForCFI; // Defaults to false;
  259. //===--- Prologue State ----------------------------------------------===//
  260. std::vector<MachineMove> InitialFrameState;
  261. public:
  262. explicit MCAsmInfo();
  263. virtual ~MCAsmInfo();
  264. // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
  265. static unsigned getSLEB128Size(int Value);
  266. static unsigned getULEB128Size(unsigned Value);
  267. /// getPointerSize - Get the pointer size in bytes.
  268. unsigned getPointerSize() const {
  269. return PointerSize;
  270. }
  271. /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
  272. /// size in bytes.
  273. unsigned getCalleeSaveStackSlotSize() const {
  274. return CalleeSaveStackSlotSize;
  275. }
  276. /// isLittleEndian - True if the target is little endian.
  277. bool isLittleEndian() const {
  278. return IsLittleEndian;
  279. }
  280. /// isStackGrowthDirectionUp - True if target stack grow up.
  281. bool isStackGrowthDirectionUp() const {
  282. return StackGrowsUp;
  283. }
  284. bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
  285. // Data directive accessors.
  286. //
  287. const char *getData8bitsDirective(unsigned AS = 0) const {
  288. return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
  289. }
  290. const char *getData16bitsDirective(unsigned AS = 0) const {
  291. return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
  292. }
  293. const char *getData32bitsDirective(unsigned AS = 0) const {
  294. return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
  295. }
  296. const char *getData64bitsDirective(unsigned AS = 0) const {
  297. return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
  298. }
  299. const char *getGPRel64Directive() const { return GPRel64Directive; }
  300. const char *getGPRel32Directive() const { return GPRel32Directive; }
  301. /// getNonexecutableStackSection - Targets can implement this method to
  302. /// specify a section to switch to if the translation unit doesn't have any
  303. /// trampolines that require an executable stack.
  304. virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
  305. return 0;
  306. }
  307. virtual const MCExpr *
  308. getExprForPersonalitySymbol(const MCSymbol *Sym,
  309. unsigned Encoding,
  310. MCStreamer &Streamer) const;
  311. const MCExpr *
  312. getExprForFDESymbol(const MCSymbol *Sym,
  313. unsigned Encoding,
  314. MCStreamer &Streamer) const;
  315. bool usesSunStyleELFSectionSwitchSyntax() const {
  316. return SunStyleELFSectionSwitchSyntax;
  317. }
  318. bool usesELFSectionDirectiveForBSS() const {
  319. return UsesELFSectionDirectiveForBSS;
  320. }
  321. bool hasMicrosoftFastStdCallMangling() const {
  322. return HasMicrosoftFastStdCallMangling;
  323. }
  324. // Accessors.
  325. //
  326. bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
  327. bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
  328. bool hasStaticCtorDtorReferenceInStaticMode() const {
  329. return HasStaticCtorDtorReferenceInStaticMode;
  330. }
  331. bool getLinkerRequiresNonEmptyDwarfLines() const {
  332. return LinkerRequiresNonEmptyDwarfLines;
  333. }
  334. unsigned getMaxInstLength() const {
  335. return MaxInstLength;
  336. }
  337. const char *getPCSymbol() const {
  338. return PCSymbol;
  339. }
  340. const char *getSeparatorString() const {
  341. return SeparatorString;
  342. }
  343. unsigned getCommentColumn() const {
  344. return CommentColumn;
  345. }
  346. const char *getCommentString() const {
  347. return CommentString;
  348. }
  349. const char *getLabelSuffix() const {
  350. return LabelSuffix;
  351. }
  352. const char *getDebugLabelSuffix() const {
  353. return DebugLabelSuffix;
  354. }
  355. const char *getGlobalPrefix() const {
  356. return GlobalPrefix;
  357. }
  358. const char *getPrivateGlobalPrefix() const {
  359. return PrivateGlobalPrefix;
  360. }
  361. const char *getLinkerPrivateGlobalPrefix() const {
  362. return LinkerPrivateGlobalPrefix;
  363. }
  364. const char *getInlineAsmStart() const {
  365. return InlineAsmStart;
  366. }
  367. const char *getInlineAsmEnd() const {
  368. return InlineAsmEnd;
  369. }
  370. const char *getCode16Directive() const {
  371. return Code16Directive;
  372. }
  373. const char *getCode32Directive() const {
  374. return Code32Directive;
  375. }
  376. const char *getCode64Directive() const {
  377. return Code64Directive;
  378. }
  379. unsigned getAssemblerDialect() const {
  380. return AssemblerDialect;
  381. }
  382. bool doesAllowQuotesInName() const {
  383. return AllowQuotesInName;
  384. }
  385. bool doesAllowNameToStartWithDigit() const {
  386. return AllowNameToStartWithDigit;
  387. }
  388. bool doesAllowPeriodsInName() const {
  389. return AllowPeriodsInName;
  390. }
  391. bool doesAllowUTF8() const {
  392. return AllowUTF8;
  393. }
  394. bool doesSupportDataRegionDirectives() const {
  395. return UseDataRegionDirectives;
  396. }
  397. const char *getZeroDirective() const {
  398. return ZeroDirective;
  399. }
  400. const char *getAsciiDirective() const {
  401. return AsciiDirective;
  402. }
  403. const char *getAscizDirective() const {
  404. return AscizDirective;
  405. }
  406. const char *getAlignDirective() const {
  407. return AlignDirective;
  408. }
  409. bool getAlignmentIsInBytes() const {
  410. return AlignmentIsInBytes;
  411. }
  412. unsigned getTextAlignFillValue() const {
  413. return TextAlignFillValue;
  414. }
  415. const char *getGlobalDirective() const {
  416. return GlobalDirective;
  417. }
  418. const char *getExternDirective() const {
  419. return ExternDirective;
  420. }
  421. bool hasSetDirective() const { return HasSetDirective; }
  422. bool hasAggressiveSymbolFolding() const {
  423. return HasAggressiveSymbolFolding;
  424. }
  425. bool getCOMMDirectiveAlignmentIsInBytes() const {
  426. return COMMDirectiveAlignmentIsInBytes;
  427. }
  428. LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
  429. return LCOMMDirectiveAlignmentType;
  430. }
  431. bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
  432. bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
  433. bool hasNoDeadStrip() const { return HasNoDeadStrip; }
  434. bool hasSymbolResolver() const { return HasSymbolResolver; }
  435. const char *getWeakRefDirective() const { return WeakRefDirective; }
  436. const char *getWeakDefDirective() const { return WeakDefDirective; }
  437. const char *getLinkOnceDirective() const { return LinkOnceDirective; }
  438. MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
  439. MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
  440. return HiddenDeclarationVisibilityAttr;
  441. }
  442. MCSymbolAttr getProtectedVisibilityAttr() const {
  443. return ProtectedVisibilityAttr;
  444. }
  445. bool hasLEB128() const {
  446. return HasLEB128;
  447. }
  448. bool doesSupportDebugInformation() const {
  449. return SupportsDebugInformation;
  450. }
  451. bool doesSupportExceptionHandling() const {
  452. return ExceptionsType != ExceptionHandling::None;
  453. }
  454. ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
  455. return ExceptionsType;
  456. }
  457. bool isExceptionHandlingDwarf() const {
  458. return
  459. (ExceptionsType == ExceptionHandling::DwarfCFI ||
  460. ExceptionsType == ExceptionHandling::ARM ||
  461. ExceptionsType == ExceptionHandling::Win64);
  462. }
  463. bool doesDwarfUseInlineInfoSection() const {
  464. return DwarfUsesInlineInfoSection;
  465. }
  466. const char *getDwarfSectionOffsetDirective() const {
  467. return DwarfSectionOffsetDirective;
  468. }
  469. bool doesDwarfUseRelocationsAcrossSections() const {
  470. return DwarfUsesRelocationsAcrossSections;
  471. }
  472. bool useDwarfRegNumForCFI() const {
  473. return DwarfRegNumForCFI;
  474. }
  475. void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
  476. const MachineLocation &S) {
  477. InitialFrameState.push_back(MachineMove(label, D, S));
  478. }
  479. const std::vector<MachineMove> &getInitialFrameState() const {
  480. return InitialFrameState;
  481. }
  482. };
  483. }
  484. #endif