1 //===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
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 }; }
28 //===------------------------------------------------------------------===//
29 // Properties to be set by the target writer, used to configure asm printer.
32 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
33 /// section on this target. Null if this target doesn't support zerofill.
34 const char *ZeroFillDirective; // Default is null.
36 /// NonexecutableStackDirective - Directive for declaring to the
37 /// linker and beyond that the emitted code does not require stack
38 /// memory to be executable.
39 const char *NonexecutableStackDirective; // Default is null.
41 /// NeedsSet - True if target asm treats expressions in data directives
42 /// as linktime-relocatable. For assembly-time computation, we need to
46 /// is computed at assembly time, while
48 /// is relocated if the relative locations of x and y change at linktime.
49 /// We want both these things in different places.
50 bool NeedsSet; // Defaults to false.
52 /// MaxInstLength - This is the maximum possible length of an instruction,
53 /// which is needed to compute the size of an inline asm.
54 unsigned MaxInstLength; // Defaults to 4.
56 /// PCSymbol - The symbol used to represent the current PC. Used in PC
57 /// relative expressions.
58 const char *PCSymbol; // Defaults to "$".
60 /// SeparatorChar - This character, if specified, is used to separate
61 /// instructions from each other when on the same line. This is used to
62 /// measure inline asm instructions.
63 char SeparatorChar; // Defaults to ';'
65 /// CommentColumn - This indicates the comment num (zero-based) at
66 /// which asm comments should be printed.
67 unsigned CommentColumn; // Defaults to 60
69 /// CommentString - This indicates the comment character used by the
71 const char *CommentString; // Defaults to "#"
73 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
74 /// onto all global symbols. This is often used for "_" or ".".
75 const char *GlobalPrefix; // Defaults to ""
77 /// PrivateGlobalPrefix - This prefix is used for globals like constant
78 /// pool entries that are completely private to the .s file and should not
79 /// have names in the .o file. This is often "." or "L".
80 const char *PrivateGlobalPrefix; // Defaults to "."
82 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
83 /// be passed through the assembler but be removed by the linker. This
84 /// is "l" on Darwin, currently used for some ObjC metadata.
85 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
87 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
88 /// emit before and after an inline assembly statement.
89 const char *InlineAsmStart; // Defaults to "#APP\n"
90 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
92 /// AssemblerDialect - Which dialect of an assembler variant to use.
93 unsigned AssemblerDialect; // Defaults to 0
95 /// AllowQuotesInName - This is true if the assembler allows for complex
96 /// symbol names to be surrounded in quotes. This defaults to false.
97 bool AllowQuotesInName;
99 //===--- Data Emission Directives -------------------------------------===//
101 /// ZeroDirective - this should be set to the directive used to get some
102 /// number of zero bytes emitted to the current section. Common cases are
103 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
104 /// Data*bitsDirective's will be used to emit zero bytes.
105 const char *ZeroDirective; // Defaults to "\t.zero\t"
106 const char *ZeroDirectiveSuffix; // Defaults to ""
108 /// AsciiDirective - This directive allows emission of an ascii string with
109 /// the standard C escape characters embedded into it.
110 const char *AsciiDirective; // Defaults to "\t.ascii\t"
112 /// AscizDirective - If not null, this allows for special handling of
113 /// zero terminated strings on this target. This is commonly supported as
114 /// ".asciz". If a target doesn't support this, it can be set to null.
115 const char *AscizDirective; // Defaults to "\t.asciz\t"
117 /// DataDirectives - These directives are used to output some unit of
118 /// integer data to the current section. If a data directive is set to
119 /// null, smaller data directives will be used to emit the large sizes.
120 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
121 const char *Data16bitsDirective; // Defaults to "\t.short\t"
122 const char *Data32bitsDirective; // Defaults to "\t.long\t"
123 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
125 /// getDataASDirective - Return the directive that should be used to emit
126 /// data of the specified size to the specified numeric address space.
127 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
128 assert(AS != 0 && "Don't know the directives for default addr space");
132 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
133 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
134 /// normal ELF syntax (,"a,w") in .section directives.
135 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
137 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
138 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
139 /// which doesn't support the '.bss' directive only.
140 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
142 //===--- Alignment Information ----------------------------------------===//
144 /// AlignDirective - The directive used to emit round up to an alignment
147 const char *AlignDirective; // Defaults to "\t.align\t"
149 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
150 /// emits ".align N" directives, where N is the number of bytes to align to.
151 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
153 bool AlignmentIsInBytes; // Defaults to true
155 /// TextAlignFillValue - If non-zero, this is used to fill the executable
156 /// space created as the result of a alignment directive.
157 unsigned TextAlignFillValue; // Defaults to 0
159 //===--- Section Switching Directives ---------------------------------===//
161 /// JumpTableDirective - if non-null, the directive to emit before jump
162 /// table entries. FIXME: REMOVE THIS.
163 const char *JumpTableDirective; // Defaults to NULL.
164 const char *PICJumpTableDirective; // Defaults to NULL.
167 //===--- Global Variable Emission Directives --------------------------===//
169 /// GlobalDirective - This is the directive used to declare a global entity.
171 const char *GlobalDirective; // Defaults to NULL.
173 /// ExternDirective - This is the directive used to declare external
176 const char *ExternDirective; // Defaults to NULL.
178 /// SetDirective - This is the name of a directive that can be used to tell
179 /// the assembler to set the value of a variable to some expression.
180 const char *SetDirective; // Defaults to null.
182 /// LCOMMDirective - This is the name of a directive (if supported) that can
183 /// be used to efficiently declare a local (internal) block of zero
184 /// initialized data in the .bss/.data section. The syntax expected is:
185 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
187 const char *LCOMMDirective; // Defaults to null.
189 const char *COMMDirective; // Defaults to "\t.comm\t".
191 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
192 /// argument that specifies the alignment of the declaration.
193 bool COMMDirectiveTakesAlignment; // Defaults to true.
195 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
196 /// directives, this is true for most ELF targets.
197 bool HasDotTypeDotSizeDirective; // Defaults to true.
199 /// HasSingleParameterDotFile - True if the target has a single parameter
200 /// .file directive, this is true for ELF targets.
201 bool HasSingleParameterDotFile; // Defaults to true.
203 /// UsedDirective - This directive, if non-null, is used to declare a global
204 /// as being used somehow that the assembler can't see. This prevents dead
205 /// code elimination on some targets.
206 const char *UsedDirective; // Defaults to NULL.
208 /// WeakRefDirective - This directive, if non-null, is used to declare a
209 /// global as being a weak undefined symbol.
210 const char *WeakRefDirective; // Defaults to NULL.
212 /// WeakDefDirective - This directive, if non-null, is used to declare a
213 /// global as being a weak defined symbol.
214 const char *WeakDefDirective; // Defaults to NULL.
216 /// HiddenDirective - This directive, if non-null, is used to declare a
217 /// global or function as having hidden visibility.
218 const char *HiddenDirective; // Defaults to "\t.hidden\t".
220 /// ProtectedDirective - This directive, if non-null, is used to declare a
221 /// global or function as having protected visibility.
222 const char *ProtectedDirective; // Defaults to "\t.protected\t".
224 //===--- Dwarf Emission Directives -----------------------------------===//
226 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
227 /// offsets for debug information.
228 bool AbsoluteDebugSectionOffsets; // Defaults to false.
230 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
231 /// offsets for EH information. Defaults to false.
232 bool AbsoluteEHSectionOffsets;
234 /// HasLEB128 - True if target asm supports leb128 directives.
235 bool HasLEB128; // Defaults to false.
237 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
238 /// directives for emitting debugging information.
239 bool HasDotLocAndDotFile; // Defaults to false.
241 /// SupportsDebugInformation - True if target supports emission of debugging
243 bool SupportsDebugInformation; // Defaults to false.
245 /// SupportsExceptionHandling - True if target supports exception handling.
246 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
248 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
249 bool DwarfRequiresFrameSection; // Defaults to true.
251 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
252 /// encode inline subroutine information.
253 bool DwarfUsesInlineInfoSection; // Defaults to false.
255 /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
256 /// doesn't show up in the symbol table of the object file.
257 bool Is_EHSymbolPrivate; // Defaults to true.
259 /// GlobalEHDirective - This is the directive used to make exception frame
260 /// tables globally visible.
261 const char *GlobalEHDirective; // Defaults to NULL.
263 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
264 /// handle a weak_definition of constant 0 for an omitted EH frame.
265 bool SupportsWeakOmittedEHFrame; // Defaults to true.
267 /// DwarfSectionOffsetDirective - Special section offset directive.
268 const char* DwarfSectionOffsetDirective; // Defaults to NULL
270 //===--- CBE Asm Translation Table -----------------------------------===//
272 const char *const *AsmTransCBE; // Defaults to empty
275 explicit MCAsmInfo();
276 virtual ~MCAsmInfo();
278 /// getSLEB128Size - Compute the number of bytes required for a signed
280 static unsigned getSLEB128Size(int Value);
282 /// getULEB128Size - Compute the number of bytes required for an unsigned
284 static unsigned getULEB128Size(unsigned Value);
286 // Data directive accessors.
288 const char *getData8bitsDirective(unsigned AS = 0) const {
289 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
291 const char *getData16bitsDirective(unsigned AS = 0) const {
292 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
294 const char *getData32bitsDirective(unsigned AS = 0) const {
295 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
297 const char *getData64bitsDirective(unsigned AS = 0) const {
298 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
302 bool usesSunStyleELFSectionSwitchSyntax() const {
303 return SunStyleELFSectionSwitchSyntax;
306 bool usesELFSectionDirectiveForBSS() const {
307 return UsesELFSectionDirectiveForBSS;
312 const char *getZeroFillDirective() const {
313 return ZeroFillDirective;
315 const char *getNonexecutableStackDirective() const {
316 return NonexecutableStackDirective;
318 bool needsSet() const {
321 unsigned getMaxInstLength() const {
322 return MaxInstLength;
324 const char *getPCSymbol() const {
327 char getSeparatorChar() const {
328 return SeparatorChar;
330 unsigned getCommentColumn() const {
331 return CommentColumn;
333 const char *getCommentString() const {
334 return CommentString;
336 const char *getGlobalPrefix() const {
339 const char *getPrivateGlobalPrefix() const {
340 return PrivateGlobalPrefix;
342 const char *getLinkerPrivateGlobalPrefix() const {
343 return LinkerPrivateGlobalPrefix;
345 const char *getInlineAsmStart() const {
346 return InlineAsmStart;
348 const char *getInlineAsmEnd() const {
351 unsigned getAssemblerDialect() const {
352 return AssemblerDialect;
354 bool doesAllowQuotesInName() const {
355 return AllowQuotesInName;
357 const char *getZeroDirective() const {
358 return ZeroDirective;
360 const char *getZeroDirectiveSuffix() const {
361 return ZeroDirectiveSuffix;
363 const char *getAsciiDirective() const {
364 return AsciiDirective;
366 const char *getAscizDirective() const {
367 return AscizDirective;
369 const char *getJumpTableDirective(bool isPIC) const {
370 return isPIC ? PICJumpTableDirective : JumpTableDirective;
372 const char *getAlignDirective() const {
373 return AlignDirective;
375 bool getAlignmentIsInBytes() const {
376 return AlignmentIsInBytes;
378 unsigned getTextAlignFillValue() const {
379 return TextAlignFillValue;
381 const char *getGlobalDirective() const {
382 return GlobalDirective;
384 const char *getExternDirective() const {
385 return ExternDirective;
387 const char *getSetDirective() const {
390 const char *getLCOMMDirective() const {
391 return LCOMMDirective;
393 const char *getCOMMDirective() const {
394 return COMMDirective;
396 bool getCOMMDirectiveTakesAlignment() const {
397 return COMMDirectiveTakesAlignment;
399 bool hasDotTypeDotSizeDirective() const {
400 return HasDotTypeDotSizeDirective;
402 bool hasSingleParameterDotFile() const {
403 return HasSingleParameterDotFile;
405 const char *getUsedDirective() const {
406 return UsedDirective;
408 const char *getWeakRefDirective() const {
409 return WeakRefDirective;
411 const char *getWeakDefDirective() const {
412 return WeakDefDirective;
414 const char *getHiddenDirective() const {
415 return HiddenDirective;
417 const char *getProtectedDirective() const {
418 return ProtectedDirective;
420 bool isAbsoluteDebugSectionOffsets() const {
421 return AbsoluteDebugSectionOffsets;
423 bool isAbsoluteEHSectionOffsets() const {
424 return AbsoluteEHSectionOffsets;
426 bool hasLEB128() const {
429 bool hasDotLocAndDotFile() const {
430 return HasDotLocAndDotFile;
432 bool doesSupportDebugInformation() const {
433 return SupportsDebugInformation;
435 bool doesSupportExceptionHandling() const {
436 return ExceptionsType != ExceptionHandling::None;
438 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
439 return ExceptionsType;
441 bool doesDwarfRequireFrameSection() const {
442 return DwarfRequiresFrameSection;
444 bool doesDwarfUsesInlineInfoSection() const {
445 return DwarfUsesInlineInfoSection;
447 bool is_EHSymbolPrivate() const {
448 return Is_EHSymbolPrivate;
450 const char *getGlobalEHDirective() const {
451 return GlobalEHDirective;
453 bool getSupportsWeakOmittedEHFrame() const {
454 return SupportsWeakOmittedEHFrame;
456 const char *getDwarfSectionOffsetDirective() const {
457 return DwarfSectionOffsetDirective;
459 const char *const *getAsmCBE() const {