Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCAsmInfo.cpp
35233 views
//===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines target asm properties related what form asm statements9// should take.10//11//===----------------------------------------------------------------------===//1213#include "llvm/MC/MCAsmInfo.h"14#include "llvm/ADT/StringExtras.h"15#include "llvm/BinaryFormat/Dwarf.h"16#include "llvm/MC/MCContext.h"17#include "llvm/MC/MCExpr.h"18#include "llvm/MC/MCStreamer.h"19#include "llvm/Support/CommandLine.h"2021using namespace llvm;2223namespace {24enum DefaultOnOff { Default, Enable, Disable };25}26static cl::opt<DefaultOnOff> DwarfExtendedLoc(27"dwarf-extended-loc", cl::Hidden,28cl::desc("Disable emission of the extended flags in .loc directives."),29cl::values(clEnumVal(Default, "Default for platform"),30clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),31cl::init(Default));3233namespace llvm {34cl::opt<cl::boolOrDefault> UseLEB128Directives(35"use-leb128-directives", cl::Hidden,36cl::desc(37"Disable the usage of LEB128 directives, and generate .byte instead."),38cl::init(cl::BOU_UNSET));39}4041MCAsmInfo::MCAsmInfo() {42SeparatorString = ";";43CommentString = "#";44LabelSuffix = ":";45PrivateGlobalPrefix = "L";46PrivateLabelPrefix = PrivateGlobalPrefix;47LinkerPrivateGlobalPrefix = "";48InlineAsmStart = "APP";49InlineAsmEnd = "NO_APP";50Code16Directive = ".code16";51Code32Directive = ".code32";52Code64Directive = ".code64";53ZeroDirective = "\t.zero\t";54AsciiDirective = "\t.ascii\t";55AscizDirective = "\t.asciz\t";56Data8bitsDirective = "\t.byte\t";57Data16bitsDirective = "\t.short\t";58Data32bitsDirective = "\t.long\t";59Data64bitsDirective = "\t.quad\t";60GlobalDirective = "\t.globl\t";61WeakDirective = "\t.weak\t";62if (DwarfExtendedLoc != Default)63SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;64if (UseLEB128Directives != cl::BOU_UNSET)65HasLEB128Directives = UseLEB128Directives == cl::BOU_TRUE;66UseIntegratedAssembler = true;67ParseInlineAsmUsingAsmParser = false;68PreserveAsmComments = true;69PPCUseFullRegisterNames = false;70}7172MCAsmInfo::~MCAsmInfo() = default;7374void MCAsmInfo::addInitialFrameState(const MCCFIInstruction &Inst) {75InitialFrameState.push_back(Inst);76}7778const MCExpr *79MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,80unsigned Encoding,81MCStreamer &Streamer) const {82return getExprForFDESymbol(Sym, Encoding, Streamer);83}8485const MCExpr *86MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,87unsigned Encoding,88MCStreamer &Streamer) const {89if (!(Encoding & dwarf::DW_EH_PE_pcrel))90return MCSymbolRefExpr::create(Sym, Streamer.getContext());9192MCContext &Context = Streamer.getContext();93const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);94MCSymbol *PCSym = Context.createTempSymbol();95Streamer.emitLabel(PCSym);96const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);97return MCBinaryExpr::createSub(Res, PC, Context);98}99100bool MCAsmInfo::isAcceptableChar(char C) const {101if (C == '@')102return doesAllowAtInName();103104return isAlnum(C) || C == '_' || C == '$' || C == '.';105}106107bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {108if (Name.empty())109return false;110111// If any of the characters in the string is an unacceptable character, force112// quotes.113for (char C : Name) {114if (!isAcceptableChar(C))115return false;116}117118return true;119}120121bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {122// FIXME: Does .section .bss/.data/.text work everywhere??123return SectionName == ".text" || SectionName == ".data" ||124(SectionName == ".bss" && !usesELFSectionDirectiveForBSS());125}126127128