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>
23using namespace llvm;
24
25MCAsmInfo::MCAsmInfo() {
26  PointerSize = 4;
27  CalleeSaveStackSlotSize = 4;
28
29  IsLittleEndian = true;
30  StackGrowsUp = false;
31  HasSubsectionsViaSymbols = false;
32  HasMachoZeroFillDirective = false;
33  HasMachoTBSSDirective = false;
34  HasStaticCtorDtorReferenceInStaticMode = false;
35  MaxInstLength = 4;
36  MinInstAlignment = 1;
37  DollarIsPC = false;
38  SeparatorString = ";";
39  CommentString = "#";
40  LabelSuffix = ":";
41  UseAssignmentForEHBegin = false;
42  NeedsLocalForSize = false;
43  PrivateGlobalPrefix = "L";
44  PrivateLabelPrefix = PrivateGlobalPrefix;
45  LinkerPrivateGlobalPrefix = "";
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;
54  UseDataRegionDirectives = false;
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";
62  SunStyleELFSectionSwitchSyntax = false;
63  UsesELFSectionDirectiveForBSS = false;
64  AlignmentIsInBytes = true;
65  TextAlignFillValue = 0;
66  GPRel64Directive = nullptr;
67  GPRel32Directive = nullptr;
68  GlobalDirective = "\t.globl\t";
69  SetDirectiveSuppressesReloc = false;
70  HasAggressiveSymbolFolding = true;
71  COMMDirectiveAlignmentIsInBytes = true;
72  LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
73  HasFunctionAlignment = true;
74  HasDotTypeDotSizeDirective = true;
75  HasSingleParameterDotFile = true;
76  HasIdentDirective = false;
77  HasNoDeadStrip = false;
78  HasAltEntry = false;
79  WeakDirective = "\t.weak\t";
80  WeakRefDirective = nullptr;
81  HasWeakDefDirective = false;
82  HasWeakDefCanBeHiddenDirective = false;
83  HasLinkOnceDirective = false;
84  HiddenVisibilityAttr = MCSA_Hidden;
85  HiddenDeclarationVisibilityAttr = MCSA_Hidden;
86  ProtectedVisibilityAttr = MCSA_Protected;
87  SupportsDebugInformation = false;
88  ExceptionsType = ExceptionHandling::None;
89  WinEHEncodingType = WinEH::EncodingType::Invalid;
90  DwarfUsesRelocationsAcrossSections = true;
91  DwarfFDESymbolsUseAbsDiff = false;
92  DwarfRegNumForCFI = false;
93  NeedsDwarfSectionOffsetDirective = false;
94  UseParensForSymbolVariant = false;
95  UseLogicalShr = true;
96
97  // FIXME: Clang's logic should be synced with the logic used to initialize
98  //        this member and the two implementations should be merged.
99  // For reference:
100  // - Solaris always enables the integrated assembler by default
101  //   - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
102  // - Windows always enables the integrated assembler by default
103  //   - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
104  // - MachO targets always enables the integrated assembler by default
105  //   - MCAsmInfoDarwin is handling this case
106  // - Generic_GCC toolchains enable the integrated assembler on a per
107  //   architecture basis.
108  //   - The target subclasses for AArch64, ARM, and X86 handle these cases
109  UseIntegratedAssembler = false;
110  PreserveAsmComments = true;
111
112  CompressDebugSections = DebugCompressionType::DCT_None;
113}
114
115MCAsmInfo::~MCAsmInfo() {
116}
117
118bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
119  return false;
120}
121
122const MCExpr *
123MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
124                                       unsigned Encoding,
125                                       MCStreamer &Streamer) const {
126  return getExprForFDESymbol(Sym, Encoding, Streamer);
127}
128
129const MCExpr *
130MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
131                               unsigned Encoding,
132                               MCStreamer &Streamer) const {
133  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
134    return MCSymbolRefExpr::create(Sym, Streamer.getContext());
135
136  MCContext &Context = Streamer.getContext();
137  const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
138  MCSymbol *PCSym = Context.createTempSymbol();
139  Streamer.EmitLabel(PCSym);
140  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
141  return MCBinaryExpr::createSub(Res, PC, Context);
142}
143
144static bool isAcceptableChar(char C) {
145  return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
146         (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
147}
148
149bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
150  if (Name.empty())
151    return false;
152
153  // If any of the characters in the string is an unacceptable character, force
154  // quotes.
155  for (char C : Name) {
156    if (!isAcceptableChar(C))
157      return false;
158  }
159
160  return true;
161}
162
163bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
164  // FIXME: Does .section .bss/.data/.text work everywhere??
165  return SectionName == ".text" || SectionName == ".data" ||
166        (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
167}
168