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