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