LLVM  3.7.0
MCAsmInfo.cpp
Go to the documentation of this file.
1 //===-- MCAsmInfo.cpp - Asm Info -------------------------------------------==//
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 defines target asm properties related what form asm statements
11 // should take.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/Dwarf.h"
21 #include <cctype>
22 #include <cstring>
23 using namespace llvm;
24 
26  PointerSize = 4;
28 
29  IsLittleEndian = true;
30  StackGrowsUp = false;
33  HasMachoTBSSDirective = false;
35  MaxInstLength = 4;
36  MinInstAlignment = 1;
37  DollarIsPC = false;
38  SeparatorString = ";";
39  CommentString = "#";
40  LabelSuffix = ":";
42  NeedsLocalForSize = false;
43  PrivateGlobalPrefix = "L";
46  InlineAsmStart = "APP";
47  InlineAsmEnd = "NO_APP";
48  Code16Directive = ".code16";
49  Code32Directive = ".code32";
50  Code64Directive = ".code64";
51  AssemblerDialect = 0;
52  AllowAtInName = false;
53  SupportsQuotedNames = true;
55  ZeroDirective = "\t.zero\t";
56  AsciiDirective = "\t.ascii\t";
57  AscizDirective = "\t.asciz\t";
58  Data8bitsDirective = "\t.byte\t";
59  Data16bitsDirective = "\t.short\t";
60  Data32bitsDirective = "\t.long\t";
61  Data64bitsDirective = "\t.quad\t";
64  AlignmentIsInBytes = true;
66  GPRel64Directive = nullptr;
67  GPRel32Directive = nullptr;
68  GlobalDirective = "\t.globl\t";
73  HasFunctionAlignment = true;
76  HasIdentDirective = false;
77  HasNoDeadStrip = false;
78  WeakDirective = "\t.weak\t";
79  WeakRefDirective = nullptr;
80  HasWeakDefDirective = false;
82  HasLinkOnceDirective = false;
91  DwarfRegNumForCFI = false;
94  UseLogicalShr = true;
95 
96  // FIXME: Clang's logic should be synced with the logic used to initialize
97  // this member and the two implementations should be merged.
98  // For reference:
99  // - Solaris always enables the integrated assembler by default
100  // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
101  // - Windows always enables the integrated assembler by default
102  // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
103  // - MachO targets always enables the integrated assembler by default
104  // - MCAsmInfoDarwin is handling this case
105  // - Generic_GCC toolchains enable the integrated assembler on a per
106  // architecture basis.
107  // - The target subclasses for AArch64, ARM, and X86 handle these cases
108  UseIntegratedAssembler = false;
109 
110  CompressDebugSections = false;
111 }
112 
114 }
115 
117  return false;
118 }
119 
120 const MCExpr *
122  unsigned Encoding,
123  MCStreamer &Streamer) const {
124  return getExprForFDESymbol(Sym, Encoding, Streamer);
125 }
126 
127 const MCExpr *
129  unsigned Encoding,
130  MCStreamer &Streamer) const {
131  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
132  return MCSymbolRefExpr::create(Sym, Streamer.getContext());
133 
134  MCContext &Context = Streamer.getContext();
135  const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
136  MCSymbol *PCSym = Context.createTempSymbol();
137  Streamer.EmitLabel(PCSym);
138  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
139  return MCBinaryExpr::createSub(Res, PC, Context);
140 }
141 
142 static bool isAcceptableChar(char C) {
143  return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
144  (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
145 }
146 
148  if (Name.empty())
149  return false;
150 
151  // If any of the characters in the string is an unacceptable character, force
152  // quotes.
153  for (char C : Name) {
154  if (!isAcceptableChar(C))
155  return false;
156  }
157 
158  return true;
159 }
bool HasSingleParameterDotFile
True if the target has a single parameter .file directive, this is true for ELF targets.
Definition: MCAsmInfo.h:273
const char * Code16Directive
These are assembly directives that tells the assembler to interpret the following instructions differ...
Definition: MCAsmInfo.h:147
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:147
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition: MCAsmInfo.h:261
unsigned TextAlignFillValue
If non-zero, this is used to fill the executable space created as the result of a alignment directive...
Definition: MCAsmInfo.h:225
bool HasSubsectionsViaSymbols
True if this target has the MachO .subsections_via_symbols directive.
Definition: MCAsmInfo.h:79
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:353
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:284
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:315
bool DwarfRegNumForCFI
True if dwarf register numbers are printed instead of symbolic register names in .cfi_* directives.
Definition: MCAsmInfo.h:336
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
bool DwarfUsesRelocationsAcrossSections
True if Dwarf2 output generally uses relocations for references to other .debug_* sections...
Definition: MCAsmInfo.h:328
const char * Data64bitsDirective
Definition: MCAsmInfo.h:191
const char * ZeroDirective
This should be set to the directive used to get some number of zero bytes emitted to the current sect...
Definition: MCAsmInfo.h:173
bool SupportsQuotedNames
If this is true, symbol names with invalid characters will be printed in quotes.
Definition: MCAsmInfo.h:160
bool IsLittleEndian
True if target is little endian. Default is true.
Definition: MCAsmInfo.h:72
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:231
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition: MCAsmInfo.h:69
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition: MCAsmInfo.h:152
bool HasWeakDefCanBeHiddenDirective
True if we have a directive to declare a global as being a weak defined symbol that can be hidden (un...
Definition: MCAsmInfo.h:296
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:116
bool HasDotTypeDotSizeDirective
True if the target has .type and .size directives, this is true for most ELF targets.
Definition: MCAsmInfo.h:269
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:177
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition: MCAsmInfo.h:221
const char * PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ...
Definition: MCAsmInfo.h:127
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line...
Definition: MCAsmInfo.h:109
bool HasNoDeadStrip
True if this target supports the MachO .no_dead_strip directive.
Definition: MCAsmInfo.h:281
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:121
bool UseLogicalShr
True if the integrated assembler should interpret 'a >> b' constant expressions as logical rather t...
Definition: MCAsmInfo.h:360
bool UsesELFSectionDirectiveForBSS
This is true if this target uses ELF '.section' directive before the '.bss' one.
Definition: MCAsmInfo.h:211
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:188
bool HasAggressiveSymbolFolding
False if the assembler requires that we use.
Definition: MCAsmInfo.h:253
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
bool StackGrowsUp
True if target stack grow up. Default is false.
Definition: MCAsmInfo.h:75
MCContext & getContext() const
Definition: MCStreamer.h:210
Context object for machine code objects.
Definition: MCContext.h:48
bool SunStyleELFSectionSwitchSyntax
This is true if this target uses "Sun Style" syntax for section switching ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in .section directives.
Definition: MCAsmInfo.h:206
bool HasFunctionAlignment
Definition: MCAsmInfo.h:265
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:514
MCSymbolAttr HiddenVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having hidden visibility...
Definition: MCAsmInfo.h:304
const char * Code32Directive
Definition: MCAsmInfo.h:148
bool HasLinkOnceDirective
True if we have a .linkonce directive.
Definition: MCAsmInfo.h:300
const char * CommentString
This indicates the comment character used by the assembler.
Definition: MCAsmInfo.h:113
.protected (ELF)
Definition: MCDirectives.h:39
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:182
bool DollarIsPC
The '$' token, when not referencing an identifier or constant, refers to the current PC...
Definition: MCAsmInfo.h:105
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition: MCAsmInfo.h:141
.hidden (ELF)
Definition: MCDirectives.h:31
bool HasIdentDirective
True if the target has a .ident directive, this is true for ELF targets.
Definition: MCAsmInfo.h:277
Streaming machine code generation interface.
Definition: MCStreamer.h:157
const char * GPRel64Directive
If non-null, a directive that is used to emit a word which should be relocated as a 64-bit GP-relativ...
Definition: MCAsmInfo.h:196
bool COMMDirectiveAlignmentIsInBytes
True is .comm's and .lcomms optional alignment is to be specified in bytes instead of log2(n)...
Definition: MCAsmInfo.h:257
unsigned PointerSize
Pointer size in bytes. Default is 4.
Definition: MCAsmInfo.h:65
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition: MCAsmInfo.h:156
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition: MCAsmInfo.h:318
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition: MCAsmInfo.h:324
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol...
Definition: MCAsmInfo.h:288
const char * Data16bitsDirective
Definition: MCAsmInfo.h:189
bool UseAssignmentForEHBegin
Definition: MCAsmInfo.h:119
bool HasWeakDefDirective
True if we have a directive to declare a global as being a weak defined symbol.
Definition: MCAsmInfo.h:292
bool NeedsLocalForSize
Definition: MCAsmInfo.h:122
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:203
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:116
bool HasMachoZeroFillDirective
True if this is a MachO target that supports the macho-specific .zerofill directive for emitting BSS ...
Definition: MCAsmInfo.h:83
bool HasStaticCtorDtorReferenceInStaticMode
True if the compiler should emit a ".reference .constructors_used" or ".reference ...
Definition: MCAsmInfo.h:93
virtual ~MCAsmInfo()
Definition: MCAsmInfo.cpp:113
const char * InlineAsmEnd
Definition: MCAsmInfo.h:142
bool DwarfFDESymbolsUseAbsDiff
True if DWARF FDE symbol reference relocations should be replaced by an absolute difference.
Definition: MCAsmInfo.h:332
bool HasMachoTBSSDirective
True if this is a MachO target that supports the macho-specific .tbss directive for emitting thread l...
Definition: MCAsmInfo.h:87
unsigned MinInstAlignment
Every possible instruction length is a multiple of this value.
Definition: MCAsmInfo.h:101
const char * Data32bitsDirective
Definition: MCAsmInfo.h:190
const char * GPRel32Directive
If non-null, a directive that is used to emit a word which should be relocated as a 32-bit GP-relativ...
Definition: MCAsmInfo.h:201
MCSymbolAttr ProtectedVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare a symbol as having protected visibility...
Definition: MCAsmInfo.h:312
bool SetDirectiveSuppressesReloc
True if the expression .long f - g uses a relocation but it can be suppressed by writing a = f - g ...
Definition: MCAsmInfo.h:238
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition: MCAsmInfo.h:321
bool UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives...
Definition: MCAsmInfo.h:165
static bool isAcceptableChar(char C)
Definition: MCAsmInfo.cpp:142
bool NeedsDwarfSectionOffsetDirective
Definition: MCAsmInfo.h:213
MCSymbolAttr HiddenDeclarationVisibilityAttr
This attribute, if not MCSA_Invalid, is used to declare an undefined symbol as having hidden visibili...
Definition: MCAsmInfo.h:308
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
bool CompressDebugSections
Compress DWARF debug sections. Defaults to false.
Definition: MCAsmInfo.h:356
const char * PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:131
const char * LinkerPrivateGlobalPrefix
This prefix is used for symbols that should be passed through the assembler but be removed by the lin...
Definition: MCAsmInfo.h:137
const char * Code64Directive
Definition: MCAsmInfo.h:149
unsigned MaxInstLength
This is the maximum possible length of an instruction, which is needed to compute the size of an inli...
Definition: MCAsmInfo.h:97
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
bool UseParensForSymbolVariant
True if target uses parens to indicate the symbol variant instead of
Definition: MCAsmInfo.h:340