1 //===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
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 defines target asm properties related what form asm statements
13 //===----------------------------------------------------------------------===//
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/BinaryFormat/Dwarf.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCStreamer.h"
23 MCAsmInfo::MCAsmInfo() {
24 SeparatorString = ";";
27 PrivateGlobalPrefix = "L";
28 PrivateLabelPrefix = PrivateGlobalPrefix;
29 LinkerPrivateGlobalPrefix = "";
30 InlineAsmStart = "APP";
31 InlineAsmEnd = "NO_APP";
32 Code16Directive = ".code16";
33 Code32Directive = ".code32";
34 Code64Directive = ".code64";
35 ZeroDirective = "\t.zero\t";
36 AsciiDirective = "\t.ascii\t";
37 AscizDirective = "\t.asciz\t";
38 Data8bitsDirective = "\t.byte\t";
39 Data16bitsDirective = "\t.short\t";
40 Data32bitsDirective = "\t.long\t";
41 Data64bitsDirective = "\t.quad\t";
42 GlobalDirective = "\t.globl\t";
43 WeakDirective = "\t.weak\t";
45 // FIXME: Clang's logic should be synced with the logic used to initialize
46 // this member and the two implementations should be merged.
48 // - Solaris always enables the integrated assembler by default
49 // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
50 // - Windows always enables the integrated assembler by default
51 // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
52 // - MachO targets always enables the integrated assembler by default
53 // - MCAsmInfoDarwin is handling this case
54 // - Generic_GCC toolchains enable the integrated assembler on a per
55 // architecture basis.
56 // - The target subclasses for AArch64, ARM, and X86 handle these cases
57 UseIntegratedAssembler = false;
58 PreserveAsmComments = true;
61 MCAsmInfo::~MCAsmInfo() = default;
63 bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
68 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
70 MCStreamer &Streamer) const {
71 return getExprForFDESymbol(Sym, Encoding, Streamer);
75 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
77 MCStreamer &Streamer) const {
78 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
79 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
81 MCContext &Context = Streamer.getContext();
82 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
83 MCSymbol *PCSym = Context.createTempSymbol();
84 Streamer.EmitLabel(PCSym);
85 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
86 return MCBinaryExpr::createSub(Res, PC, Context);
89 static bool isAcceptableChar(char C) {
90 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
91 (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
94 bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
98 // If any of the characters in the string is an unacceptable character, force
100 for (char C : Name) {
101 if (!isAcceptableChar(C))
108 bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
109 // FIXME: Does .section .bss/.data/.text work everywhere??
110 return SectionName == ".text" || SectionName == ".data" ||
111 (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());