blob: c330e740c2d6fa1fe5080993d76ffcb7c5849984 [file] [log] [blame]
Chris Lattneraf76e592009-08-22 20:48:53 +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"
Rafael Espindoladebd7e42011-05-01 03:50:49 +000016#include "llvm/MC/MCContext.h"
Rafael Espindolabfa27cc2011-04-28 16:09:09 +000017#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCStreamer.h"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000019#include "llvm/Support/DataTypes.h"
Rafael Espindoladebd7e42011-05-01 03:50:49 +000020#include "llvm/Support/Dwarf.h"
Dale Johannesen3bb62832007-04-23 20:00:17 +000021#include <cctype>
22#include <cstring>
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000023using namespace llvm;
24
Chris Lattner8eeba352010-01-20 06:34:14 +000025MCAsmInfo::MCAsmInfo() {
Evan Cheng1be0e272011-07-15 02:09:41 +000026 PointerSize = 4;
27 IsLittleEndian = true;
28 StackGrowsUp = false;
Chris Lattnerf9f93e42010-01-23 07:21:06 +000029 HasSubsectionsViaSymbols = false;
Chris Lattneraac138e2010-01-19 02:09:44 +000030 HasMachoZeroFillDirective = false;
Eric Christopherc1a887d2010-05-20 00:49:07 +000031 HasMachoTBSSDirective = false;
Duncan Sands147272b2011-09-02 18:07:19 +000032 StructorOutputOrder = Structors::ReversePriorityOrder;
Chris Lattner71eae712010-01-19 04:34:02 +000033 HasStaticCtorDtorReferenceInStaticMode = false;
Rafael Espindola767b1be2010-12-04 00:31:13 +000034 LinkerRequiresNonEmptyDwarfLines = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000035 MaxInstLength = 4;
36 PCSymbol = "$";
Jim Grosbachd31d3042011-03-24 18:46:34 +000037 SeparatorString = ";";
Daniel Dunbar73163f82010-02-05 07:32:18 +000038 CommentColumn = 40;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000039 CommentString = "#";
Chris Lattnere07b75e2010-09-22 22:19:53 +000040 LabelSuffix = ":";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000041 GlobalPrefix = "";
42 PrivateGlobalPrefix = ".";
Chris Lattner90f8b702009-07-21 17:30:51 +000043 LinkerPrivateGlobalPrefix = "";
Chris Lattnere2b06012009-08-11 22:39:40 +000044 InlineAsmStart = "APP";
45 InlineAsmEnd = "NO_APP";
Evan Chengbd27f5a2011-07-27 00:38:12 +000046 Code16Directive = ".code16";
47 Code32Directive = ".code32";
48 Code64Directive = ".code64";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000049 AssemblerDialect = 0;
Chris Lattnera93ca922009-06-18 23:41:35 +000050 AllowQuotesInName = false;
Anton Korobeynikovc6f729e2009-09-18 16:57:42 +000051 AllowNameToStartWithDigit = false;
Mon P Wangb9a01bc2010-04-29 04:00:56 +000052 AllowPeriodsInName = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000053 ZeroDirective = "\t.zero\t";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000054 AsciiDirective = "\t.ascii\t";
55 AscizDirective = "\t.asciz\t";
56 Data8bitsDirective = "\t.byte\t";
57 Data16bitsDirective = "\t.short\t";
58 Data32bitsDirective = "\t.long\t";
59 Data64bitsDirective = "\t.quad\t";
Owen Anderson2fec6c52011-10-04 23:26:17 +000060 DataBegin = "$d.";
61 CodeBegin = "$a.";
62 JT8Begin = "$d.";
63 JT16Begin = "$d.";
64 JT32Begin = "$d.";
Owen Anderson5d6a6732011-10-14 20:28:57 +000065 SupportsDataRegions = false;
Chris Lattner5277b222009-08-08 20:43:12 +000066 SunStyleELFSectionSwitchSyntax = false;
Bruno Cardoso Lopesfdf229e2009-08-13 23:30:21 +000067 UsesELFSectionDirectiveForBSS = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000068 AlignDirective = "\t.align\t";
69 AlignmentIsInBytes = true;
70 TextAlignFillValue = 0;
Chris Lattner78f485a2010-01-25 21:10:10 +000071 GPRel32Directive = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000072 GlobalDirective = "\t.globl\t";
Chris Lattnercee63322010-01-26 20:40:54 +000073 HasSetDirective = true;
Rafael Espindola90a5a0c2010-12-22 21:51:29 +000074 HasAggressiveSymbolFolding = true;
Benjamin Kramer36a16012011-09-01 23:04:27 +000075 LCOMMDirectiveType = LCOMM::None;
Rafael Espindola2e2563b2010-01-26 20:21:43 +000076 COMMDirectiveAlignmentIsInBytes = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000077 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000078 HasSingleParameterDotFile = true;
Chris Lattner3a9be0e2010-01-23 05:51:36 +000079 HasNoDeadStrip = false;
Kevin Enderbye8e98d72010-11-19 18:39:33 +000080 HasSymbolResolver = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000081 WeakRefDirective = 0;
82 WeakDefDirective = 0;
Chris Lattner41eb8b42010-01-19 05:08:13 +000083 LinkOnceDirective = 0;
Chris Lattner152a29b2010-01-23 06:53:23 +000084 HiddenVisibilityAttr = MCSA_Hidden;
Stuart Hastings5129bde2011-02-23 02:27:05 +000085 HiddenDeclarationVisibilityAttr = MCSA_Hidden;
Chris Lattner152a29b2010-01-23 06:53:23 +000086 ProtectedVisibilityAttr = MCSA_Protected;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000087 HasLEB128 = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000088 SupportsDebugInformation = false;
Jim Grosbach1b747ad2009-08-11 00:09:57 +000089 ExceptionsType = ExceptionHandling::None;
Devang Patel0f7fef32009-04-13 17:02:03 +000090 DwarfUsesInlineInfoSection = false;
Rafael Espindoladc52ecf2011-05-10 20:35:05 +000091 DwarfRequiresRelocationForSectionOffset = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000092 DwarfSectionOffsetDirective = 0;
Devang Patelb1fcfbe2010-09-02 16:43:44 +000093 DwarfUsesLabelOffsetForRanges = true;
Nick Lewycky390c40d2011-10-27 06:44:11 +000094 DwarfUsesRelocationsForStringPool = true;
Akira Hatanaka3014b2f2011-07-07 20:30:33 +000095 DwarfRegNumForCFI = false;
Chris Lattner8a29fa62010-03-12 21:03:47 +000096 HasMicrosoftFastStdCallMangling = false;
Chris Lattner18a4c162009-08-02 07:24:22 +000097
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000098 AsmTransCBE = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +000099}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000100
Chris Lattneraf76e592009-08-22 20:48:53 +0000101MCAsmInfo::~MCAsmInfo() {
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000102}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000103
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000104
Chris Lattneraf76e592009-08-22 20:48:53 +0000105unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000106 unsigned Size = 0;
107 do {
108 Value >>= 7;
109 Size += sizeof(int8_t);
110 } while (Value);
111 return Size;
112}
113
Chris Lattneraf76e592009-08-22 20:48:53 +0000114unsigned MCAsmInfo::getSLEB128Size(int Value) {
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000115 unsigned Size = 0;
116 int Sign = Value >> (8 * sizeof(Value) - 1);
117 bool IsMore;
118
119 do {
120 unsigned Byte = Value & 0x7f;
121 Value >>= 7;
122 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
123 Size += sizeof(int8_t);
124 } while (IsMore);
125 return Size;
126}
Rafael Espindolabfa27cc2011-04-28 16:09:09 +0000127
128const MCExpr *
129MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
Rafael Espindoladebd7e42011-05-01 03:50:49 +0000130 unsigned Encoding,
Rafael Espindolabfa27cc2011-04-28 16:09:09 +0000131 MCStreamer &Streamer) const {
Rafael Espindoladebd7e42011-05-01 03:50:49 +0000132 return getExprForFDESymbol(Sym, Encoding, Streamer);
Rafael Espindolaa0057ca2011-04-28 21:04:39 +0000133}
134
135const MCExpr *
136MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
Rafael Espindoladebd7e42011-05-01 03:50:49 +0000137 unsigned Encoding,
Rafael Espindolaa0057ca2011-04-28 21:04:39 +0000138 MCStreamer &Streamer) const {
Rafael Espindoladebd7e42011-05-01 03:50:49 +0000139 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
140 return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
141
142 MCContext &Context = Streamer.getContext();
143 const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
144 MCSymbol *PCSym = Context.CreateTempSymbol();
145 Streamer.EmitLabel(PCSym);
146 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
147 return MCBinaryExpr::CreateSub(Res, PC, Context);
Rafael Espindolabfa27cc2011-04-28 16:09:09 +0000148}