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