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