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