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