blob: 3eb8f50de5a8a54af8f21c3f972746b697e0e681 [file] [log] [blame]
Chris Lattner7b26fce2009-08-22 20:48:53 +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"
Michael J. Spencer447762d2010-11-29 18:16:10 +000019#include "llvm/Support/DataTypes.h"
Rafael Espindolafd057852011-05-01 03:50:49 +000020#include "llvm/Support/Dwarf.h"
Dale Johannesen0a1069d2007-04-23 20:00:17 +000021#include <cctype>
22#include <cstring>
Jim Laskey681ecbb2006-09-06 18:35:33 +000023using namespace llvm;
24
Chris Lattner2b4364f2010-01-20 06:34:14 +000025MCAsmInfo::MCAsmInfo() {
Evan Chenga83b37a2011-07-15 02:09:41 +000026 PointerSize = 4;
Eli Bendersky32aab222013-01-23 16:22:04 +000027 CalleeSaveStackSlotSize = 4;
Eli Bendersky0893e102013-01-22 18:02:49 +000028
Evan Chenga83b37a2011-07-15 02:09:41 +000029 IsLittleEndian = true;
30 StackGrowsUp = false;
Chris Lattner76bdea32010-01-23 07:21:06 +000031 HasSubsectionsViaSymbols = false;
Chris Lattner1d371882010-01-19 02:09:44 +000032 HasMachoZeroFillDirective = false;
Eric Christopher27e7ffc2010-05-20 00:49:07 +000033 HasMachoTBSSDirective = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000034 MaxInstLength = 4;
Ulrich Weigand32d725b2013-06-12 14:46:54 +000035 MinInstAlignment = 1;
David Majnemer0c58bc62013-09-25 10:47:21 +000036 DollarIsPC = false;
Jim Grosbacha3df87f2011-03-24 18:46:34 +000037 SeparatorString = ";";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000038 CommentString = "#";
Chris Lattner7bce0592010-09-22 22:19:53 +000039 LabelSuffix = ":";
Rafael Espindolaf4917042014-06-24 22:45:16 +000040 UseAssignmentForEHBegin = false;
Rafael Espindola86bd6a12015-03-05 18:55:50 +000041 NeedsLocalForSize = false;
Rafael Espindola5113d162013-12-02 23:39:26 +000042 PrivateGlobalPrefix = "L";
Matt Arsenault4e273432014-12-04 00:06:57 +000043 PrivateLabelPrefix = PrivateGlobalPrefix;
Tim Northoverc3988b42014-03-29 07:05:06 +000044 LinkerPrivateGlobalPrefix = "";
Chris Lattnerabdcbc72009-08-11 22:39:40 +000045 InlineAsmStart = "APP";
46 InlineAsmEnd = "NO_APP";
Evan Cheng481ebb02011-07-27 00:38:12 +000047 Code16Directive = ".code16";
48 Code32Directive = ".code32";
49 Code64Directive = ".code64";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000050 AssemblerDialect = 0;
Hans Wennborgce69d772013-10-18 20:46:28 +000051 AllowAtInName = false;
Matt Arsenault8b643552015-06-09 00:31:39 +000052 SupportsQuotedNames = true;
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000053 UseDataRegionDirectives = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000054 ZeroDirective = "\t.zero\t";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000055 AsciiDirective = "\t.ascii\t";
56 AscizDirective = "\t.asciz\t";
57 Data8bitsDirective = "\t.byte\t";
58 Data16bitsDirective = "\t.short\t";
59 Data32bitsDirective = "\t.long\t";
60 Data64bitsDirective = "\t.quad\t";
Chris Lattnerc9ea8fd2009-08-08 20:43:12 +000061 SunStyleELFSectionSwitchSyntax = false;
Bruno Cardoso Lopes62e6a8b2009-08-13 23:30:21 +000062 UsesELFSectionDirectiveForBSS = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000063 AlignmentIsInBytes = true;
64 TextAlignFillValue = 0;
Craig Topperbb694de2014-04-13 04:57:38 +000065 GPRel64Directive = nullptr;
66 GPRel32Directive = nullptr;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000067 GlobalDirective = "\t.globl\t";
Rafael Espindolac606bfe2014-10-21 01:17:30 +000068 SetDirectiveSuppressesReloc = false;
Rafael Espindolaa6cd2d82010-12-22 21:51:29 +000069 HasAggressiveSymbolFolding = true;
Rafael Espindoladcb03f02010-01-26 20:21:43 +000070 COMMDirectiveAlignmentIsInBytes = true;
Benjamin Kramer68b9f052012-09-07 21:08:01 +000071 LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
Jingyue Wue8290f22015-03-12 01:50:30 +000072 HasFunctionAlignment = true;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000073 HasDotTypeDotSizeDirective = true;
Rafael Espindolacda011b2008-12-03 11:01:37 +000074 HasSingleParameterDotFile = true;
Rafael Espindola5645bad2013-10-16 01:05:45 +000075 HasIdentDirective = false;
Chris Lattner1deb09c2010-01-23 05:51:36 +000076 HasNoDeadStrip = false;
Lang Hames1b640e02016-03-15 01:43:05 +000077 HasAltEntry = false;
Jingyue Wu5b62eb92014-12-01 21:16:17 +000078 WeakDirective = "\t.weak\t";
Craig Topperbb694de2014-04-13 04:57:38 +000079 WeakRefDirective = nullptr;
Rafael Espindola04867ce2013-12-02 23:04:51 +000080 HasWeakDefDirective = false;
David Fang1b018492013-12-10 21:37:41 +000081 HasWeakDefCanBeHiddenDirective = false;
Rafael Espindola04867ce2013-12-02 23:04:51 +000082 HasLinkOnceDirective = false;
Chris Lattner0bfd2792010-01-23 06:53:23 +000083 HiddenVisibilityAttr = MCSA_Hidden;
Stuart Hastingsbf836592011-02-23 02:27:05 +000084 HiddenDeclarationVisibilityAttr = MCSA_Hidden;
Chris Lattner0bfd2792010-01-23 06:53:23 +000085 ProtectedVisibilityAttr = MCSA_Protected;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000086 SupportsDebugInformation = false;
Jim Grosbach693e36a2009-08-11 00:09:57 +000087 ExceptionsType = ExceptionHandling::None;
Saleem Abdulrasoold4580912014-09-01 23:48:29 +000088 WinEHEncodingType = WinEH::EncodingType::Invalid;
Nick Lewycky33da3362012-06-22 01:25:12 +000089 DwarfUsesRelocationsAcrossSections = true;
Iain Sandoe618def62014-01-08 10:22:54 +000090 DwarfFDESymbolsUseAbsDiff = false;
Akira Hatanaka2f2d9cb2011-07-07 20:30:33 +000091 DwarfRegNumForCFI = false;
Matt Arsenault034ca0f2013-04-22 22:49:11 +000092 NeedsDwarfSectionOffsetDirective = false;
David Peixotto8ad70b32013-12-04 22:43:20 +000093 UseParensForSymbolVariant = false;
Ahmed Bougacha19052872015-04-28 01:37:11 +000094 UseLogicalShr = true;
Daniel Sanders753e1762014-02-13 14:44:26 +000095
96 // FIXME: Clang's logic should be synced with the logic used to initialize
97 // this member and the two implementations should be merged.
98 // For reference:
99 // - Solaris always enables the integrated assembler by default
100 // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
101 // - Windows always enables the integrated assembler by default
102 // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
103 // - MachO targets always enables the integrated assembler by default
104 // - MCAsmInfoDarwin is handling this case
105 // - Generic_GCC toolchains enable the integrated assembler on a per
106 // architecture basis.
Saleem Abdulrasoolfaa29bd2014-06-11 04:19:25 +0000107 // - The target subclasses for AArch64, ARM, and X86 handle these cases
Daniel Sanders753e1762014-02-13 14:44:26 +0000108 UseIntegratedAssembler = false;
Nirav Dave53a72f42016-07-11 12:42:14 +0000109 PreserveAsmComments = true;
David Blaikie7400a972014-03-27 20:45:58 +0000110
George Rimarc91e38c2016-05-27 12:27:32 +0000111 CompressDebugSections = DebugCompressionType::DCT_None;
Chris Lattner95129a72006-10-13 17:50:07 +0000112}
Chris Lattnerafe6d7a2006-10-05 00:35:16 +0000113
Chris Lattner7b26fce2009-08-22 20:48:53 +0000114MCAsmInfo::~MCAsmInfo() {
Chris Lattnerafe6d7a2006-10-05 00:35:16 +0000115}
Chris Lattner95129a72006-10-13 17:50:07 +0000116
Lang Hames1e923ec2015-01-09 18:55:42 +0000117bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
118 return false;
119}
120
Rafael Espindolac5dac4d2011-04-28 16:09:09 +0000121const MCExpr *
122MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
Rafael Espindolafd057852011-05-01 03:50:49 +0000123 unsigned Encoding,
Rafael Espindolac5dac4d2011-04-28 16:09:09 +0000124 MCStreamer &Streamer) const {
Rafael Espindolafd057852011-05-01 03:50:49 +0000125 return getExprForFDESymbol(Sym, Encoding, Streamer);
Rafael Espindola6bd6a702011-04-28 21:04:39 +0000126}
127
128const MCExpr *
129MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
Rafael Espindolafd057852011-05-01 03:50:49 +0000130 unsigned Encoding,
Rafael Espindola6bd6a702011-04-28 21:04:39 +0000131 MCStreamer &Streamer) const {
Rafael Espindolafd057852011-05-01 03:50:49 +0000132 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
Jim Grosbach13760bd2015-05-30 01:25:56 +0000133 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
Rafael Espindolafd057852011-05-01 03:50:49 +0000134
135 MCContext &Context = Streamer.getContext();
Jim Grosbach13760bd2015-05-30 01:25:56 +0000136 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
Jim Grosbach6f482002015-05-18 18:43:14 +0000137 MCSymbol *PCSym = Context.createTempSymbol();
Rafael Espindolafd057852011-05-01 03:50:49 +0000138 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +0000139 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
140 return MCBinaryExpr::createSub(Res, PC, Context);
Rafael Espindolac5dac4d2011-04-28 16:09:09 +0000141}
Matt Arsenault8b643552015-06-09 00:31:39 +0000142
143static bool isAcceptableChar(char C) {
144 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
145 (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
146}
147
148bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
149 if (Name.empty())
150 return false;
151
152 // If any of the characters in the string is an unacceptable character, force
153 // quotes.
154 for (char C : Name) {
155 if (!isAcceptableChar(C))
156 return false;
157 }
158
159 return true;
160}
Tom Stellard8e025762015-09-25 21:41:14 +0000161
162bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
163 // FIXME: Does .section .bss/.data/.text work everywhere??
164 return SectionName == ".text" || SectionName == ".data" ||
165 (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
166}