blob: 30f22d2d68f4e9b873c5a5aa75561b4242950a7d [file] [log] [blame]
Eugene Zelenkoa700a602017-02-11 00:27:28 +00001//===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
Jim Laskeyec0d9fe2006-09-06 18:35:33 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskeyec0d9fe2006-09-06 18:35:33 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines target asm properties related what form asm statements
11// should take.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattneraf76e592009-08-22 20:48:53 +000015#include "llvm/MC/MCAsmInfo.h"
Zachary Turner19ca2b02017-06-07 03:48:56 +000016#include "llvm/BinaryFormat/Dwarf.h"
Rafael Espindoladebd7e42011-05-01 03:50:49 +000017#include "llvm/MC/MCContext.h"
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000018#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCStreamer.h"
Alexey Bataevd88368c2018-04-03 17:28:55 +000020#include "llvm/Support/CommandLine.h"
Eugene Zelenkoa700a602017-02-11 00:27:28 +000021
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000022using namespace llvm;
23
Alexey Bataevd88368c2018-04-03 17:28:55 +000024enum DefaultOnOff { Default, Enable, Disable };
25static cl::opt<DefaultOnOff> DwarfExtendedLoc(
26 "dwarf-extended-loc", cl::Hidden,
27 cl::desc("Disable emission of the extended flags in .loc directives."),
28 cl::values(clEnumVal(Default, "Default for platform"),
29 clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
30 cl::init(Default));
31
Chris Lattner8eeba352010-01-20 06:34:14 +000032MCAsmInfo::MCAsmInfo() {
Jim Grosbachd31d3042011-03-24 18:46:34 +000033 SeparatorString = ";";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000034 CommentString = "#";
Chris Lattnere07b75e2010-09-22 22:19:53 +000035 LabelSuffix = ":";
Rafael Espindola9472fd72013-12-02 23:39:26 +000036 PrivateGlobalPrefix = "L";
Matt Arsenault459e5952014-12-04 00:06:57 +000037 PrivateLabelPrefix = PrivateGlobalPrefix;
Tim Northoverc5d592d2014-03-29 07:05:06 +000038 LinkerPrivateGlobalPrefix = "";
Chris Lattnere2b06012009-08-11 22:39:40 +000039 InlineAsmStart = "APP";
40 InlineAsmEnd = "NO_APP";
Evan Chengbd27f5a2011-07-27 00:38:12 +000041 Code16Directive = ".code16";
42 Code32Directive = ".code32";
43 Code64Directive = ".code64";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000044 ZeroDirective = "\t.zero\t";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000045 AsciiDirective = "\t.ascii\t";
46 AscizDirective = "\t.asciz\t";
47 Data8bitsDirective = "\t.byte\t";
48 Data16bitsDirective = "\t.short\t";
49 Data32bitsDirective = "\t.long\t";
50 Data64bitsDirective = "\t.quad\t";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000051 GlobalDirective = "\t.globl\t";
Jingyue Wub0432782014-12-01 21:16:17 +000052 WeakDirective = "\t.weak\t";
Alexey Bataevd88368c2018-04-03 17:28:55 +000053 if (DwarfExtendedLoc != Default)
54 SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;
Daniel Sanders38c6b582014-02-13 14:44:26 +000055
56 // FIXME: Clang's logic should be synced with the logic used to initialize
57 // this member and the two implementations should be merged.
58 // For reference:
59 // - Solaris always enables the integrated assembler by default
60 // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
61 // - Windows always enables the integrated assembler by default
62 // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
63 // - MachO targets always enables the integrated assembler by default
64 // - MCAsmInfoDarwin is handling this case
65 // - Generic_GCC toolchains enable the integrated assembler on a per
66 // architecture basis.
Saleem Abdulrasool9c7ddf72014-06-11 04:19:25 +000067 // - The target subclasses for AArch64, ARM, and X86 handle these cases
Daniel Sanders38c6b582014-02-13 14:44:26 +000068 UseIntegratedAssembler = false;
Nirav Daveaee0f142016-07-11 12:42:14 +000069 PreserveAsmComments = true;
Chris Lattner4c7b07a2006-10-13 17:50:07 +000070}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +000071
Eugene Zelenkoa700a602017-02-11 00:27:28 +000072MCAsmInfo::~MCAsmInfo() = default;
Chris Lattner4c7b07a2006-10-13 17:50:07 +000073
Lang Hames4c553e02015-01-09 18:55:42 +000074bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
75 return false;
76}
77
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000078const MCExpr *
79MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
Rafael Espindoladebd7e42011-05-01 03:50:49 +000080 unsigned Encoding,
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000081 MCStreamer &Streamer) const {
Rafael Espindoladebd7e42011-05-01 03:50:49 +000082 return getExprForFDESymbol(Sym, Encoding, Streamer);
Rafael Espindolaa0057ca2011-04-28 21:04:39 +000083}
84
85const MCExpr *
86MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
Rafael Espindoladebd7e42011-05-01 03:50:49 +000087 unsigned Encoding,
Rafael Espindolaa0057ca2011-04-28 21:04:39 +000088 MCStreamer &Streamer) const {
Rafael Espindoladebd7e42011-05-01 03:50:49 +000089 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
Jim Grosbach586c0042015-05-30 01:25:56 +000090 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
Rafael Espindoladebd7e42011-05-01 03:50:49 +000091
92 MCContext &Context = Streamer.getContext();
Jim Grosbach586c0042015-05-30 01:25:56 +000093 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
Jim Grosbach19696da2015-05-18 18:43:14 +000094 MCSymbol *PCSym = Context.createTempSymbol();
Rafael Espindoladebd7e42011-05-01 03:50:49 +000095 Streamer.EmitLabel(PCSym);
Jim Grosbach586c0042015-05-30 01:25:56 +000096 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
97 return MCBinaryExpr::createSub(Res, PC, Context);
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000098}
Matt Arsenaultd99ce2f2015-06-09 00:31:39 +000099
100static bool isAcceptableChar(char C) {
101 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
102 (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
103}
104
105bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
106 if (Name.empty())
107 return false;
108
109 // If any of the characters in the string is an unacceptable character, force
110 // quotes.
111 for (char C : Name) {
112 if (!isAcceptableChar(C))
113 return false;
114 }
115
116 return true;
117}
Tom Stellard68f9d1c2015-09-25 21:41:14 +0000118
119bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
120 // FIXME: Does .section .bss/.data/.text work everywhere??
121 return SectionName == ".text" || SectionName == ".data" ||
122 (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
123}