blob: 71e51e320f8bdd8a2a01532268834e3620633aa3 [file] [log] [blame]
Eugene Zelenkod3a6c892017-02-11 00:27:28 +00001//===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
Jim Laskey681ecbb2006-09-06 18:35:33 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Jim Laskey681ecbb2006-09-06 18:35:33 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file defines target asm properties related what form asm statements
10// should take.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner7b26fce2009-08-22 20:48:53 +000014#include "llvm/MC/MCAsmInfo.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000015#include "llvm/BinaryFormat/Dwarf.h"
Rafael Espindolafd057852011-05-01 03:50:49 +000016#include "llvm/MC/MCContext.h"
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000017#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCStreamer.h"
Alexey Bataevf7226ed2018-04-03 17:28:55 +000019#include "llvm/Support/CommandLine.h"
Eugene Zelenkod3a6c892017-02-11 00:27:28 +000020
Jim Laskey681ecbb2006-09-06 18:35:33 +000021using namespace llvm;
22
Alexey Bataevf7226ed2018-04-03 17:28:55 +000023enum DefaultOnOff { Default, Enable, Disable };
24static cl::opt<DefaultOnOff> DwarfExtendedLoc(
25 "dwarf-extended-loc", cl::Hidden,
26 cl::desc("Disable emission of the extended flags in .loc directives."),
27 cl::values(clEnumVal(Default, "Default for platform"),
28 clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
29 cl::init(Default));
30
Chris Lattner2b4364f2010-01-20 06:34:14 +000031MCAsmInfo::MCAsmInfo() {
Jim Grosbacha3df87f2011-03-24 18:46:34 +000032 SeparatorString = ";";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000033 CommentString = "#";
Chris Lattner7bce0592010-09-22 22:19:53 +000034 LabelSuffix = ":";
Rafael Espindola5113d162013-12-02 23:39:26 +000035 PrivateGlobalPrefix = "L";
Matt Arsenault4e273432014-12-04 00:06:57 +000036 PrivateLabelPrefix = PrivateGlobalPrefix;
Tim Northoverc3988b42014-03-29 07:05:06 +000037 LinkerPrivateGlobalPrefix = "";
Chris Lattnerabdcbc72009-08-11 22:39:40 +000038 InlineAsmStart = "APP";
39 InlineAsmEnd = "NO_APP";
Evan Cheng481ebb02011-07-27 00:38:12 +000040 Code16Directive = ".code16";
41 Code32Directive = ".code32";
42 Code64Directive = ".code64";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000043 ZeroDirective = "\t.zero\t";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000044 AsciiDirective = "\t.ascii\t";
45 AscizDirective = "\t.asciz\t";
46 Data8bitsDirective = "\t.byte\t";
47 Data16bitsDirective = "\t.short\t";
48 Data32bitsDirective = "\t.long\t";
49 Data64bitsDirective = "\t.quad\t";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000050 GlobalDirective = "\t.globl\t";
Jingyue Wu5b62eb92014-12-01 21:16:17 +000051 WeakDirective = "\t.weak\t";
Alexey Bataevf7226ed2018-04-03 17:28:55 +000052 if (DwarfExtendedLoc != Default)
53 SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;
Daniel Sanders753e1762014-02-13 14:44:26 +000054
55 // FIXME: Clang's logic should be synced with the logic used to initialize
56 // this member and the two implementations should be merged.
57 // For reference:
58 // - Solaris always enables the integrated assembler by default
59 // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
60 // - Windows always enables the integrated assembler by default
61 // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
62 // - MachO targets always enables the integrated assembler by default
63 // - MCAsmInfoDarwin is handling this case
64 // - Generic_GCC toolchains enable the integrated assembler on a per
65 // architecture basis.
Saleem Abdulrasoolfaa29bd2014-06-11 04:19:25 +000066 // - The target subclasses for AArch64, ARM, and X86 handle these cases
Daniel Sanders753e1762014-02-13 14:44:26 +000067 UseIntegratedAssembler = false;
Nirav Dave53a72f42016-07-11 12:42:14 +000068 PreserveAsmComments = true;
Chris Lattner95129a72006-10-13 17:50:07 +000069}
Chris Lattnerafe6d7a2006-10-05 00:35:16 +000070
Eugene Zelenkod3a6c892017-02-11 00:27:28 +000071MCAsmInfo::~MCAsmInfo() = default;
Chris Lattner95129a72006-10-13 17:50:07 +000072
Eric Christopher886a7b32019-04-12 06:57:45 +000073void MCAsmInfo::addInitialFrameState(const MCCFIInstruction &Inst) {
74 InitialFrameState.push_back(Inst);
75}
76
Lang Hames1e923ec2015-01-09 18:55:42 +000077bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
78 return false;
79}
80
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000081const MCExpr *
82MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
Rafael Espindolafd057852011-05-01 03:50:49 +000083 unsigned Encoding,
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000084 MCStreamer &Streamer) const {
Rafael Espindolafd057852011-05-01 03:50:49 +000085 return getExprForFDESymbol(Sym, Encoding, Streamer);
Rafael Espindola6bd6a702011-04-28 21:04:39 +000086}
87
88const MCExpr *
89MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
Rafael Espindolafd057852011-05-01 03:50:49 +000090 unsigned Encoding,
Rafael Espindola6bd6a702011-04-28 21:04:39 +000091 MCStreamer &Streamer) const {
Rafael Espindolafd057852011-05-01 03:50:49 +000092 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
Jim Grosbach13760bd2015-05-30 01:25:56 +000093 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
Rafael Espindolafd057852011-05-01 03:50:49 +000094
95 MCContext &Context = Streamer.getContext();
Jim Grosbach13760bd2015-05-30 01:25:56 +000096 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
Jim Grosbach6f482002015-05-18 18:43:14 +000097 MCSymbol *PCSym = Context.createTempSymbol();
Rafael Espindolafd057852011-05-01 03:50:49 +000098 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000099 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
100 return MCBinaryExpr::createSub(Res, PC, Context);
Rafael Espindolac5dac4d2011-04-28 16:09:09 +0000101}
Matt Arsenault8b643552015-06-09 00:31:39 +0000102
103static bool isAcceptableChar(char C) {
104 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
105 (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
106}
107
108bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
109 if (Name.empty())
110 return false;
111
112 // If any of the characters in the string is an unacceptable character, force
113 // quotes.
114 for (char C : Name) {
115 if (!isAcceptableChar(C))
116 return false;
117 }
118
119 return true;
120}
Tom Stellard8e025762015-09-25 21:41:14 +0000121
122bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
123 // FIXME: Does .section .bss/.data/.text work everywhere??
124 return SectionName == ".text" || SectionName == ".data" ||
125 (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
126}