MCAsmInfo.h revision 208954
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/MCDirectives.h" 20#include <cassert> 21 22namespace llvm { 23 class MCSection; 24 class MCContext; 25 26 /// MCAsmInfo - This class is intended to be used as a base class for asm 27 /// properties and features specific to the target. 28 namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; } 29 30 class MCAsmInfo { 31 protected: 32 //===------------------------------------------------------------------===// 33 // Properties to be set by the target writer, used to configure asm printer. 34 // 35 36 /// HasSubsectionsViaSymbols - True if this target has the MachO 37 /// .subsections_via_symbols directive. 38 bool HasSubsectionsViaSymbols; // Default is false. 39 40 /// HasMachoZeroFillDirective - True if this is a MachO target that supports 41 /// the macho-specific .zerofill directive for emitting BSS Symbols. 42 bool HasMachoZeroFillDirective; // Default is false. 43 44 /// HasMachoTBSSDirective - True if this is a MachO target that supports 45 /// the macho-specific .tbss directive for emitting thread local BSS Symbols 46 bool HasMachoTBSSDirective; // Default is false. 47 48 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should 49 /// emit a ".reference .constructors_used" or ".reference .destructors_used" 50 /// directive after the a static ctor/dtor list. This directive is only 51 /// emitted in Static relocation model. 52 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false. 53 54 /// MaxInstLength - This is the maximum possible length of an instruction, 55 /// which is needed to compute the size of an inline asm. 56 unsigned MaxInstLength; // Defaults to 4. 57 58 /// PCSymbol - The symbol used to represent the current PC. Used in PC 59 /// relative expressions. 60 const char *PCSymbol; // Defaults to "$". 61 62 /// SeparatorChar - This character, if specified, is used to separate 63 /// instructions from each other when on the same line. This is used to 64 /// measure inline asm instructions. 65 char SeparatorChar; // Defaults to ';' 66 67 /// CommentColumn - This indicates the comment num (zero-based) at 68 /// which asm comments should be printed. 69 unsigned CommentColumn; // Defaults to 40 70 71 /// CommentString - This indicates the comment character used by the 72 /// assembler. 73 const char *CommentString; // Defaults to "#" 74 75 /// GlobalPrefix - If this is set to a non-empty string, it is prepended 76 /// onto all global symbols. This is often used for "_" or ".". 77 const char *GlobalPrefix; // Defaults to "" 78 79 /// PrivateGlobalPrefix - This prefix is used for globals like constant 80 /// pool entries that are completely private to the .s file and should not 81 /// have names in the .o file. This is often "." or "L". 82 const char *PrivateGlobalPrefix; // Defaults to "." 83 84 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should 85 /// be passed through the assembler but be removed by the linker. This 86 /// is "l" on Darwin, currently used for some ObjC metadata. 87 const char *LinkerPrivateGlobalPrefix; // Defaults to "" 88 89 /// InlineAsmStart/End - If these are nonempty, they contain a directive to 90 /// emit before and after an inline assembly statement. 91 const char *InlineAsmStart; // Defaults to "#APP\n" 92 const char *InlineAsmEnd; // Defaults to "#NO_APP\n" 93 94 /// AssemblerDialect - Which dialect of an assembler variant to use. 95 unsigned AssemblerDialect; // Defaults to 0 96 97 /// AllowQuotesInName - This is true if the assembler allows for complex 98 /// symbol names to be surrounded in quotes. This defaults to false. 99 bool AllowQuotesInName; 100 101 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol 102 /// names to start with a digit (e.g., "0x0021"). This defaults to false. 103 bool AllowNameToStartWithDigit; 104 105 /// AllowPeriodsInName - This is true if the assembler allows periods in 106 /// symbol names. This defaults to true. 107 bool AllowPeriodsInName; 108 109 //===--- Data Emission Directives -------------------------------------===// 110 111 /// ZeroDirective - this should be set to the directive used to get some 112 /// number of zero bytes emitted to the current section. Common cases are 113 /// "\t.zero\t" and "\t.space\t". If this is set to null, the 114 /// Data*bitsDirective's will be used to emit zero bytes. 115 const char *ZeroDirective; // Defaults to "\t.zero\t" 116 117 /// AsciiDirective - This directive allows emission of an ascii string with 118 /// the standard C escape characters embedded into it. 119 const char *AsciiDirective; // Defaults to "\t.ascii\t" 120 121 /// AscizDirective - If not null, this allows for special handling of 122 /// zero terminated strings on this target. This is commonly supported as 123 /// ".asciz". If a target doesn't support this, it can be set to null. 124 const char *AscizDirective; // Defaults to "\t.asciz\t" 125 126 /// DataDirectives - These directives are used to output some unit of 127 /// integer data to the current section. If a data directive is set to 128 /// null, smaller data directives will be used to emit the large sizes. 129 const char *Data8bitsDirective; // Defaults to "\t.byte\t" 130 const char *Data16bitsDirective; // Defaults to "\t.short\t" 131 const char *Data32bitsDirective; // Defaults to "\t.long\t" 132 const char *Data64bitsDirective; // Defaults to "\t.quad\t" 133 134 /// GPRel32Directive - if non-null, a directive that is used to emit a word 135 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword 136 /// on Mips or .gprel32 on Alpha. 137 const char *GPRel32Directive; // Defaults to NULL. 138 139 /// getDataASDirective - Return the directive that should be used to emit 140 /// data of the specified size to the specified numeric address space. 141 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const { 142 assert(AS != 0 && "Don't know the directives for default addr space"); 143 return 0; 144 } 145 146 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun 147 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the 148 /// normal ELF syntax (,"a,w") in .section directives. 149 bool SunStyleELFSectionSwitchSyntax; // Defaults to false. 150 151 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF 152 /// '.section' directive before the '.bss' one. It's used for PPC/Linux 153 /// which doesn't support the '.bss' directive only. 154 bool UsesELFSectionDirectiveForBSS; // Defaults to false. 155 156 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft 157 /// style mangling for functions with X86_StdCall/X86_FastCall calling 158 /// convention. 159 bool HasMicrosoftFastStdCallMangling; // Defaults to false. 160 161 //===--- Alignment Information ----------------------------------------===// 162 163 /// AlignDirective - The directive used to emit round up to an alignment 164 /// boundary. 165 /// 166 const char *AlignDirective; // Defaults to "\t.align\t" 167 168 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter 169 /// emits ".align N" directives, where N is the number of bytes to align to. 170 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte 171 /// boundary. 172 bool AlignmentIsInBytes; // Defaults to true 173 174 /// TextAlignFillValue - If non-zero, this is used to fill the executable 175 /// space created as the result of a alignment directive. 176 unsigned TextAlignFillValue; // Defaults to 0 177 178 //===--- Global Variable Emission Directives --------------------------===// 179 180 /// GlobalDirective - This is the directive used to declare a global entity. 181 /// 182 const char *GlobalDirective; // Defaults to NULL. 183 184 /// ExternDirective - This is the directive used to declare external 185 /// globals. 186 /// 187 const char *ExternDirective; // Defaults to NULL. 188 189 /// HasSetDirective - True if the assembler supports the .set directive. 190 bool HasSetDirective; // Defaults to true. 191 192 /// HasLCOMMDirective - This is true if the target supports the .lcomm 193 /// directive. 194 bool HasLCOMMDirective; // Defaults to false. 195 196 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional 197 /// alignment is to be specified in bytes instead of log2(n). 198 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true; 199 200 /// HasDotTypeDotSizeDirective - True if the target has .type and .size 201 /// directives, this is true for most ELF targets. 202 bool HasDotTypeDotSizeDirective; // Defaults to true. 203 204 /// HasSingleParameterDotFile - True if the target has a single parameter 205 /// .file directive, this is true for ELF targets. 206 bool HasSingleParameterDotFile; // Defaults to true. 207 208 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip 209 /// directive. 210 bool HasNoDeadStrip; // Defaults to false. 211 212 /// WeakRefDirective - This directive, if non-null, is used to declare a 213 /// global as being a weak undefined symbol. 214 const char *WeakRefDirective; // Defaults to NULL. 215 216 /// WeakDefDirective - This directive, if non-null, is used to declare a 217 /// global as being a weak defined symbol. 218 const char *WeakDefDirective; // Defaults to NULL. 219 220 /// LinkOnceDirective - This directive, if non-null is used to declare a 221 /// global as being a weak defined symbol. This is used on cygwin/mingw. 222 const char *LinkOnceDirective; // Defaults to NULL. 223 224 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to 225 /// declare a symbol as having hidden visibility. 226 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden. 227 228 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used 229 /// to declare a symbol as having protected visibility. 230 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected 231 232 //===--- Dwarf Emission Directives -----------------------------------===// 233 234 /// HasLEB128 - True if target asm supports leb128 directives. 235 bool HasLEB128; // Defaults to false. 236 237 /// hasDotLocAndDotFile - True if target asm supports .loc and .file 238 /// directives for emitting debugging information. 239 bool HasDotLocAndDotFile; // Defaults to false. 240 241 /// SupportsDebugInformation - True if target supports emission of debugging 242 /// information. 243 bool SupportsDebugInformation; // Defaults to false. 244 245 /// SupportsExceptionHandling - True if target supports exception handling. 246 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None 247 248 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section 249 bool DwarfRequiresFrameSection; // Defaults to true. 250 251 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to 252 /// encode inline subroutine information. 253 bool DwarfUsesInlineInfoSection; // Defaults to false. 254 255 /// DwarfSectionOffsetDirective - Special section offset directive. 256 const char* DwarfSectionOffsetDirective; // Defaults to NULL 257 258 //===--- CBE Asm Translation Table -----------------------------------===// 259 260 const char *const *AsmTransCBE; // Defaults to empty 261 262 public: 263 explicit MCAsmInfo(); 264 virtual ~MCAsmInfo(); 265 266 // FIXME: move these methods to DwarfPrinter when the JIT stops using them. 267 static unsigned getSLEB128Size(int Value); 268 static unsigned getULEB128Size(unsigned Value); 269 270 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; } 271 272 // Data directive accessors. 273 // 274 const char *getData8bitsDirective(unsigned AS = 0) const { 275 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS); 276 } 277 const char *getData16bitsDirective(unsigned AS = 0) const { 278 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS); 279 } 280 const char *getData32bitsDirective(unsigned AS = 0) const { 281 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS); 282 } 283 const char *getData64bitsDirective(unsigned AS = 0) const { 284 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS); 285 } 286 const char *getGPRel32Directive() const { return GPRel32Directive; } 287 288 /// getNonexecutableStackSection - Targets can implement this method to 289 /// specify a section to switch to if the translation unit doesn't have any 290 /// trampolines that require an executable stack. 291 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{ 292 return 0; 293 } 294 295 bool usesSunStyleELFSectionSwitchSyntax() const { 296 return SunStyleELFSectionSwitchSyntax; 297 } 298 299 bool usesELFSectionDirectiveForBSS() const { 300 return UsesELFSectionDirectiveForBSS; 301 } 302 303 bool hasMicrosoftFastStdCallMangling() const { 304 return HasMicrosoftFastStdCallMangling; 305 } 306 307 // Accessors. 308 // 309 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; } 310 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; } 311 bool hasStaticCtorDtorReferenceInStaticMode() const { 312 return HasStaticCtorDtorReferenceInStaticMode; 313 } 314 unsigned getMaxInstLength() const { 315 return MaxInstLength; 316 } 317 const char *getPCSymbol() const { 318 return PCSymbol; 319 } 320 char getSeparatorChar() const { 321 return SeparatorChar; 322 } 323 unsigned getCommentColumn() const { 324 return CommentColumn; 325 } 326 const char *getCommentString() const { 327 return CommentString; 328 } 329 const char *getGlobalPrefix() const { 330 return GlobalPrefix; 331 } 332 const char *getPrivateGlobalPrefix() const { 333 return PrivateGlobalPrefix; 334 } 335 const char *getLinkerPrivateGlobalPrefix() const { 336 return LinkerPrivateGlobalPrefix; 337 } 338 const char *getInlineAsmStart() const { 339 return InlineAsmStart; 340 } 341 const char *getInlineAsmEnd() const { 342 return InlineAsmEnd; 343 } 344 unsigned getAssemblerDialect() const { 345 return AssemblerDialect; 346 } 347 bool doesAllowQuotesInName() const { 348 return AllowQuotesInName; 349 } 350 bool doesAllowNameToStartWithDigit() const { 351 return AllowNameToStartWithDigit; 352 } 353 bool doesAllowPeriodsInName() const { 354 return AllowPeriodsInName; 355 } 356 const char *getZeroDirective() const { 357 return ZeroDirective; 358 } 359 const char *getAsciiDirective() const { 360 return AsciiDirective; 361 } 362 const char *getAscizDirective() const { 363 return AscizDirective; 364 } 365 const char *getAlignDirective() const { 366 return AlignDirective; 367 } 368 bool getAlignmentIsInBytes() const { 369 return AlignmentIsInBytes; 370 } 371 unsigned getTextAlignFillValue() const { 372 return TextAlignFillValue; 373 } 374 const char *getGlobalDirective() const { 375 return GlobalDirective; 376 } 377 const char *getExternDirective() const { 378 return ExternDirective; 379 } 380 bool hasSetDirective() const { return HasSetDirective; } 381 bool hasLCOMMDirective() const { return HasLCOMMDirective; } 382 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;} 383 bool getCOMMDirectiveAlignmentIsInBytes() const { 384 return COMMDirectiveAlignmentIsInBytes; 385 } 386 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; } 387 bool hasNoDeadStrip() const { return HasNoDeadStrip; } 388 const char *getWeakRefDirective() const { return WeakRefDirective; } 389 const char *getWeakDefDirective() const { return WeakDefDirective; } 390 const char *getLinkOnceDirective() const { return LinkOnceDirective; } 391 392 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;} 393 MCSymbolAttr getProtectedVisibilityAttr() const { 394 return ProtectedVisibilityAttr; 395 } 396 bool hasLEB128() const { 397 return HasLEB128; 398 } 399 bool hasDotLocAndDotFile() const { 400 return HasDotLocAndDotFile; 401 } 402 bool doesSupportDebugInformation() const { 403 return SupportsDebugInformation; 404 } 405 bool doesSupportExceptionHandling() const { 406 return ExceptionsType != ExceptionHandling::None; 407 } 408 ExceptionHandling::ExceptionsType getExceptionHandlingType() const { 409 return ExceptionsType; 410 } 411 bool doesDwarfRequireFrameSection() const { 412 return DwarfRequiresFrameSection; 413 } 414 bool doesDwarfUsesInlineInfoSection() const { 415 return DwarfUsesInlineInfoSection; 416 } 417 const char *getDwarfSectionOffsetDirective() const { 418 return DwarfSectionOffsetDirective; 419 } 420 const char *const *getAsmCBE() const { 421 return AsmTransCBE; 422 } 423 }; 424} 425 426#endif 427