xref: /freebsd/contrib/llvm-project/llvm/lib/MC/MCAsmInfo.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file defines target asm properties related what form asm statements
100b57cec5SDimitry Andric // should take.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h"
1506c3fb27SDimitry Andric #include "llvm/ADT/StringExtras.h"
160b57cec5SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h"
170b57cec5SDimitry Andric #include "llvm/MC/MCContext.h"
180b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h"
190b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h"
200b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric using namespace llvm;
230b57cec5SDimitry Andric 
24fe6060f1SDimitry Andric namespace {
250b57cec5SDimitry Andric enum DefaultOnOff { Default, Enable, Disable };
26fe6060f1SDimitry Andric }
270b57cec5SDimitry Andric static cl::opt<DefaultOnOff> DwarfExtendedLoc(
280b57cec5SDimitry Andric     "dwarf-extended-loc", cl::Hidden,
290b57cec5SDimitry Andric     cl::desc("Disable emission of the extended flags in .loc directives."),
300b57cec5SDimitry Andric     cl::values(clEnumVal(Default, "Default for platform"),
310b57cec5SDimitry Andric                clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
320b57cec5SDimitry Andric     cl::init(Default));
330b57cec5SDimitry Andric 
34fe6060f1SDimitry Andric namespace llvm {
35e8d8bef9SDimitry Andric cl::opt<cl::boolOrDefault> UseLEB128Directives(
36e8d8bef9SDimitry Andric     "use-leb128-directives", cl::Hidden,
37e8d8bef9SDimitry Andric     cl::desc(
38e8d8bef9SDimitry Andric         "Disable the usage of LEB128 directives, and generate .byte instead."),
39e8d8bef9SDimitry Andric     cl::init(cl::BOU_UNSET));
40fe6060f1SDimitry Andric }
41e8d8bef9SDimitry Andric 
MCAsmInfo()420b57cec5SDimitry Andric MCAsmInfo::MCAsmInfo() {
430b57cec5SDimitry Andric   SeparatorString = ";";
440b57cec5SDimitry Andric   CommentString = "#";
450b57cec5SDimitry Andric   LabelSuffix = ":";
460b57cec5SDimitry Andric   PrivateGlobalPrefix = "L";
470b57cec5SDimitry Andric   PrivateLabelPrefix = PrivateGlobalPrefix;
480b57cec5SDimitry Andric   LinkerPrivateGlobalPrefix = "";
490b57cec5SDimitry Andric   InlineAsmStart = "APP";
500b57cec5SDimitry Andric   InlineAsmEnd = "NO_APP";
510b57cec5SDimitry Andric   Code16Directive = ".code16";
520b57cec5SDimitry Andric   Code32Directive = ".code32";
530b57cec5SDimitry Andric   Code64Directive = ".code64";
540b57cec5SDimitry Andric   ZeroDirective = "\t.zero\t";
550b57cec5SDimitry Andric   AsciiDirective = "\t.ascii\t";
560b57cec5SDimitry Andric   AscizDirective = "\t.asciz\t";
570b57cec5SDimitry Andric   Data8bitsDirective = "\t.byte\t";
580b57cec5SDimitry Andric   Data16bitsDirective = "\t.short\t";
590b57cec5SDimitry Andric   Data32bitsDirective = "\t.long\t";
600b57cec5SDimitry Andric   Data64bitsDirective = "\t.quad\t";
610b57cec5SDimitry Andric   GlobalDirective = "\t.globl\t";
620b57cec5SDimitry Andric   WeakDirective = "\t.weak\t";
630b57cec5SDimitry Andric   if (DwarfExtendedLoc != Default)
640b57cec5SDimitry Andric     SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;
65e8d8bef9SDimitry Andric   if (UseLEB128Directives != cl::BOU_UNSET)
66e8d8bef9SDimitry Andric     HasLEB128Directives = UseLEB128Directives == cl::BOU_TRUE;
675ffd83dbSDimitry Andric   UseIntegratedAssembler = true;
68fe6060f1SDimitry Andric   ParseInlineAsmUsingAsmParser = false;
690b57cec5SDimitry Andric   PreserveAsmComments = true;
70*5f757f3fSDimitry Andric   PPCUseFullRegisterNames = false;
710b57cec5SDimitry Andric }
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric MCAsmInfo::~MCAsmInfo() = default;
740b57cec5SDimitry Andric 
addInitialFrameState(const MCCFIInstruction & Inst)750b57cec5SDimitry Andric void MCAsmInfo::addInitialFrameState(const MCCFIInstruction &Inst) {
760b57cec5SDimitry Andric   InitialFrameState.push_back(Inst);
770b57cec5SDimitry Andric }
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric const MCExpr *
getExprForPersonalitySymbol(const MCSymbol * Sym,unsigned Encoding,MCStreamer & Streamer) const800b57cec5SDimitry Andric MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
810b57cec5SDimitry Andric                                        unsigned Encoding,
820b57cec5SDimitry Andric                                        MCStreamer &Streamer) const {
830b57cec5SDimitry Andric   return getExprForFDESymbol(Sym, Encoding, Streamer);
840b57cec5SDimitry Andric }
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric const MCExpr *
getExprForFDESymbol(const MCSymbol * Sym,unsigned Encoding,MCStreamer & Streamer) const870b57cec5SDimitry Andric MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
880b57cec5SDimitry Andric                                unsigned Encoding,
890b57cec5SDimitry Andric                                MCStreamer &Streamer) const {
900b57cec5SDimitry Andric   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
910b57cec5SDimitry Andric     return MCSymbolRefExpr::create(Sym, Streamer.getContext());
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   MCContext &Context = Streamer.getContext();
940b57cec5SDimitry Andric   const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
950b57cec5SDimitry Andric   MCSymbol *PCSym = Context.createTempSymbol();
965ffd83dbSDimitry Andric   Streamer.emitLabel(PCSym);
970b57cec5SDimitry Andric   const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
980b57cec5SDimitry Andric   return MCBinaryExpr::createSub(Res, PC, Context);
990b57cec5SDimitry Andric }
1000b57cec5SDimitry Andric 
isAcceptableChar(char C) const101480093f4SDimitry Andric bool MCAsmInfo::isAcceptableChar(char C) const {
10281ad6265SDimitry Andric   if (C == '@')
10381ad6265SDimitry Andric     return doesAllowAtInName();
10481ad6265SDimitry Andric 
10581ad6265SDimitry Andric   return isAlnum(C) || C == '_' || C == '$' || C == '.';
1060b57cec5SDimitry Andric }
1070b57cec5SDimitry Andric 
isValidUnquotedName(StringRef Name) const1080b57cec5SDimitry Andric bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
1090b57cec5SDimitry Andric   if (Name.empty())
1100b57cec5SDimitry Andric     return false;
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric   // If any of the characters in the string is an unacceptable character, force
1130b57cec5SDimitry Andric   // quotes.
1140b57cec5SDimitry Andric   for (char C : Name) {
1150b57cec5SDimitry Andric     if (!isAcceptableChar(C))
1160b57cec5SDimitry Andric       return false;
1170b57cec5SDimitry Andric   }
1180b57cec5SDimitry Andric 
1190b57cec5SDimitry Andric   return true;
1200b57cec5SDimitry Andric }
1210b57cec5SDimitry Andric 
shouldOmitSectionDirective(StringRef SectionName) const1220b57cec5SDimitry Andric bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
1230b57cec5SDimitry Andric   // FIXME: Does .section .bss/.data/.text work everywhere??
1240b57cec5SDimitry Andric   return SectionName == ".text" || SectionName == ".data" ||
1250b57cec5SDimitry Andric         (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
1260b57cec5SDimitry Andric }
127