blob: 73dc74a4f20d82384808dcd50f0358ca1e331839 [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;
Rafael Espindola1048e752010-12-04 00:31:13 +000035 LinkerRequiresNonEmptyDwarfLines = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000036 MaxInstLength = 4;
Ulrich Weigand32d725b2013-06-12 14:46:54 +000037 MinInstAlignment = 1;
Jim Grosbacha3df87f2011-03-24 18:46:34 +000038 SeparatorString = ";";
Daniel Dunbar675ae272010-02-05 07:32:18 +000039 CommentColumn = 40;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000040 CommentString = "#";
Chris Lattner7bce0592010-09-22 22:19:53 +000041 LabelSuffix = ":";
Reed Kotleraee4d5d12012-12-16 04:00:45 +000042 DebugLabelSuffix = ":";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000043 GlobalPrefix = "";
44 PrivateGlobalPrefix = ".";
Chris Lattner1177cee2009-07-21 17:30:51 +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;
Chris Lattnerb8476452009-06-18 23:41:35 +000052 AllowQuotesInName = false;
Anton Korobeynikov592638a2009-09-18 16:57:42 +000053 AllowNameToStartWithDigit = false;
Mon P Wangb0a0a262010-04-29 04:00:56 +000054 AllowPeriodsInName = true;
Alexis Hunt0235f682012-04-07 00:37:53 +000055 AllowUTF8 = true;
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000056 UseDataRegionDirectives = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000057 ZeroDirective = "\t.zero\t";
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000058 AsciiDirective = "\t.ascii\t";
59 AscizDirective = "\t.asciz\t";
60 Data8bitsDirective = "\t.byte\t";
61 Data16bitsDirective = "\t.short\t";
62 Data32bitsDirective = "\t.long\t";
63 Data64bitsDirective = "\t.quad\t";
Chris Lattnerc9ea8fd2009-08-08 20:43:12 +000064 SunStyleELFSectionSwitchSyntax = false;
Bruno Cardoso Lopes62e6a8b2009-08-13 23:30:21 +000065 UsesELFSectionDirectiveForBSS = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000066 AlignDirective = "\t.align\t";
67 AlignmentIsInBytes = true;
68 TextAlignFillValue = 0;
Akira Hatanakaf0b08442012-02-03 04:33:00 +000069 GPRel64Directive = 0;
Chris Lattner19bd0392010-01-25 21:10:10 +000070 GPRel32Directive = 0;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000071 GlobalDirective = "\t.globl\t";
Chris Lattnerff234e02010-01-26 20:40:54 +000072 HasSetDirective = true;
Rafael Espindolaa6cd2d82010-12-22 21:51:29 +000073 HasAggressiveSymbolFolding = true;
Rafael Espindoladcb03f02010-01-26 20:21:43 +000074 COMMDirectiveAlignmentIsInBytes = true;
Benjamin Kramer68b9f052012-09-07 21:08:01 +000075 LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000076 HasDotTypeDotSizeDirective = true;
Rafael Espindolacda011b2008-12-03 11:01:37 +000077 HasSingleParameterDotFile = true;
Chris Lattner1deb09c2010-01-23 05:51:36 +000078 HasNoDeadStrip = false;
Kevin Enderby8be14412010-11-19 18:39:33 +000079 HasSymbolResolver = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000080 WeakRefDirective = 0;
81 WeakDefDirective = 0;
Chris Lattnerb1f29342010-01-19 05:08:13 +000082 LinkOnceDirective = 0;
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 HasLEB128 = false;
Anton Korobeynikov87001fd2008-09-25 21:00:33 +000087 SupportsDebugInformation = false;
Jim Grosbach693e36a2009-08-11 00:09:57 +000088 ExceptionsType = ExceptionHandling::None;
Nick Lewycky33da3362012-06-22 01:25:12 +000089 DwarfUsesRelocationsAcrossSections = true;
Akira Hatanaka2f2d9cb2011-07-07 20:30:33 +000090 DwarfRegNumForCFI = false;
Chris Lattner8d99c762010-03-12 21:03:47 +000091 HasMicrosoftFastStdCallMangling = false;
Matt Arsenault034ca0f2013-04-22 22:49:11 +000092 NeedsDwarfSectionOffsetDirective = false;
Chris Lattner95129a72006-10-13 17:50:07 +000093}
Chris Lattnerafe6d7a2006-10-05 00:35:16 +000094
Chris Lattner7b26fce2009-08-22 20:48:53 +000095MCAsmInfo::~MCAsmInfo() {
Chris Lattnerafe6d7a2006-10-05 00:35:16 +000096}
Chris Lattner95129a72006-10-13 17:50:07 +000097
Anton Korobeynikov942fda02007-03-07 02:47:57 +000098
David Blaikie5acff7e2013-06-23 18:31:11 +000099unsigned MCAsmInfo::getULEB128Size(uint64_t Value) {
Anton Korobeynikovbd890b12008-08-16 12:57:46 +0000100 unsigned Size = 0;
101 do {
102 Value >>= 7;
103 Size += sizeof(int8_t);
104 } while (Value);
105 return Size;
106}
107
David Blaikie5acff7e2013-06-23 18:31:11 +0000108unsigned MCAsmInfo::getSLEB128Size(int64_t Value) {
Anton Korobeynikovbd890b12008-08-16 12:57:46 +0000109 unsigned Size = 0;
110 int Sign = Value >> (8 * sizeof(Value) - 1);
111 bool IsMore;
112
113 do {
114 unsigned Byte = Value & 0x7f;
115 Value >>= 7;
116 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
117 Size += sizeof(int8_t);
118 } while (IsMore);
119 return Size;
120}
Rafael Espindolac5dac4d2011-04-28 16:09:09 +0000121
122const 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))
134 return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
135
136 MCContext &Context = Streamer.getContext();
137 const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
138 MCSymbol *PCSym = Context.CreateTempSymbol();
139 Streamer.EmitLabel(PCSym);
140 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
141 return MCBinaryExpr::CreateSub(Res, PC, Context);
Rafael Espindolac5dac4d2011-04-28 16:09:09 +0000142}