MCAsmInfo.h revision 814819f6ea7fb0638fe73920299fda0da941a59e
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 const char *ZeroDirectiveSuffix; // Defaults to "" 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 /// UsedDirective - This directive, if non-null, is used to declare a global 214 /// as being used somehow that the assembler can't see. This prevents dead 215 /// code elimination on some targets. 216 const char *UsedDirective; // Defaults to NULL. 217 218 /// WeakRefDirective - This directive, if non-null, is used to declare a 219 /// global as being a weak undefined symbol. 220 const char *WeakRefDirective; // Defaults to NULL. 221 222 /// WeakDefDirective - This directive, if non-null, is used to declare a 223 /// global as being a weak defined symbol. 224 const char *WeakDefDirective; // Defaults to NULL. 225 226 /// LinkOnceDirective - This directive, if non-null is used to declare a 227 /// global as being a weak defined symbol. This is used on cygwin/mingw. 228 const char *LinkOnceDirective; // Defaults to NULL. 229 230 /// HiddenDirective - This directive, if non-null, is used to declare a 231 /// global or function as having hidden visibility. 232 const char *HiddenDirective; // Defaults to "\t.hidden\t". 233 234 /// ProtectedDirective - This directive, if non-null, is used to declare a 235 /// global or function as having protected visibility. 236 const char *ProtectedDirective; // Defaults to "\t.protected\t". 237 238 //===--- Dwarf Emission Directives -----------------------------------===// 239 240 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section 241 /// offsets for debug information. 242 bool AbsoluteDebugSectionOffsets; // Defaults to false. 243 244 /// AbsoluteEHSectionOffsets - True if we should emit abolute section 245 /// offsets for EH information. Defaults to false. 246 bool AbsoluteEHSectionOffsets; 247 248 /// HasLEB128 - True if target asm supports leb128 directives. 249 bool HasLEB128; // Defaults to false. 250 251 /// hasDotLocAndDotFile - True if target asm supports .loc and .file 252 /// directives for emitting debugging information. 253 bool HasDotLocAndDotFile; // Defaults to false. 254 255 /// SupportsDebugInformation - True if target supports emission of debugging 256 /// information. 257 bool SupportsDebugInformation; // Defaults to false. 258 259 /// SupportsExceptionHandling - True if target supports exception handling. 260 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None 261 262 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section 263 bool DwarfRequiresFrameSection; // Defaults to true. 264 265 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to 266 /// encode inline subroutine information. 267 bool DwarfUsesInlineInfoSection; // Defaults to false. 268 269 /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it 270 /// doesn't show up in the symbol table of the object file. 271 bool Is_EHSymbolPrivate; // Defaults to true. 272 273 /// GlobalEHDirective - This is the directive used to make exception frame 274 /// tables globally visible. 275 const char *GlobalEHDirective; // Defaults to NULL. 276 277 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will 278 /// handle a weak_definition of constant 0 for an omitted EH frame. 279 bool SupportsWeakOmittedEHFrame; // Defaults to true. 280 281 /// DwarfSectionOffsetDirective - Special section offset directive. 282 const char* DwarfSectionOffsetDirective; // Defaults to NULL 283 284 //===--- CBE Asm Translation Table -----------------------------------===// 285 286 const char *const *AsmTransCBE; // Defaults to empty 287 288 public: 289 explicit MCAsmInfo(); 290 virtual ~MCAsmInfo(); 291 292 /// getSLEB128Size - Compute the number of bytes required for a signed 293 /// leb128 value. 294 static unsigned getSLEB128Size(int Value); 295 296 /// getULEB128Size - Compute the number of bytes required for an unsigned 297 /// leb128 value. 298 static unsigned getULEB128Size(unsigned Value); 299 300 // Data directive accessors. 301 // 302 const char *getData8bitsDirective(unsigned AS = 0) const { 303 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS); 304 } 305 const char *getData16bitsDirective(unsigned AS = 0) const { 306 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS); 307 } 308 const char *getData32bitsDirective(unsigned AS = 0) const { 309 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS); 310 } 311 const char *getData64bitsDirective(unsigned AS = 0) const { 312 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS); 313 } 314 315 316 bool usesSunStyleELFSectionSwitchSyntax() const { 317 return SunStyleELFSectionSwitchSyntax; 318 } 319 320 bool usesELFSectionDirectiveForBSS() const { 321 return UsesELFSectionDirectiveForBSS; 322 } 323 324 // Accessors. 325 // 326 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; } 327 bool hasStaticCtorDtorReferenceInStaticMode() const { 328 return HasStaticCtorDtorReferenceInStaticMode; 329 } 330 const char *getNonexecutableStackDirective() const { 331 return NonexecutableStackDirective; 332 } 333 bool needsSet() const { 334 return NeedsSet; 335 } 336 unsigned getMaxInstLength() const { 337 return MaxInstLength; 338 } 339 const char *getPCSymbol() const { 340 return PCSymbol; 341 } 342 char getSeparatorChar() const { 343 return SeparatorChar; 344 } 345 unsigned getCommentColumn() const { 346 return CommentColumn; 347 } 348 const char *getCommentString() const { 349 return CommentString; 350 } 351 const char *getGlobalPrefix() const { 352 return GlobalPrefix; 353 } 354 const char *getPrivateGlobalPrefix() const { 355 return PrivateGlobalPrefix; 356 } 357 const char *getLinkerPrivateGlobalPrefix() const { 358 return LinkerPrivateGlobalPrefix; 359 } 360 const char *getInlineAsmStart() const { 361 return InlineAsmStart; 362 } 363 const char *getInlineAsmEnd() const { 364 return InlineAsmEnd; 365 } 366 unsigned getAssemblerDialect() const { 367 return AssemblerDialect; 368 } 369 bool doesAllowQuotesInName() const { 370 return AllowQuotesInName; 371 } 372 bool doesAllowNameToStartWithDigit() const { 373 return AllowNameToStartWithDigit; 374 } 375 const char *getZeroDirective() const { 376 return ZeroDirective; 377 } 378 const char *getZeroDirectiveSuffix() const { 379 return ZeroDirectiveSuffix; 380 } 381 const char *getAsciiDirective() const { 382 return AsciiDirective; 383 } 384 const char *getAscizDirective() const { 385 return AscizDirective; 386 } 387 const char *getJumpTableDirective(bool isPIC) const { 388 return isPIC ? PICJumpTableDirective : JumpTableDirective; 389 } 390 const char *getAlignDirective() const { 391 return AlignDirective; 392 } 393 bool getAlignmentIsInBytes() const { 394 return AlignmentIsInBytes; 395 } 396 unsigned getTextAlignFillValue() const { 397 return TextAlignFillValue; 398 } 399 const char *getGlobalDirective() const { 400 return GlobalDirective; 401 } 402 const char *getExternDirective() const { 403 return ExternDirective; 404 } 405 const char *getSetDirective() const { 406 return SetDirective; 407 } 408 const char *getLCOMMDirective() const { 409 return LCOMMDirective; 410 } 411 const char *getCOMMDirective() const { 412 return COMMDirective; 413 } 414 bool getCOMMDirectiveTakesAlignment() const { 415 return COMMDirectiveTakesAlignment; 416 } 417 bool hasDotTypeDotSizeDirective() const { 418 return HasDotTypeDotSizeDirective; 419 } 420 bool hasSingleParameterDotFile() const { 421 return HasSingleParameterDotFile; 422 } 423 const char *getUsedDirective() const { 424 return UsedDirective; 425 } 426 const char *getWeakRefDirective() const { return WeakRefDirective; } 427 const char *getWeakDefDirective() const { return WeakDefDirective; } 428 const char *getLinkOnceDirective() const { return LinkOnceDirective; } 429 const char *getHiddenDirective() const { 430 return HiddenDirective; 431 } 432 const char *getProtectedDirective() const { 433 return ProtectedDirective; 434 } 435 bool isAbsoluteDebugSectionOffsets() const { 436 return AbsoluteDebugSectionOffsets; 437 } 438 bool isAbsoluteEHSectionOffsets() const { 439 return AbsoluteEHSectionOffsets; 440 } 441 bool hasLEB128() const { 442 return HasLEB128; 443 } 444 bool hasDotLocAndDotFile() const { 445 return HasDotLocAndDotFile; 446 } 447 bool doesSupportDebugInformation() const { 448 return SupportsDebugInformation; 449 } 450 bool doesSupportExceptionHandling() const { 451 return ExceptionsType != ExceptionHandling::None; 452 } 453 ExceptionHandling::ExceptionsType getExceptionHandlingType() const { 454 return ExceptionsType; 455 } 456 bool doesDwarfRequireFrameSection() const { 457 return DwarfRequiresFrameSection; 458 } 459 bool doesDwarfUsesInlineInfoSection() const { 460 return DwarfUsesInlineInfoSection; 461 } 462 bool is_EHSymbolPrivate() const { 463 return Is_EHSymbolPrivate; 464 } 465 const char *getGlobalEHDirective() const { 466 return GlobalEHDirective; 467 } 468 bool getSupportsWeakOmittedEHFrame() const { 469 return SupportsWeakOmittedEHFrame; 470 } 471 const char *getDwarfSectionOffsetDirective() const { 472 return DwarfSectionOffsetDirective; 473 } 474 const char *const *getAsmCBE() const { 475 return AsmTransCBE; 476 } 477 }; 478} 479 480#endif 481