blob: b9be685cedc4139dc2d214bd69b98b6baf7a29f6 [file] [log] [blame]
Eugene Zelenkod3a6c892017-02-11 00:27:28 +00001//===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
Jim Laskey681ecbb2006-09-06 18:35:33 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Laskey681ecbb2006-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 Lattner7b26fce2009-08-22 20:48:53 +000015#include "llvm/MC/MCAsmInfo.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"
Rafael Espindolafd057852011-05-01 03:50:49 +000019#include "llvm/Support/Dwarf.h"
Eugene Zelenkod3a6c892017-02-11 00:27:28 +000020
Jim Laskey681ecbb2006-09-06 18:35:33 +000021using namespace llvm;
22
Chris Lattner2b4364f2010-01-20 06:34:14 +000023MCAsmInfo::MCAsmInfo() {
Jim Grosbacha3df87f2011-03-24 18:46:34 +000024 SeparatorString = ";";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000025 CommentString = "#";
Chris Lattner7bce0592010-09-22 22:19:53 +000026 LabelSuffix = ":";
Rafael Espindola5113d162013-12-02 23:39:26 +000027 PrivateGlobalPrefix = "L";
Matt Arsenault4e273432014-12-04 00:06:57 +000028 PrivateLabelPrefix = PrivateGlobalPrefix;
Tim Northoverc3988b42014-03-29 07:05:06 +000029 LinkerPrivateGlobalPrefix = "";
Chris Lattnerabdcbc72009-08-11 22:39:40 +000030 InlineAsmStart = "APP";
31 InlineAsmEnd = "NO_APP";
Evan Cheng481ebb02011-07-27 00:38:12 +000032 Code16Directive = ".code16";
33 Code32Directive = ".code32";
34 Code64Directive = ".code64";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000035 ZeroDirective = "\t.zero\t";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000036 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";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000042 GlobalDirective = "\t.globl\t";
Jingyue Wu5b62eb92014-12-01 21:16:17 +000043 WeakDirective = "\t.weak\t";
Daniel Sanders753e1762014-02-13 14:44:26 +000044
45 // FIXME: Clang's logic should be synced with the logic used to initialize
46 // this member and the two implementations should be merged.
47 // For reference:
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.
Saleem Abdulrasoolfaa29bd2014-06-11 04:19:25 +000056 // - The target subclasses for AArch64, ARM, and X86 handle these cases
Daniel Sanders753e1762014-02-13 14:44:26 +000057 UseIntegratedAssembler = false;
Nirav Dave53a72f42016-07-11 12:42:14 +000058 PreserveAsmComments = true;
Chris Lattner95129a72006-10-13 17:50:07 +000059}
Chris Lattnerafe6d7a2006-10-05 00:35:16 +000060
Eugene Zelenkod3a6c892017-02-11 00:27:28 +000061MCAsmInfo::~MCAsmInfo() = default;
Chris Lattner95129a72006-10-13 17:50:07 +000062
Lang Hames1e923ec2015-01-09 18:55:42 +000063bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
64 return false;
65}
66
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000067const MCExpr *
68MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
Rafael Espindolafd057852011-05-01 03:50:49 +000069 unsigned Encoding,
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000070 MCStreamer &Streamer) const {
Rafael Espindolafd057852011-05-01 03:50:49 +000071 return getExprForFDESymbol(Sym, Encoding, Streamer);
Rafael Espindola6bd6a702011-04-28 21:04:39 +000072}
73
74const MCExpr *
75MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
Rafael Espindolafd057852011-05-01 03:50:49 +000076 unsigned Encoding,
Rafael Espindola6bd6a702011-04-28 21:04:39 +000077 MCStreamer &Streamer) const {
Rafael Espindolafd057852011-05-01 03:50:49 +000078 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
Jim Grosbach13760bd2015-05-30 01:25:56 +000079 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
Rafael Espindolafd057852011-05-01 03:50:49 +000080
81 MCContext &Context = Streamer.getContext();
Jim Grosbach13760bd2015-05-30 01:25:56 +000082 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
Jim Grosbach6f482002015-05-18 18:43:14 +000083 MCSymbol *PCSym = Context.createTempSymbol();
Rafael Espindolafd057852011-05-01 03:50:49 +000084 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000085 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
86 return MCBinaryExpr::createSub(Res, PC, Context);
Rafael Espindolac5dac4d2011-04-28 16:09:09 +000087}
Matt Arsenault8b643552015-06-09 00:31:39 +000088
89static bool isAcceptableChar(char C) {
90 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
91 (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
92}
93
94bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
95 if (Name.empty())
96 return false;
97
98 // If any of the characters in the string is an unacceptable character, force
99 // quotes.
100 for (char C : Name) {
101 if (!isAcceptableChar(C))
102 return false;
103 }
104
105 return true;
106}
Tom Stellard8e025762015-09-25 21:41:14 +0000107
108bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
109 // FIXME: Does .section .bss/.data/.text work everywhere??
110 return SectionName == ".text" || SectionName == ".data" ||
111 (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
112}