blob: e751a6d9fc3b07ec3febd9d14a7e3600f9c101da [file] [log] [blame]
Daniel Dunbara11af532009-06-24 01:03:06 +00001//===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/MC/MCStreamer.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000011#include "llvm/ADT/OwningPtr.h"
12#include "llvm/ADT/SmallString.h"
13#include "llvm/ADT/StringExtras.h"
14#include "llvm/ADT/Twine.h"
15#include "llvm/MC/MCAsmBackend.h"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000016#include "llvm/MC/MCAsmInfo.h"
Daniel Dunbar4a0abd82009-08-27 00:51:57 +000017#include "llvm/MC/MCCodeEmitter.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000018#include "llvm/MC/MCContext.h"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000019#include "llvm/MC/MCExpr.h"
Daniel Dunbar2761fc42010-12-16 03:20:06 +000020#include "llvm/MC/MCFixupKindInfo.h"
Daniel Dunbarabde2982009-07-01 06:35:03 +000021#include "llvm/MC/MCInst.h"
Chris Lattner90edac02009-09-14 03:02:37 +000022#include "llvm/MC/MCInstPrinter.h"
Evan Chengbfe36862011-07-26 20:57:44 +000023#include "llvm/MC/MCObjectFileInfo.h"
Evan Cheng0e6a0522011-07-18 20:57:22 +000024#include "llvm/MC/MCRegisterInfo.h"
Evan Chenge76a33b2011-07-20 05:58:47 +000025#include "llvm/MC/MCSectionCOFF.h"
Chris Lattnerf9bdedd2009-08-10 18:15:01 +000026#include "llvm/MC/MCSectionMachO.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000027#include "llvm/MC/MCSymbol.h"
Rafael Espindola5e195a42013-10-05 16:42:21 +000028#include "llvm/Support/CommandLine.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000029#include "llvm/Support/ErrorHandling.h"
Daniel Dunbar4a0abd82009-08-27 00:51:57 +000030#include "llvm/Support/Format.h"
Chris Lattner86e22112010-01-22 07:29:22 +000031#include "llvm/Support/FormattedStream.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000032#include "llvm/Support/MathExtras.h"
Rafael Espindolaa11c3e22013-06-11 22:21:28 +000033#include "llvm/Support/Path.h"
Nick Lewycky476b2422010-12-19 20:43:38 +000034#include <cctype>
Daniel Dunbara11af532009-06-24 01:03:06 +000035using namespace llvm;
36
37namespace {
38
Chris Lattner46a947d2009-08-17 04:17:34 +000039class MCAsmStreamer : public MCStreamer {
Bill Wendling916a94b2011-06-17 20:35:21 +000040protected:
Chris Lattner86e22112010-01-22 07:29:22 +000041 formatted_raw_ostream &OS;
Bill Wendling99cb6222013-06-18 07:20:20 +000042 const MCAsmInfo *MAI;
Bill Wendling916a94b2011-06-17 20:35:21 +000043private:
Chris Lattner4c42a6d2010-03-19 05:48:53 +000044 OwningPtr<MCInstPrinter> InstPrinter;
Benjamin Kramer1abcd062010-07-29 17:48:06 +000045 OwningPtr<MCCodeEmitter> Emitter;
Evan Cheng78c10ee2011-07-25 23:24:55 +000046 OwningPtr<MCAsmBackend> AsmBackend;
Jim Grosbach00545e12010-09-22 18:16:55 +000047
Chris Lattner86e22112010-01-22 07:29:22 +000048 SmallString<128> CommentToEmit;
Chris Lattnerd79d9dc2010-01-22 19:17:48 +000049 raw_svector_ostream CommentStream;
Daniel Dunbar9dee8e32010-02-03 18:18:30 +000050
Daniel Dunbar9dee8e32010-02-03 18:18:30 +000051 unsigned IsVerboseAsm : 1;
52 unsigned ShowInst : 1;
Rafael Espindola89b93722010-12-10 07:39:47 +000053 unsigned UseLoc : 1;
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +000054 unsigned UseCFI : 1;
Nick Lewycky44d798d2011-10-17 23:05:28 +000055 unsigned UseDwarfDirectory : 1;
Daniel Dunbar9dee8e32010-02-03 18:18:30 +000056
Rafael Espindola277abc82011-04-30 16:34:57 +000057 enum EHSymbolFlags { EHGlobal = 1,
58 EHWeakDefinition = 1 << 1,
59 EHPrivateExtern = 1 << 2 };
60 DenseMap<const MCSymbol*, unsigned> FlagMap;
61
Rafael Espindola5d4918d2010-12-04 03:21:47 +000062 bool needsSet(const MCExpr *Value);
63
Rafael Espindola6e032942011-05-30 20:20:15 +000064 void EmitRegisterName(int64_t Register);
Rafael Espindola547be262012-01-07 22:42:19 +000065 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
Rafael Espindola1fe97372012-01-09 00:17:29 +000066 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame);
Rafael Espindola6e032942011-05-30 20:20:15 +000067
Chris Lattner46a947d2009-08-17 04:17:34 +000068public:
Rafael Espindola320296a2013-10-08 13:08:17 +000069 MCAsmStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer,
70 formatted_raw_ostream &os, bool isVerboseAsm, bool useLoc,
71 bool useCFI, bool useDwarfDirectory, MCInstPrinter *printer,
72 MCCodeEmitter *emitter, MCAsmBackend *asmbackend, bool showInst)
73 : MCStreamer(Context, TargetStreamer), OS(os), MAI(Context.getAsmInfo()),
74 InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend),
75 CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
76 ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI),
77 UseDwarfDirectory(useDwarfDirectory) {
Chris Lattner5d672cf2010-02-10 00:10:18 +000078 if (InstPrinter && IsVerboseAsm)
79 InstPrinter->setCommentStream(CommentStream);
80 }
Chris Lattner46a947d2009-08-17 04:17:34 +000081 ~MCAsmStreamer() {}
Daniel Dunbara11af532009-06-24 01:03:06 +000082
Chris Lattner86e22112010-01-22 07:29:22 +000083 inline void EmitEOL() {
Chris Lattnerd79d9dc2010-01-22 19:17:48 +000084 // If we don't have any comments, just emit a \n.
85 if (!IsVerboseAsm) {
Chris Lattner86e22112010-01-22 07:29:22 +000086 OS << '\n';
87 return;
88 }
89 EmitCommentsAndEOL();
90 }
91 void EmitCommentsAndEOL();
Chris Lattner56591ab2010-02-02 23:37:42 +000092
93 /// isVerboseAsm - Return true if this streamer supports verbose assembly at
94 /// all.
95 virtual bool isVerboseAsm() const { return IsVerboseAsm; }
Jim Grosbach00545e12010-09-22 18:16:55 +000096
Chris Lattner91bead72010-04-03 21:35:55 +000097 /// hasRawTextSupport - We support EmitRawText.
98 virtual bool hasRawTextSupport() const { return true; }
Daniel Dunbar6b716532010-02-09 23:00:14 +000099
Chris Lattnerd32c7cf2010-01-22 18:21:35 +0000100 /// AddComment - Add a comment that can be emitted to the generated .s
Chris Lattner86e22112010-01-22 07:29:22 +0000101 /// file if applicable as a QoI issue to make the output of the compiler
102 /// more readable. This only affects the MCAsmStreamer, and only when
103 /// verbose assembly output is enabled.
Chris Lattnerd32c7cf2010-01-22 18:21:35 +0000104 virtual void AddComment(const Twine &T);
Daniel Dunbar6b716532010-02-09 23:00:14 +0000105
106 /// AddEncodingComment - Add a comment showing the encoding of an instruction.
107 virtual void AddEncodingComment(const MCInst &Inst);
108
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000109 /// GetCommentOS - Return a raw_ostream that comments can be written to.
110 /// Unlike AddComment, you are required to terminate comments with \n if you
111 /// use this method.
112 virtual raw_ostream &GetCommentOS() {
113 if (!IsVerboseAsm)
114 return nulls(); // Discard comments unless in verbose asm mode.
115 return CommentStream;
116 }
Daniel Dunbar6b716532010-02-09 23:00:14 +0000117
Chris Lattner0fd90fd2010-01-22 19:52:01 +0000118 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
119 virtual void AddBlankLine() {
120 EmitEOL();
121 }
Daniel Dunbar6b716532010-02-09 23:00:14 +0000122
Chris Lattner46a947d2009-08-17 04:17:34 +0000123 /// @name MCStreamer Interface
124 /// @{
Daniel Dunbara11af532009-06-24 01:03:06 +0000125
Peter Collingbournedf39be62013-04-17 21:18:16 +0000126 virtual void ChangeSection(const MCSection *Section,
127 const MCExpr *Subsection);
Daniel Dunbara11af532009-06-24 01:03:06 +0000128
Rafael Espindolad80781b2010-09-15 21:48:40 +0000129 virtual void InitSections() {
Eli Bendersky030f63a2013-01-14 19:04:57 +0000130 InitToTextSection();
131 }
132
133 virtual void InitToTextSection() {
Nico Rieckef1762b2013-04-14 21:18:36 +0000134 SwitchSection(getContext().getObjectFileInfo()->getTextSection());
Rafael Espindolad80781b2010-09-15 21:48:40 +0000135 }
136
Chris Lattner46a947d2009-08-17 04:17:34 +0000137 virtual void EmitLabel(MCSymbol *Symbol);
Reed Kotler2c3a4642012-12-16 04:00:45 +0000138 virtual void EmitDebugLabel(MCSymbol *Symbol);
139
Rafael Espindola277abc82011-04-30 16:34:57 +0000140 virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
141 MCSymbol *EHSymbol);
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000142 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Daniel Dunbarcddd2362013-01-18 01:25:48 +0000143 virtual void EmitLinkerOptions(ArrayRef<std::string> Options);
Jim Grosbach3e965312012-05-18 19:12:01 +0000144 virtual void EmitDataRegion(MCDataRegionType Kind);
Jim Grosbachce792992010-11-05 22:08:08 +0000145 virtual void EmitThumbFunc(MCSymbol *Func);
Daniel Dunbara11af532009-06-24 01:03:06 +0000146
Daniel Dunbar821e3332009-08-31 08:09:28 +0000147 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
Rafael Espindola484291c2010-11-01 14:28:48 +0000148 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
Rafael Espindola32a006e2010-12-03 00:55:40 +0000149 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
150 const MCSymbol *LastLabel,
Evan Cheng672b93a2011-07-14 05:43:07 +0000151 const MCSymbol *Label,
152 unsigned PointerSize);
Rafael Espindolaa37bd1d2011-04-30 03:21:04 +0000153 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
154 const MCSymbol *Label);
Daniel Dunbara11af532009-06-24 01:03:06 +0000155
Saleem Abdulrasool1c9cd022013-08-09 01:52:03 +0000156 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
Kevin Enderbya5c78322009-07-13 21:03:15 +0000157
Chris Lattner46a947d2009-08-17 04:17:34 +0000158 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
Chris Lattnerb54b9dd2010-05-08 19:54:22 +0000159 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
160 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
161 virtual void EmitCOFFSymbolType(int Type);
162 virtual void EndCOFFSymbolDef();
Rafael Espindola8f7d12c2011-12-17 01:14:52 +0000163 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
Chris Lattner99328ad2010-01-25 07:52:13 +0000164 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
Chris Lattner9eb158d2010-01-23 07:47:02 +0000165 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000166 unsigned ByteAlignment);
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000167
Chris Lattner9eb158d2010-01-23 07:47:02 +0000168 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
169 ///
170 /// @param Symbol - The common symbol to emit.
171 /// @param Size - The size of the common symbol.
Dmitri Gribenkoa00b80b2012-08-23 16:54:08 +0000172 /// @param ByteAlignment - The alignment of the common symbol in bytes.
Benjamin Kramer36a16012011-09-01 23:04:27 +0000173 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
174 unsigned ByteAlignment);
Jim Grosbach00545e12010-09-22 18:16:55 +0000175
Daniel Dunbar8751b942009-08-28 05:48:22 +0000176 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
Evan Chengc90a1fc2012-06-22 20:14:46 +0000177 uint64_t Size = 0, unsigned ByteAlignment = 0);
Kevin Enderby71148242009-07-14 21:35:03 +0000178
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000179 virtual void EmitTBSSSymbol (const MCSection *Section, MCSymbol *Symbol,
180 uint64_t Size, unsigned ByteAlignment = 0);
Jim Grosbach00545e12010-09-22 18:16:55 +0000181
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000182 virtual void EmitBytes(StringRef Data);
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000183
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000184 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size);
185 virtual void EmitIntValue(uint64_t Value, unsigned Size);
Rafael Espindola3ff57092010-11-02 17:22:24 +0000186
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000187 virtual void EmitULEB128Value(const MCExpr *Value);
Rafael Espindola3ff57092010-11-02 17:22:24 +0000188
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000189 virtual void EmitSLEB128Value(const MCExpr *Value);
Rafael Espindola3ff57092010-11-02 17:22:24 +0000190
Akira Hatanaka6c2cf8b2012-02-03 04:33:00 +0000191 virtual void EmitGPRel64Value(const MCExpr *Value);
192
Chris Lattner718fb592010-01-25 21:28:50 +0000193 virtual void EmitGPRel32Value(const MCExpr *Value);
Jim Grosbach00545e12010-09-22 18:16:55 +0000194
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000195
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000196 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
Chris Lattner9be3fee2009-07-10 22:20:30 +0000197
Chris Lattner46a947d2009-08-17 04:17:34 +0000198 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
199 unsigned ValueSize = 1,
200 unsigned MaxBytesToEmit = 0);
Daniel Dunbara11af532009-06-24 01:03:06 +0000201
Kevin Enderby6e720482010-02-23 18:26:34 +0000202 virtual void EmitCodeAlignment(unsigned ByteAlignment,
203 unsigned MaxBytesToEmit = 0);
204
Jim Grosbachebd4c052012-01-27 00:37:08 +0000205 virtual bool EmitValueToOffset(const MCExpr *Offset,
Chris Lattner46a947d2009-08-17 04:17:34 +0000206 unsigned char Value = 0);
Daniel Dunbara11af532009-06-24 01:03:06 +0000207
Chris Lattnera6594fc2010-01-25 18:58:59 +0000208 virtual void EmitFileDirective(StringRef Filename);
Nick Lewycky44d798d2011-10-17 23:05:28 +0000209 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
Manman Ren3de61b42013-03-07 01:42:00 +0000210 StringRef Filename, unsigned CUID = 0);
Rafael Espindolaaf6b58082010-11-16 21:20:32 +0000211 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
212 unsigned Column, unsigned Flags,
Devang Patel3f3bf932011-04-18 20:26:49 +0000213 unsigned Isa, unsigned Discriminator,
214 StringRef FileName);
Chris Lattnera6594fc2010-01-25 18:58:59 +0000215
Rafael Espindolac7ce3e42013-10-16 01:05:45 +0000216 virtual void EmitIdent(StringRef IdentString);
Rafael Espindola713c4bf2011-05-10 13:39:48 +0000217 virtual void EmitCFISections(bool EH, bool Debug);
Rafael Espindola066c2f42011-04-12 23:59:07 +0000218 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
219 virtual void EmitCFIDefCfaOffset(int64_t Offset);
220 virtual void EmitCFIDefCfaRegister(int64_t Register);
221 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
222 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
223 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
224 virtual void EmitCFIRememberState();
225 virtual void EmitCFIRestoreState();
226 virtual void EmitCFISameValue(int64_t Register);
227 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
228 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
Rafael Espindola16d7d432012-01-23 21:51:52 +0000229 virtual void EmitCFISignalFrame();
Rafael Espindolac8fec7e2012-11-23 16:59:41 +0000230 virtual void EmitCFIUndefined(int64_t Register);
Rafael Espindolaf4f14f62012-11-25 15:14:49 +0000231 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
Venkatraman Govindaraju83ba58e2013-09-26 14:49:40 +0000232 virtual void EmitCFIWindowSave();
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000233
Charles Davisfbc539f2011-05-22 21:12:15 +0000234 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
Charles Davis0e30f022011-05-18 04:58:05 +0000235 virtual void EmitWin64EHEndProc();
Charles Davisf0709012011-05-18 20:54:10 +0000236 virtual void EmitWin64EHStartChained();
237 virtual void EmitWin64EHEndChained();
Charles Davis440596f2011-05-19 17:46:39 +0000238 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
239 bool Except);
240 virtual void EmitWin64EHHandlerData();
Charles Davisc3b16282011-05-19 19:35:55 +0000241 virtual void EmitWin64EHPushReg(unsigned Register);
242 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
243 virtual void EmitWin64EHAllocStack(unsigned Size);
244 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
245 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
Charles Davis0e30f022011-05-18 04:58:05 +0000246 virtual void EmitWin64EHPushFrame(bool Code);
247 virtual void EmitWin64EHEndProlog();
248
Chris Lattnera6594fc2010-01-25 18:58:59 +0000249 virtual void EmitInstruction(const MCInst &Inst);
Jim Grosbach00545e12010-09-22 18:16:55 +0000250
Eli Bendersky4766ef42012-12-20 19:05:53 +0000251 virtual void EmitBundleAlignMode(unsigned AlignPow2);
Eli Bendersky6c1d4972013-01-07 21:51:08 +0000252 virtual void EmitBundleLock(bool AlignToEnd);
Eli Bendersky4766ef42012-12-20 19:05:53 +0000253 virtual void EmitBundleUnlock();
254
Jim Grosbachbd4ec842010-09-22 18:18:30 +0000255 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
Chris Lattner91bead72010-04-03 21:35:55 +0000256 /// the specified string in the output .s file. This capability is
257 /// indicated by the hasRawTextSupport() predicate.
258 virtual void EmitRawText(StringRef String);
Jim Grosbach00545e12010-09-22 18:16:55 +0000259
Rafael Espindola99b42372012-01-07 03:13:18 +0000260 virtual void FinishImpl();
Chris Lattner46a947d2009-08-17 04:17:34 +0000261};
Daniel Dunbar84a29262009-06-24 19:25:34 +0000262
Chris Lattner46a947d2009-08-17 04:17:34 +0000263} // end anonymous namespace.
Daniel Dunbara11af532009-06-24 01:03:06 +0000264
Chris Lattnerd32c7cf2010-01-22 18:21:35 +0000265/// AddComment - Add a comment that can be emitted to the generated .s
Chris Lattner86e22112010-01-22 07:29:22 +0000266/// file if applicable as a QoI issue to make the output of the compiler
267/// more readable. This only affects the MCAsmStreamer, and only when
268/// verbose assembly output is enabled.
Chris Lattnerd32c7cf2010-01-22 18:21:35 +0000269void MCAsmStreamer::AddComment(const Twine &T) {
Chris Lattner86e22112010-01-22 07:29:22 +0000270 if (!IsVerboseAsm) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000271
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000272 // Make sure that CommentStream is flushed.
273 CommentStream.flush();
Jim Grosbach00545e12010-09-22 18:16:55 +0000274
Chris Lattner86e22112010-01-22 07:29:22 +0000275 T.toVector(CommentToEmit);
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000276 // Each comment goes on its own line.
277 CommentToEmit.push_back('\n');
Jim Grosbach00545e12010-09-22 18:16:55 +0000278
Chris Lattner14ca1772010-01-22 21:16:10 +0000279 // Tell the comment stream that the vector changed underneath it.
280 CommentStream.resync();
Chris Lattner86e22112010-01-22 07:29:22 +0000281}
282
283void MCAsmStreamer::EmitCommentsAndEOL() {
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000284 if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
285 OS << '\n';
286 return;
287 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000288
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000289 CommentStream.flush();
Chris Lattner86e22112010-01-22 07:29:22 +0000290 StringRef Comments = CommentToEmit.str();
Jim Grosbach00545e12010-09-22 18:16:55 +0000291
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000292 assert(Comments.back() == '\n' &&
293 "Comment array not newline terminated");
294 do {
Chris Lattner86e22112010-01-22 07:29:22 +0000295 // Emit a line of comments.
Bill Wendling99cb6222013-06-18 07:20:20 +0000296 OS.PadToColumn(MAI->getCommentColumn());
Chris Lattner86e22112010-01-22 07:29:22 +0000297 size_t Position = Comments.find('\n');
Bill Wendling99cb6222013-06-18 07:20:20 +0000298 OS << MAI->getCommentString() << ' ' << Comments.substr(0, Position) <<'\n';
Jim Grosbach00545e12010-09-22 18:16:55 +0000299
Chris Lattner86e22112010-01-22 07:29:22 +0000300 Comments = Comments.substr(Position+1);
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000301 } while (!Comments.empty());
Jim Grosbach00545e12010-09-22 18:16:55 +0000302
Chris Lattner14ca1772010-01-22 21:16:10 +0000303 CommentToEmit.clear();
304 // Tell the comment stream that the vector changed underneath it.
305 CommentStream.resync();
Chris Lattner86e22112010-01-22 07:29:22 +0000306}
307
Daniel Dunbar304f6a42009-06-25 21:03:18 +0000308static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
309 assert(Bytes && "Invalid size!");
310 return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
311}
312
Peter Collingbournedf39be62013-04-17 21:18:16 +0000313void MCAsmStreamer::ChangeSection(const MCSection *Section,
314 const MCExpr *Subsection) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000315 assert(Section && "Cannot switch to a null section!");
Bill Wendling99cb6222013-06-18 07:20:20 +0000316 Section->PrintSwitchToSection(*MAI, OS, Subsection);
Daniel Dunbara11af532009-06-24 01:03:06 +0000317}
318
Rafael Espindola277abc82011-04-30 16:34:57 +0000319void MCAsmStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
320 MCSymbol *EHSymbol) {
321 if (UseCFI)
322 return;
323
324 unsigned Flags = FlagMap.lookup(Symbol);
325
326 if (Flags & EHGlobal)
327 EmitSymbolAttribute(EHSymbol, MCSA_Global);
328 if (Flags & EHWeakDefinition)
329 EmitSymbolAttribute(EHSymbol, MCSA_WeakDefinition);
330 if (Flags & EHPrivateExtern)
331 EmitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
332}
333
Daniel Dunbara11af532009-06-24 01:03:06 +0000334void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000335 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
Rafael Espindolaed708f92011-04-27 15:21:19 +0000336 MCStreamer::EmitLabel(Symbol);
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000337
Bill Wendling99cb6222013-06-18 07:20:20 +0000338 OS << *Symbol << MAI->getLabelSuffix();
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000339 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000340}
341
Reed Kotler2c3a4642012-12-16 04:00:45 +0000342void MCAsmStreamer::EmitDebugLabel(MCSymbol *Symbol) {
343 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
344 MCStreamer::EmitDebugLabel(Symbol);
345
Bill Wendling99cb6222013-06-18 07:20:20 +0000346 OS << *Symbol << MAI->getDebugLabelSuffix();
Reed Kotler2c3a4642012-12-16 04:00:45 +0000347 EmitEOL();
348}
349
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000350void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Kevin Enderbyf96db462009-07-16 17:56:39 +0000351 switch (Flag) {
Jason W Kimafd1cc22010-09-30 02:45:56 +0000352 case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000353 case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
Bill Wendling99cb6222013-06-18 07:20:20 +0000354 case MCAF_Code16: OS << '\t'<< MAI->getCode16Directive();break;
355 case MCAF_Code32: OS << '\t'<< MAI->getCode32Directive();break;
356 case MCAF_Code64: OS << '\t'<< MAI->getCode64Directive();break;
Kevin Enderbyf96db462009-07-16 17:56:39 +0000357 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000358 EmitEOL();
Kevin Enderbya5c78322009-07-13 21:03:15 +0000359}
360
Daniel Dunbarcddd2362013-01-18 01:25:48 +0000361void MCAsmStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
362 assert(!Options.empty() && "At least one option is required!");
363 OS << "\t.linker_option \"" << Options[0] << '"';
364 for (ArrayRef<std::string>::iterator it = Options.begin() + 1,
365 ie = Options.end(); it != ie; ++it) {
366 OS << ", " << '"' << *it << '"';
367 }
Daniel Dunbar6d49b682013-01-18 19:37:00 +0000368 OS << "\n";
Daniel Dunbarcddd2362013-01-18 01:25:48 +0000369}
370
Jim Grosbach3e965312012-05-18 19:12:01 +0000371void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000372 if (!MAI->doesSupportDataRegionDirectives())
Jim Grosbach3e965312012-05-18 19:12:01 +0000373 return;
374 switch (Kind) {
375 case MCDR_DataRegion: OS << "\t.data_region"; break;
376 case MCDR_DataRegionJT8: OS << "\t.data_region jt8"; break;
377 case MCDR_DataRegionJT16: OS << "\t.data_region jt16"; break;
378 case MCDR_DataRegionJT32: OS << "\t.data_region jt32"; break;
379 case MCDR_DataRegionEnd: OS << "\t.end_data_region"; break;
380 }
381 EmitEOL();
382}
383
Jim Grosbachce792992010-11-05 22:08:08 +0000384void MCAsmStreamer::EmitThumbFunc(MCSymbol *Func) {
385 // This needs to emit to a temporary string to get properly quoted
386 // MCSymbols when they have spaces in them.
387 OS << "\t.thumb_func";
Rafael Espindola64695402011-05-16 16:17:21 +0000388 // Only Mach-O hasSubsectionsViaSymbols()
Bill Wendling99cb6222013-06-18 07:20:20 +0000389 if (MAI->hasSubsectionsViaSymbols())
Jim Grosbachce792992010-11-05 22:08:08 +0000390 OS << '\t' << *Func;
391 EmitEOL();
392}
393
Daniel Dunbar821e3332009-08-31 08:09:28 +0000394void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000395 OS << *Symbol << " = " << *Value;
396 EmitEOL();
Daniel Dunbarfffff912009-10-16 01:34:54 +0000397
398 // FIXME: Lift context changes into super class.
Daniel Dunbar08a408a2010-05-05 17:41:00 +0000399 Symbol->setVariableValue(Value);
Daniel Dunbara11af532009-06-24 01:03:06 +0000400}
401
Rafael Espindola484291c2010-11-01 14:28:48 +0000402void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
403 OS << ".weakref " << *Alias << ", " << *Symbol;
404 EmitEOL();
405}
406
Rafael Espindola32a006e2010-12-03 00:55:40 +0000407void MCAsmStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
408 const MCSymbol *LastLabel,
Evan Cheng672b93a2011-07-14 05:43:07 +0000409 const MCSymbol *Label,
410 unsigned PointerSize) {
411 EmitDwarfSetLineAddr(LineDelta, Label, PointerSize);
Rafael Espindola32a006e2010-12-03 00:55:40 +0000412}
413
Rafael Espindolaa37bd1d2011-04-30 03:21:04 +0000414void MCAsmStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
415 const MCSymbol *Label) {
416 EmitIntValue(dwarf::DW_CFA_advance_loc4, 1);
417 const MCExpr *AddrDelta = BuildSymbolDiff(getContext(), Label, LastLabel);
Rafael Espindolaa6f26782011-05-19 21:40:34 +0000418 AddrDelta = ForceExpAbs(AddrDelta);
Rafael Espindolaa37bd1d2011-04-30 03:21:04 +0000419 EmitValue(AddrDelta, 4);
420}
421
422
Saleem Abdulrasool1c9cd022013-08-09 01:52:03 +0000423bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000424 MCSymbolAttr Attribute) {
Daniel Dunbara11af532009-06-24 01:03:06 +0000425 switch (Attribute) {
Craig Topper85814382012-02-07 05:05:23 +0000426 case MCSA_Invalid: llvm_unreachable("Invalid symbol attribute");
Chris Lattnered0ab152010-01-25 18:30:45 +0000427 case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function
428 case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
429 case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object
430 case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object
431 case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
432 case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
Rafael Espindolae9c0ff22010-11-13 04:55:06 +0000433 case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
Saleem Abdulrasool1c9cd022013-08-09 01:52:03 +0000434 if (!MAI->hasDotTypeDotSizeDirective())
435 return false; // Symbol attribute not supported
Dan Gohman523d70e2010-02-04 01:42:13 +0000436 OS << "\t.type\t" << *Symbol << ','
Bill Wendling99cb6222013-06-18 07:20:20 +0000437 << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
Chris Lattnered0ab152010-01-25 18:30:45 +0000438 switch (Attribute) {
Saleem Abdulrasool1c9cd022013-08-09 01:52:03 +0000439 default: return false;
Chris Lattnered0ab152010-01-25 18:30:45 +0000440 case MCSA_ELF_TypeFunction: OS << "function"; break;
441 case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
442 case MCSA_ELF_TypeObject: OS << "object"; break;
443 case MCSA_ELF_TypeTLS: OS << "tls_object"; break;
444 case MCSA_ELF_TypeCommon: OS << "common"; break;
445 case MCSA_ELF_TypeNoType: OS << "no_type"; break;
Rafael Espindolae9c0ff22010-11-13 04:55:06 +0000446 case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
Chris Lattnered0ab152010-01-25 18:30:45 +0000447 }
448 EmitEOL();
Saleem Abdulrasool1c9cd022013-08-09 01:52:03 +0000449 return true;
Chris Lattnered0ab152010-01-25 18:30:45 +0000450 case MCSA_Global: // .globl/.global
Bill Wendling99cb6222013-06-18 07:20:20 +0000451 OS << MAI->getGlobalDirective();
Rafael Espindola277abc82011-04-30 16:34:57 +0000452 FlagMap[Symbol] |= EHGlobal;
Chris Lattnered0ab152010-01-25 18:30:45 +0000453 break;
Chris Lattner61abd7b2010-06-21 20:35:01 +0000454 case MCSA_Hidden: OS << "\t.hidden\t"; break;
455 case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
456 case MCSA_Internal: OS << "\t.internal\t"; break;
457 case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break;
458 case MCSA_Local: OS << "\t.local\t"; break;
459 case MCSA_NoDeadStrip: OS << "\t.no_dead_strip\t"; break;
Kevin Enderbye8e98d72010-11-19 18:39:33 +0000460 case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break;
Rafael Espindola277abc82011-04-30 16:34:57 +0000461 case MCSA_PrivateExtern:
462 OS << "\t.private_extern\t";
463 FlagMap[Symbol] |= EHPrivateExtern;
464 break;
Chris Lattner61abd7b2010-06-21 20:35:01 +0000465 case MCSA_Protected: OS << "\t.protected\t"; break;
466 case MCSA_Reference: OS << "\t.reference\t"; break;
467 case MCSA_Weak: OS << "\t.weak\t"; break;
Rafael Espindola277abc82011-04-30 16:34:57 +0000468 case MCSA_WeakDefinition:
469 OS << "\t.weak_definition\t";
470 FlagMap[Symbol] |= EHWeakDefinition;
471 break;
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000472 // .weak_reference
Bill Wendling99cb6222013-06-18 07:20:20 +0000473 case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break;
Kevin Enderbyf59cac52010-07-08 17:22:42 +0000474 case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
Daniel Dunbara11af532009-06-24 01:03:06 +0000475 }
476
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000477 OS << *Symbol;
478 EmitEOL();
Saleem Abdulrasool1c9cd022013-08-09 01:52:03 +0000479
480 return true;
Daniel Dunbara11af532009-06-24 01:03:06 +0000481}
482
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000483void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000484 OS << ".desc" << ' ' << *Symbol << ',' << DescValue;
485 EmitEOL();
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000486}
487
Chris Lattnerb54b9dd2010-05-08 19:54:22 +0000488void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
489 OS << "\t.def\t " << *Symbol << ';';
490 EmitEOL();
491}
492
493void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
494 OS << "\t.scl\t" << StorageClass << ';';
495 EmitEOL();
496}
497
498void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
499 OS << "\t.type\t" << Type << ';';
500 EmitEOL();
501}
502
503void MCAsmStreamer::EndCOFFSymbolDef() {
504 OS << "\t.endef";
505 EmitEOL();
506}
507
Rafael Espindola8f7d12c2011-12-17 01:14:52 +0000508void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
509 OS << "\t.secrel32\t" << *Symbol << '\n';
510 EmitEOL();
511}
512
Chris Lattner99328ad2010-01-25 07:52:13 +0000513void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000514 assert(MAI->hasDotTypeDotSizeDirective());
Chris Lattner99328ad2010-01-25 07:52:13 +0000515 OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
516}
517
Chris Lattner9eb158d2010-01-23 07:47:02 +0000518void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000519 unsigned ByteAlignment) {
Richard Mittoneb46def2013-09-23 17:56:20 +0000520 // Common symbols do not belong to any actual section.
521 AssignSection(Symbol, NULL);
Richard Mitton5cc319a2013-09-19 23:21:01 +0000522
Chris Lattner9eb158d2010-01-23 07:47:02 +0000523 OS << "\t.comm\t" << *Symbol << ',' << Size;
Chris Lattner6559d762010-01-25 07:29:13 +0000524 if (ByteAlignment != 0) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000525 if (MAI->getCOMMDirectiveAlignmentIsInBytes())
Chris Lattner4ed54382010-01-19 06:01:04 +0000526 OS << ',' << ByteAlignment;
527 else
528 OS << ',' << Log2_32(ByteAlignment);
529 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000530 EmitEOL();
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000531}
532
Chris Lattner9eb158d2010-01-23 07:47:02 +0000533/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
534///
535/// @param Symbol - The common symbol to emit.
536/// @param Size - The size of the common symbol.
Benjamin Kramer36a16012011-09-01 23:04:27 +0000537void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
538 unsigned ByteAlign) {
Richard Mittoneb46def2013-09-23 17:56:20 +0000539 // Common symbols do not belong to any actual section.
540 AssignSection(Symbol, NULL);
Richard Mitton5cc319a2013-09-19 23:21:01 +0000541
Chris Lattner9eb158d2010-01-23 07:47:02 +0000542 OS << "\t.lcomm\t" << *Symbol << ',' << Size;
Benjamin Kramer36a16012011-09-01 23:04:27 +0000543 if (ByteAlign > 1) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000544 switch (MAI->getLCOMMDirectiveAlignmentType()) {
Benjamin Kramera9e37c52012-09-07 21:08:01 +0000545 case LCOMM::NoAlignment:
546 llvm_unreachable("alignment not supported on .lcomm!");
547 case LCOMM::ByteAlignment:
Benjamin Kramer39646d92012-09-07 17:25:13 +0000548 OS << ',' << ByteAlign;
Benjamin Kramera9e37c52012-09-07 21:08:01 +0000549 break;
550 case LCOMM::Log2Alignment:
Benjamin Kramer39646d92012-09-07 17:25:13 +0000551 assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2");
552 OS << ',' << Log2_32(ByteAlign);
Benjamin Kramera9e37c52012-09-07 21:08:01 +0000553 break;
Benjamin Kramer39646d92012-09-07 17:25:13 +0000554 }
Benjamin Kramer36a16012011-09-01 23:04:27 +0000555 }
Chris Lattner9eb158d2010-01-23 07:47:02 +0000556 EmitEOL();
557}
558
Daniel Dunbar8751b942009-08-28 05:48:22 +0000559void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Evan Chengc90a1fc2012-06-22 20:14:46 +0000560 uint64_t Size, unsigned ByteAlignment) {
Richard Mitton5cc319a2013-09-19 23:21:01 +0000561 if (Symbol)
562 AssignSection(Symbol, Section);
563
Daniel Dunbar011e4db2009-08-13 23:36:34 +0000564 // Note: a .zerofill directive does not switch sections.
Chris Lattner93b6db32009-08-08 23:39:42 +0000565 OS << ".zerofill ";
Jim Grosbach00545e12010-09-22 18:16:55 +0000566
Chris Lattner93b6db32009-08-08 23:39:42 +0000567 // This is a mach-o specific directive.
Chris Lattnerff4bc462009-08-10 01:39:42 +0000568 const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
Daniel Dunbar12de0df2009-08-14 18:51:45 +0000569 OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
Jim Grosbach00545e12010-09-22 18:16:55 +0000570
Chris Lattner9be3fee2009-07-10 22:20:30 +0000571 if (Symbol != NULL) {
Chris Lattner10b318b2010-01-17 21:43:43 +0000572 OS << ',' << *Symbol << ',' << Size;
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000573 if (ByteAlignment != 0)
574 OS << ',' << Log2_32(ByteAlignment);
Chris Lattner9be3fee2009-07-10 22:20:30 +0000575 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000576 EmitEOL();
Chris Lattner9be3fee2009-07-10 22:20:30 +0000577}
578
Eric Christopherd04d98d2010-05-17 02:13:02 +0000579// .tbss sym, size, align
580// This depends that the symbol has already been mangled from the original,
581// e.g. _a.
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000582void MCAsmStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
583 uint64_t Size, unsigned ByteAlignment) {
Richard Mitton5cc319a2013-09-19 23:21:01 +0000584 AssignSection(Symbol, Section);
585
Eric Christopher482eba02010-05-14 01:50:28 +0000586 assert(Symbol != NULL && "Symbol shouldn't be NULL!");
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000587 // Instead of using the Section we'll just use the shortcut.
588 // This is a mach-o specific directive and section.
Eric Christopherd04d98d2010-05-17 02:13:02 +0000589 OS << ".tbss " << *Symbol << ", " << Size;
Jim Grosbach00545e12010-09-22 18:16:55 +0000590
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000591 // Output align if we have it. We default to 1 so don't bother printing
592 // that.
593 if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
Jim Grosbach00545e12010-09-22 18:16:55 +0000594
Eric Christopher482eba02010-05-14 01:50:28 +0000595 EmitEOL();
596}
597
Chris Lattner12e555c2010-01-23 00:15:00 +0000598static inline char toOctal(int X) { return (X&7)+'0'; }
599
Chris Lattnera6594fc2010-01-25 18:58:59 +0000600static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
601 OS << '"';
Jim Grosbach00545e12010-09-22 18:16:55 +0000602
Chris Lattnera6594fc2010-01-25 18:58:59 +0000603 for (unsigned i = 0, e = Data.size(); i != e; ++i) {
604 unsigned char C = Data[i];
605 if (C == '"' || C == '\\') {
606 OS << '\\' << (char)C;
607 continue;
608 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000609
Chris Lattnera6594fc2010-01-25 18:58:59 +0000610 if (isprint((unsigned char)C)) {
611 OS << (char)C;
612 continue;
613 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000614
Chris Lattnera6594fc2010-01-25 18:58:59 +0000615 switch (C) {
616 case '\b': OS << "\\b"; break;
617 case '\f': OS << "\\f"; break;
618 case '\n': OS << "\\n"; break;
619 case '\r': OS << "\\r"; break;
620 case '\t': OS << "\\t"; break;
621 default:
622 OS << '\\';
623 OS << toOctal(C >> 6);
624 OS << toOctal(C >> 3);
625 OS << toOctal(C >> 0);
626 break;
627 }
628 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000629
Chris Lattnera6594fc2010-01-25 18:58:59 +0000630 OS << '"';
631}
632
633
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000634void MCAsmStreamer::EmitBytes(StringRef Data) {
Peter Collingbournedf39be62013-04-17 21:18:16 +0000635 assert(getCurrentSection().first &&
636 "Cannot emit contents before setting section!");
Chris Lattner12e555c2010-01-23 00:15:00 +0000637 if (Data.empty()) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000638
Chris Lattner12e555c2010-01-23 00:15:00 +0000639 if (Data.size() == 1) {
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000640 OS << MAI->getData8bitsDirective();
Chris Lattner12e555c2010-01-23 00:15:00 +0000641 OS << (unsigned)(unsigned char)Data[0];
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000642 EmitEOL();
Chris Lattner12e555c2010-01-23 00:15:00 +0000643 return;
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000644 }
Chris Lattner12e555c2010-01-23 00:15:00 +0000645
646 // If the data ends with 0 and the target supports .asciz, use it, otherwise
647 // use .ascii
Bill Wendling99cb6222013-06-18 07:20:20 +0000648 if (MAI->getAscizDirective() && Data.back() == 0) {
649 OS << MAI->getAscizDirective();
Chris Lattner12e555c2010-01-23 00:15:00 +0000650 Data = Data.substr(0, Data.size()-1);
651 } else {
Bill Wendling99cb6222013-06-18 07:20:20 +0000652 OS << MAI->getAsciiDirective();
Chris Lattner12e555c2010-01-23 00:15:00 +0000653 }
654
Chris Lattnera6594fc2010-01-25 18:58:59 +0000655 PrintQuotedString(Data, OS);
Chris Lattner12e555c2010-01-23 00:15:00 +0000656 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000657}
658
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000659void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
660 EmitValue(MCConstantExpr::Create(Value, getContext()), Size);
Rafael Espindola2df042c2010-12-03 02:54:21 +0000661}
662
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000663void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size) {
Peter Collingbournedf39be62013-04-17 21:18:16 +0000664 assert(getCurrentSection().first &&
665 "Cannot emit contents before setting section!");
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000666 const char *Directive = 0;
667 switch (Size) {
668 default: break;
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000669 case 1: Directive = MAI->getData8bitsDirective(); break;
670 case 2: Directive = MAI->getData16bitsDirective(); break;
671 case 4: Directive = MAI->getData32bitsDirective(); break;
Chris Lattner5eaa54e2010-01-20 06:45:39 +0000672 case 8:
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000673 Directive = MAI->getData64bitsDirective();
Chris Lattner5eaa54e2010-01-20 06:45:39 +0000674 // If the target doesn't support 64-bit data, emit as two 32-bit halves.
675 if (Directive) break;
Rafael Espindolaec0b4282010-11-28 23:22:44 +0000676 int64_t IntValue;
677 if (!Value->EvaluateAsAbsolute(IntValue))
678 report_fatal_error("Don't know how to emit this value.");
Bill Wendling99cb6222013-06-18 07:20:20 +0000679 if (MAI->isLittleEndian()) {
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000680 EmitIntValue((uint32_t)(IntValue >> 0 ), 4);
681 EmitIntValue((uint32_t)(IntValue >> 32), 4);
Chris Lattner5eaa54e2010-01-20 06:45:39 +0000682 } else {
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000683 EmitIntValue((uint32_t)(IntValue >> 32), 4);
684 EmitIntValue((uint32_t)(IntValue >> 0 ), 4);
Chris Lattner5eaa54e2010-01-20 06:45:39 +0000685 }
686 return;
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000687 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000688
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000689 assert(Directive && "Invalid size for machine code value!");
Chris Lattner718fb592010-01-25 21:28:50 +0000690 OS << Directive << *Value;
Chris Lattner86e22112010-01-22 07:29:22 +0000691 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000692}
693
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000694void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
Rafael Espindolaa4b23ff2010-11-19 04:10:13 +0000695 int64_t IntValue;
696 if (Value->EvaluateAsAbsolute(IntValue)) {
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000697 EmitULEB128IntValue(IntValue);
Rafael Espindolaa4b23ff2010-11-19 04:10:13 +0000698 return;
699 }
Bill Wendling99cb6222013-06-18 07:20:20 +0000700 assert(MAI->hasLEB128() && "Cannot print a .uleb");
Rafael Espindola73873452010-11-04 18:17:08 +0000701 OS << ".uleb128 " << *Value;
Rafael Espindola3ff57092010-11-02 17:22:24 +0000702 EmitEOL();
703}
704
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000705void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
Rafael Espindolaa4b23ff2010-11-19 04:10:13 +0000706 int64_t IntValue;
707 if (Value->EvaluateAsAbsolute(IntValue)) {
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000708 EmitSLEB128IntValue(IntValue);
Rafael Espindolaa4b23ff2010-11-19 04:10:13 +0000709 return;
710 }
Bill Wendling99cb6222013-06-18 07:20:20 +0000711 assert(MAI->hasLEB128() && "Cannot print a .sleb");
Rafael Espindola73873452010-11-04 18:17:08 +0000712 OS << ".sleb128 " << *Value;
Rafael Espindola3ff57092010-11-02 17:22:24 +0000713 EmitEOL();
714}
715
Akira Hatanaka6c2cf8b2012-02-03 04:33:00 +0000716void MCAsmStreamer::EmitGPRel64Value(const MCExpr *Value) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000717 assert(MAI->getGPRel64Directive() != 0);
718 OS << MAI->getGPRel64Directive() << *Value;
Akira Hatanaka6c2cf8b2012-02-03 04:33:00 +0000719 EmitEOL();
720}
721
Chris Lattner718fb592010-01-25 21:28:50 +0000722void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000723 assert(MAI->getGPRel32Directive() != 0);
724 OS << MAI->getGPRel32Directive() << *Value;
Chris Lattner718fb592010-01-25 21:28:50 +0000725 EmitEOL();
726}
727
728
Chris Lattner6113b3d2010-01-19 18:52:28 +0000729/// EmitFill - Emit NumBytes bytes worth of the value specified by
730/// FillValue. This implements directives such as '.space'.
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000731void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
Chris Lattner8a6d7ac2010-01-19 18:58:52 +0000732 if (NumBytes == 0) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000733
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000734 if (const char *ZeroDirective = MAI->getZeroDirective()) {
735 OS << ZeroDirective << NumBytes;
736 if (FillValue != 0)
737 OS << ',' << (int)FillValue;
738 EmitEOL();
739 return;
740 }
Chris Lattneraaec2052010-01-19 19:46:13 +0000741
742 // Emit a byte at a time.
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000743 MCStreamer::EmitFill(NumBytes, FillValue);
Chris Lattner6113b3d2010-01-19 18:52:28 +0000744}
745
Daniel Dunbar84a29262009-06-24 19:25:34 +0000746void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
747 unsigned ValueSize,
748 unsigned MaxBytesToEmit) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000749 // Some assemblers don't support non-power of two alignments, so we always
750 // emit alignments as a power of two if possible.
751 if (isPowerOf2_32(ByteAlignment)) {
Chris Lattner6e579c62009-08-19 06:35:36 +0000752 switch (ValueSize) {
753 default: llvm_unreachable("Invalid size for machine code value!");
Bill Wendling99cb6222013-06-18 07:20:20 +0000754 case 1: OS << MAI->getAlignDirective(); break;
Chris Lattner33adcfb2009-08-22 21:43:10 +0000755 // FIXME: use MAI for this!
Chris Lattner6e579c62009-08-19 06:35:36 +0000756 case 2: OS << ".p2alignw "; break;
757 case 4: OS << ".p2alignl "; break;
758 case 8: llvm_unreachable("Unsupported alignment size!");
759 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000760
Bill Wendling99cb6222013-06-18 07:20:20 +0000761 if (MAI->getAlignmentIsInBytes())
Chris Lattner663c2d22009-08-19 06:12:02 +0000762 OS << ByteAlignment;
763 else
764 OS << Log2_32(ByteAlignment);
Daniel Dunbar84a29262009-06-24 19:25:34 +0000765
Chris Lattner663c2d22009-08-19 06:12:02 +0000766 if (Value || MaxBytesToEmit) {
Chris Lattner579531c2009-09-03 04:01:10 +0000767 OS << ", 0x";
768 OS.write_hex(truncateToSize(Value, ValueSize));
Chris Lattner663c2d22009-08-19 06:12:02 +0000769
Jim Grosbach00545e12010-09-22 18:16:55 +0000770 if (MaxBytesToEmit)
Chris Lattner663c2d22009-08-19 06:12:02 +0000771 OS << ", " << MaxBytesToEmit;
772 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000773 EmitEOL();
Chris Lattner663c2d22009-08-19 06:12:02 +0000774 return;
775 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000776
Chris Lattner663c2d22009-08-19 06:12:02 +0000777 // Non-power of two alignment. This is not widely supported by assemblers.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000778 // FIXME: Parameterize this based on MAI.
Daniel Dunbar84a29262009-06-24 19:25:34 +0000779 switch (ValueSize) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000780 default: llvm_unreachable("Invalid size for machine code value!");
781 case 1: OS << ".balign"; break;
782 case 2: OS << ".balignw"; break;
783 case 4: OS << ".balignl"; break;
784 case 8: llvm_unreachable("Unsupported alignment size!");
Daniel Dunbar84a29262009-06-24 19:25:34 +0000785 }
786
Chris Lattner663c2d22009-08-19 06:12:02 +0000787 OS << ' ' << ByteAlignment;
Daniel Dunbar304f6a42009-06-25 21:03:18 +0000788 OS << ", " << truncateToSize(Value, ValueSize);
Jim Grosbach00545e12010-09-22 18:16:55 +0000789 if (MaxBytesToEmit)
Daniel Dunbar84a29262009-06-24 19:25:34 +0000790 OS << ", " << MaxBytesToEmit;
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000791 EmitEOL();
Daniel Dunbar84a29262009-06-24 19:25:34 +0000792}
793
Kevin Enderby6e720482010-02-23 18:26:34 +0000794void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
795 unsigned MaxBytesToEmit) {
Chris Lattnerec167fd2010-02-23 18:44:31 +0000796 // Emit with a text fill value.
Bill Wendling99cb6222013-06-18 07:20:20 +0000797 EmitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(),
Chris Lattnerec167fd2010-02-23 18:44:31 +0000798 1, MaxBytesToEmit);
Kevin Enderby6e720482010-02-23 18:26:34 +0000799}
800
Jim Grosbachebd4c052012-01-27 00:37:08 +0000801bool MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
Daniel Dunbar84a29262009-06-24 19:25:34 +0000802 unsigned char Value) {
803 // FIXME: Verify that Offset is associated with the current section.
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000804 OS << ".org " << *Offset << ", " << (unsigned) Value;
805 EmitEOL();
Jim Grosbachebd4c052012-01-27 00:37:08 +0000806 return false;
Daniel Dunbar84a29262009-06-24 19:25:34 +0000807}
808
Chris Lattnera6594fc2010-01-25 18:58:59 +0000809
810void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000811 assert(MAI->hasSingleParameterDotFile());
Chris Lattnera6594fc2010-01-25 18:58:59 +0000812 OS << "\t.file\t";
813 PrintQuotedString(Filename, OS);
814 EmitEOL();
815}
816
Nick Lewycky44d798d2011-10-17 23:05:28 +0000817bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
Manman Ren3de61b42013-03-07 01:42:00 +0000818 StringRef Filename, unsigned CUID) {
Nick Lewycky44d798d2011-10-17 23:05:28 +0000819 if (!UseDwarfDirectory && !Directory.empty()) {
820 if (sys::path::is_absolute(Filename))
Manman Ren3de61b42013-03-07 01:42:00 +0000821 return EmitDwarfFileDirective(FileNo, "", Filename, CUID);
Nick Lewycky44d798d2011-10-17 23:05:28 +0000822
823 SmallString<128> FullPathName = Directory;
824 sys::path::append(FullPathName, Filename);
Manman Ren3de61b42013-03-07 01:42:00 +0000825 return EmitDwarfFileDirective(FileNo, "", FullPathName, CUID);
Nick Lewycky44d798d2011-10-17 23:05:28 +0000826 }
827
Rafael Espindola89b93722010-12-10 07:39:47 +0000828 if (UseLoc) {
Rafael Espindola195a0ce2010-11-19 02:26:16 +0000829 OS << "\t.file\t" << FileNo << ' ';
Nick Lewycky44d798d2011-10-17 23:05:28 +0000830 if (!Directory.empty()) {
831 PrintQuotedString(Directory, OS);
832 OS << ' ';
833 }
Rafael Espindola195a0ce2010-11-19 02:26:16 +0000834 PrintQuotedString(Filename, OS);
835 EmitEOL();
Manman Ren3de61b42013-03-07 01:42:00 +0000836 // All .file will belong to a single CUID.
837 CUID = 0;
Rafael Espindola195a0ce2010-11-19 02:26:16 +0000838 }
Manman Ren3de61b42013-03-07 01:42:00 +0000839 return this->MCStreamer::EmitDwarfFileDirective(FileNo, Directory, Filename,
840 CUID);
Rafael Espindolaaf6b58082010-11-16 21:20:32 +0000841}
842
843void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
844 unsigned Column, unsigned Flags,
845 unsigned Isa,
Devang Patel3f3bf932011-04-18 20:26:49 +0000846 unsigned Discriminator,
847 StringRef FileName) {
Rafael Espindola195a0ce2010-11-19 02:26:16 +0000848 this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
Devang Patel3f3bf932011-04-18 20:26:49 +0000849 Isa, Discriminator, FileName);
Rafael Espindola89b93722010-12-10 07:39:47 +0000850 if (!UseLoc)
Rafael Espindola195a0ce2010-11-19 02:26:16 +0000851 return;
852
Rafael Espindolaaf6b58082010-11-16 21:20:32 +0000853 OS << "\t.loc\t" << FileNo << " " << Line << " " << Column;
854 if (Flags & DWARF2_FLAG_BASIC_BLOCK)
855 OS << " basic_block";
856 if (Flags & DWARF2_FLAG_PROLOGUE_END)
857 OS << " prologue_end";
858 if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
859 OS << " epilogue_begin";
860
861 unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags();
862 if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
863 OS << " is_stmt ";
864
865 if (Flags & DWARF2_FLAG_IS_STMT)
866 OS << "1";
867 else
868 OS << "0";
869 }
870
871 if (Isa)
872 OS << "isa " << Isa;
873 if (Discriminator)
874 OS << "discriminator " << Discriminator;
Devang Patel3f3bf932011-04-18 20:26:49 +0000875
876 if (IsVerboseAsm) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000877 OS.PadToColumn(MAI->getCommentColumn());
878 OS << MAI->getCommentString() << ' ' << FileName << ':'
Devang Patel3f3bf932011-04-18 20:26:49 +0000879 << Line << ':' << Column;
880 }
Rafael Espindolaaf6b58082010-11-16 21:20:32 +0000881 EmitEOL();
Chris Lattnera6594fc2010-01-25 18:58:59 +0000882}
883
Rafael Espindolac7ce3e42013-10-16 01:05:45 +0000884void MCAsmStreamer::EmitIdent(StringRef IdentString) {
885 assert(MAI->hasIdentDirective() && ".ident directive not supported");
886 OS << "\t.ident\t";
887 PrintQuotedString(IdentString, OS);
888 EmitEOL();
889}
890
Rafael Espindola713c4bf2011-05-10 13:39:48 +0000891void MCAsmStreamer::EmitCFISections(bool EH, bool Debug) {
892 MCStreamer::EmitCFISections(EH, Debug);
893
894 if (!UseCFI)
895 return;
896
897 OS << "\t.cfi_sections ";
898 if (EH) {
899 OS << ".eh_frame";
900 if (Debug)
901 OS << ", .debug_frame";
902 } else if (Debug) {
903 OS << ".debug_frame";
904 }
905
906 EmitEOL();
907}
908
Rafael Espindola547be262012-01-07 22:42:19 +0000909void MCAsmStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
910 if (!UseCFI) {
911 RecordProcStart(Frame);
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000912 return;
Rafael Espindola547be262012-01-07 22:42:19 +0000913 }
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000914
Anton Korobeynikovc6585202011-01-14 21:57:39 +0000915 OS << "\t.cfi_startproc";
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000916 EmitEOL();
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000917}
918
Rafael Espindola1fe97372012-01-09 00:17:29 +0000919void MCAsmStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
920 if (!UseCFI) {
921 RecordProcEnd(Frame);
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000922 return;
Rafael Espindola1fe97372012-01-09 00:17:29 +0000923 }
924
925 // Put a dummy non-null value in Frame.End to mark that this frame has been
926 // closed.
927 Frame.End = (MCSymbol *) 1;
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000928
Anton Korobeynikovc6585202011-01-14 21:57:39 +0000929 OS << "\t.cfi_endproc";
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000930 EmitEOL();
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000931}
932
Rafael Espindola6e032942011-05-30 20:20:15 +0000933void MCAsmStreamer::EmitRegisterName(int64_t Register) {
Bill Wendling99cb6222013-06-18 07:20:20 +0000934 if (InstPrinter && !MAI->useDwarfRegNumForCFI()) {
935 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
936 unsigned LLVMRegister = MRI->getLLVMRegNum(Register, true);
Rafael Espindolacde4ce42011-06-02 02:34:55 +0000937 InstPrinter->printRegName(OS, LLVMRegister);
Rafael Espindola6e032942011-05-30 20:20:15 +0000938 } else {
939 OS << Register;
940 }
941}
942
Rafael Espindola066c2f42011-04-12 23:59:07 +0000943void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
Rafael Espindola7f46b082011-04-29 21:41:06 +0000944 MCStreamer::EmitCFIDefCfa(Register, Offset);
945
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000946 if (!UseCFI)
947 return;
948
Rafael Espindola6e032942011-05-30 20:20:15 +0000949 OS << "\t.cfi_def_cfa ";
950 EmitRegisterName(Register);
951 OS << ", " << Offset;
Rafael Espindola7f46b082011-04-29 21:41:06 +0000952 EmitEOL();
Rafael Espindola066c2f42011-04-12 23:59:07 +0000953}
954
955void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
956 MCStreamer::EmitCFIDefCfaOffset(Offset);
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000957
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000958 if (!UseCFI)
959 return;
960
Anton Korobeynikovc6585202011-01-14 21:57:39 +0000961 OS << "\t.cfi_def_cfa_offset " << Offset;
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000962 EmitEOL();
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000963}
964
Rafael Espindola066c2f42011-04-12 23:59:07 +0000965void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
966 MCStreamer::EmitCFIDefCfaRegister(Register);
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000967
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000968 if (!UseCFI)
969 return;
970
Rafael Espindola6e032942011-05-30 20:20:15 +0000971 OS << "\t.cfi_def_cfa_register ";
972 EmitRegisterName(Register);
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000973 EmitEOL();
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000974}
975
Rafael Espindola066c2f42011-04-12 23:59:07 +0000976void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
977 this->MCStreamer::EmitCFIOffset(Register, Offset);
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000978
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000979 if (!UseCFI)
980 return;
981
Rafael Espindola6e032942011-05-30 20:20:15 +0000982 OS << "\t.cfi_offset ";
983 EmitRegisterName(Register);
984 OS << ", " << Offset;
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000985 EmitEOL();
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000986}
987
Rafael Espindola066c2f42011-04-12 23:59:07 +0000988void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
Rafael Espindola3a83c402010-12-27 00:36:05 +0000989 unsigned Encoding) {
Rafael Espindola066c2f42011-04-12 23:59:07 +0000990 MCStreamer::EmitCFIPersonality(Sym, Encoding);
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000991
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000992 if (!UseCFI)
993 return;
994
Anton Korobeynikovc6585202011-01-14 21:57:39 +0000995 OS << "\t.cfi_personality " << Encoding << ", " << *Sym;
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000996 EmitEOL();
Rafael Espindolacdfecc82010-11-22 14:27:24 +0000997}
998
Rafael Espindola066c2f42011-04-12 23:59:07 +0000999void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
1000 MCStreamer::EmitCFILsda(Sym, Encoding);
Rafael Espindolacdfecc82010-11-22 14:27:24 +00001001
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +00001002 if (!UseCFI)
1003 return;
1004
Anton Korobeynikovc6585202011-01-14 21:57:39 +00001005 OS << "\t.cfi_lsda " << Encoding << ", " << *Sym;
Rafael Espindolacdfecc82010-11-22 14:27:24 +00001006 EmitEOL();
Rafael Espindola066c2f42011-04-12 23:59:07 +00001007}
Rafael Espindolacdfecc82010-11-22 14:27:24 +00001008
Rafael Espindola066c2f42011-04-12 23:59:07 +00001009void MCAsmStreamer::EmitCFIRememberState() {
1010 MCStreamer::EmitCFIRememberState();
1011
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +00001012 if (!UseCFI)
1013 return;
1014
Rafael Espindola066c2f42011-04-12 23:59:07 +00001015 OS << "\t.cfi_remember_state";
1016 EmitEOL();
1017}
1018
1019void MCAsmStreamer::EmitCFIRestoreState() {
1020 MCStreamer::EmitCFIRestoreState();
1021
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +00001022 if (!UseCFI)
1023 return;
1024
Rafael Espindola066c2f42011-04-12 23:59:07 +00001025 OS << "\t.cfi_restore_state";
1026 EmitEOL();
1027}
1028
1029void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
1030 MCStreamer::EmitCFISameValue(Register);
1031
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +00001032 if (!UseCFI)
1033 return;
1034
Rafael Espindola6e032942011-05-30 20:20:15 +00001035 OS << "\t.cfi_same_value ";
1036 EmitRegisterName(Register);
Rafael Espindola066c2f42011-04-12 23:59:07 +00001037 EmitEOL();
1038}
1039
1040void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
1041 MCStreamer::EmitCFIRelOffset(Register, Offset);
1042
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +00001043 if (!UseCFI)
1044 return;
1045
Rafael Espindola6e032942011-05-30 20:20:15 +00001046 OS << "\t.cfi_rel_offset ";
1047 EmitRegisterName(Register);
1048 OS << ", " << Offset;
Rafael Espindola066c2f42011-04-12 23:59:07 +00001049 EmitEOL();
1050}
1051
1052void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
1053 MCStreamer::EmitCFIAdjustCfaOffset(Adjustment);
1054
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +00001055 if (!UseCFI)
1056 return;
1057
Rafael Espindola066c2f42011-04-12 23:59:07 +00001058 OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
1059 EmitEOL();
Rafael Espindolacdfecc82010-11-22 14:27:24 +00001060}
1061
Rafael Espindola16d7d432012-01-23 21:51:52 +00001062void MCAsmStreamer::EmitCFISignalFrame() {
1063 MCStreamer::EmitCFISignalFrame();
1064
1065 if (!UseCFI)
1066 return;
1067
Eric Christopherfeba1932012-05-31 00:53:18 +00001068 OS << "\t.cfi_signal_frame";
Rafael Espindola16d7d432012-01-23 21:51:52 +00001069 EmitEOL();
1070}
1071
Rafael Espindolac8fec7e2012-11-23 16:59:41 +00001072void MCAsmStreamer::EmitCFIUndefined(int64_t Register) {
1073 MCStreamer::EmitCFIUndefined(Register);
1074
1075 if (!UseCFI)
1076 return;
1077
1078 OS << "\t.cfi_undefined " << Register;
1079 EmitEOL();
1080}
1081
Rafael Espindolaf4f14f62012-11-25 15:14:49 +00001082void MCAsmStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
1083 MCStreamer::EmitCFIRegister(Register1, Register2);
1084
1085 if (!UseCFI)
1086 return;
1087
1088 OS << "\t.cfi_register " << Register1 << ", " << Register2;
1089 EmitEOL();
1090}
1091
Venkatraman Govindaraju83ba58e2013-09-26 14:49:40 +00001092void MCAsmStreamer::EmitCFIWindowSave() {
1093 MCStreamer::EmitCFIWindowSave();
1094
1095 if (!UseCFI)
1096 return;
1097
1098 OS << "\t.cfi_window_save";
1099 EmitEOL();
1100}
1101
Charles Davisfbc539f2011-05-22 21:12:15 +00001102void MCAsmStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) {
Charles Daviscde87e22011-05-20 18:19:22 +00001103 MCStreamer::EmitWin64EHStartProc(Symbol);
1104
Charles Davis440596f2011-05-19 17:46:39 +00001105 OS << ".seh_proc " << *Symbol;
Charles Davis0e30f022011-05-18 04:58:05 +00001106 EmitEOL();
1107}
1108
Charles Davis8b3e5e52011-05-18 22:13:51 +00001109void MCAsmStreamer::EmitWin64EHEndProc() {
Charles Daviscde87e22011-05-20 18:19:22 +00001110 MCStreamer::EmitWin64EHEndProc();
1111
Charles Davis440596f2011-05-19 17:46:39 +00001112 OS << "\t.seh_endproc";
Charles Davis0e30f022011-05-18 04:58:05 +00001113 EmitEOL();
1114}
1115
Charles Davis8b3e5e52011-05-18 22:13:51 +00001116void MCAsmStreamer::EmitWin64EHStartChained() {
Charles Daviscde87e22011-05-20 18:19:22 +00001117 MCStreamer::EmitWin64EHStartChained();
1118
Charles Davis440596f2011-05-19 17:46:39 +00001119 OS << "\t.seh_startchained";
Charles Davisf0709012011-05-18 20:54:10 +00001120 EmitEOL();
1121}
1122
Charles Davis8b3e5e52011-05-18 22:13:51 +00001123void MCAsmStreamer::EmitWin64EHEndChained() {
Charles Daviscde87e22011-05-20 18:19:22 +00001124 MCStreamer::EmitWin64EHEndChained();
1125
Charles Davis440596f2011-05-19 17:46:39 +00001126 OS << "\t.seh_endchained";
Charles Davisf0709012011-05-18 20:54:10 +00001127 EmitEOL();
1128}
1129
Charles Davis440596f2011-05-19 17:46:39 +00001130void MCAsmStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
1131 bool Except) {
Charles Daviscde87e22011-05-20 18:19:22 +00001132 MCStreamer::EmitWin64EHHandler(Sym, Unwind, Except);
1133
Charles Davis440596f2011-05-19 17:46:39 +00001134 OS << "\t.seh_handler " << *Sym;
1135 if (Unwind)
1136 OS << ", @unwind";
1137 if (Except)
1138 OS << ", @except";
Charles Davisf0709012011-05-18 20:54:10 +00001139 EmitEOL();
1140}
1141
Evan Chenge76a33b2011-07-20 05:58:47 +00001142static const MCSection *getWin64EHTableSection(StringRef suffix,
1143 MCContext &context) {
1144 // FIXME: This doesn't belong in MCObjectFileInfo. However,
1145 /// this duplicate code in MCWin64EH.cpp.
1146 if (suffix == "")
1147 return context.getObjectFileInfo()->getXDataSection();
1148 return context.getCOFFSection((".xdata"+suffix).str(),
1149 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1150 COFF::IMAGE_SCN_MEM_READ |
1151 COFF::IMAGE_SCN_MEM_WRITE,
1152 SectionKind::getDataRel());
1153}
1154
Charles Davis440596f2011-05-19 17:46:39 +00001155void MCAsmStreamer::EmitWin64EHHandlerData() {
Charles Daviscde87e22011-05-20 18:19:22 +00001156 MCStreamer::EmitWin64EHHandlerData();
1157
Charles Davis410ef2b2011-05-25 21:43:45 +00001158 // Switch sections. Don't call SwitchSection directly, because that will
1159 // cause the section switch to be visible in the emitted assembly.
1160 // We only do this so the section switch that terminates the handler
1161 // data block is visible.
Charles Davis7b06b732011-05-27 19:09:24 +00001162 MCWin64EHUnwindInfo *CurFrame = getCurrentW64UnwindInfo();
1163 StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function);
Evan Chenge76a33b2011-07-20 05:58:47 +00001164 const MCSection *xdataSect = getWin64EHTableSection(suffix, getContext());
Charles Davis410ef2b2011-05-25 21:43:45 +00001165 if (xdataSect)
1166 SwitchSectionNoChange(xdataSect);
1167
Charles Davis440596f2011-05-19 17:46:39 +00001168 OS << "\t.seh_handlerdata";
Charles Davisf0709012011-05-18 20:54:10 +00001169 EmitEOL();
1170}
1171
Charles Davisc3b16282011-05-19 19:35:55 +00001172void MCAsmStreamer::EmitWin64EHPushReg(unsigned Register) {
Charles Daviscde87e22011-05-20 18:19:22 +00001173 MCStreamer::EmitWin64EHPushReg(Register);
1174
Charles Davis440596f2011-05-19 17:46:39 +00001175 OS << "\t.seh_pushreg " << Register;
Charles Davis0e30f022011-05-18 04:58:05 +00001176 EmitEOL();
1177}
1178
Charles Davisc3b16282011-05-19 19:35:55 +00001179void MCAsmStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) {
Charles Daviscde87e22011-05-20 18:19:22 +00001180 MCStreamer::EmitWin64EHSetFrame(Register, Offset);
1181
Charles Davis440596f2011-05-19 17:46:39 +00001182 OS << "\t.seh_setframe " << Register << ", " << Offset;
Charles Davis0e30f022011-05-18 04:58:05 +00001183 EmitEOL();
1184}
1185
Charles Davisc3b16282011-05-19 19:35:55 +00001186void MCAsmStreamer::EmitWin64EHAllocStack(unsigned Size) {
Charles Daviscde87e22011-05-20 18:19:22 +00001187 MCStreamer::EmitWin64EHAllocStack(Size);
1188
Charles Davis440596f2011-05-19 17:46:39 +00001189 OS << "\t.seh_stackalloc " << Size;
Charles Davis0e30f022011-05-18 04:58:05 +00001190 EmitEOL();
1191}
1192
Charles Davisc3b16282011-05-19 19:35:55 +00001193void MCAsmStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) {
Charles Daviscde87e22011-05-20 18:19:22 +00001194 MCStreamer::EmitWin64EHSaveReg(Register, Offset);
1195
Charles Davis440596f2011-05-19 17:46:39 +00001196 OS << "\t.seh_savereg " << Register << ", " << Offset;
1197 EmitEOL();
1198}
1199
Charles Davisc3b16282011-05-19 19:35:55 +00001200void MCAsmStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) {
Charles Daviscde87e22011-05-20 18:19:22 +00001201 MCStreamer::EmitWin64EHSaveXMM(Register, Offset);
1202
Charles Davis440596f2011-05-19 17:46:39 +00001203 OS << "\t.seh_savexmm " << Register << ", " << Offset;
Charles Davis0e30f022011-05-18 04:58:05 +00001204 EmitEOL();
1205}
1206
Charles Davis8b3e5e52011-05-18 22:13:51 +00001207void MCAsmStreamer::EmitWin64EHPushFrame(bool Code) {
Charles Daviscde87e22011-05-20 18:19:22 +00001208 MCStreamer::EmitWin64EHPushFrame(Code);
1209
Charles Davis440596f2011-05-19 17:46:39 +00001210 OS << "\t.seh_pushframe";
Charles Davis0e30f022011-05-18 04:58:05 +00001211 if (Code)
Charles Davis440596f2011-05-19 17:46:39 +00001212 OS << " @code";
Charles Davis0e30f022011-05-18 04:58:05 +00001213 EmitEOL();
1214}
1215
Charles Davis8b3e5e52011-05-18 22:13:51 +00001216void MCAsmStreamer::EmitWin64EHEndProlog(void) {
Charles Daviscde87e22011-05-20 18:19:22 +00001217 MCStreamer::EmitWin64EHEndProlog();
1218
Charles Davis440596f2011-05-19 17:46:39 +00001219 OS << "\t.seh_endprologue";
Charles Davis0e30f022011-05-18 04:58:05 +00001220 EmitEOL();
1221}
1222
Daniel Dunbar6b716532010-02-09 23:00:14 +00001223void MCAsmStreamer::AddEncodingComment(const MCInst &Inst) {
1224 raw_ostream &OS = GetCommentOS();
1225 SmallString<256> Code;
1226 SmallVector<MCFixup, 4> Fixups;
1227 raw_svector_ostream VecOS(Code);
1228 Emitter->EncodeInstruction(Inst, VecOS, Fixups);
1229 VecOS.flush();
Chris Lattnera6594fc2010-01-25 18:58:59 +00001230
Daniel Dunbar6b716532010-02-09 23:00:14 +00001231 // If we are showing fixups, create symbolic markers in the encoded
1232 // representation. We do this by making a per-bit map to the fixup item index,
1233 // then trying to display it as nicely as possible.
Daniel Dunbar5532cf42010-02-10 01:41:14 +00001234 SmallVector<uint8_t, 64> FixupMap;
1235 FixupMap.resize(Code.size() * 8);
Daniel Dunbar6b716532010-02-09 23:00:14 +00001236 for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
1237 FixupMap[i] = 0;
1238
1239 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1240 MCFixup &F = Fixups[i];
Daniel Dunbar2761fc42010-12-16 03:20:06 +00001241 const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
Daniel Dunbar6b716532010-02-09 23:00:14 +00001242 for (unsigned j = 0; j != Info.TargetSize; ++j) {
1243 unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
1244 assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
1245 FixupMap[Index] = 1 + i;
1246 }
1247 }
1248
Evan Cheng5c2eef62011-07-08 22:49:42 +00001249 // FIXME: Note the fixup comments for Thumb2 are completely bogus since the
Evan Cheng8fbbd1c2011-01-13 23:27:39 +00001250 // high order halfword of a 32-bit Thumb2 instruction is emitted first.
Daniel Dunbar6b716532010-02-09 23:00:14 +00001251 OS << "encoding: [";
1252 for (unsigned i = 0, e = Code.size(); i != e; ++i) {
1253 if (i)
1254 OS << ',';
1255
1256 // See if all bits are the same map entry.
1257 uint8_t MapEntry = FixupMap[i * 8 + 0];
1258 for (unsigned j = 1; j != 8; ++j) {
1259 if (FixupMap[i * 8 + j] == MapEntry)
1260 continue;
1261
1262 MapEntry = uint8_t(~0U);
1263 break;
1264 }
1265
1266 if (MapEntry != uint8_t(~0U)) {
1267 if (MapEntry == 0) {
1268 OS << format("0x%02x", uint8_t(Code[i]));
1269 } else {
Evan Cheng82caf1a2011-01-13 21:45:26 +00001270 if (Code[i]) {
Evan Cheng8fbbd1c2011-01-13 23:27:39 +00001271 // FIXME: Some of the 8 bits require fix up.
Evan Cheng82caf1a2011-01-13 21:45:26 +00001272 OS << format("0x%02x", uint8_t(Code[i])) << '\''
1273 << char('A' + MapEntry - 1) << '\'';
1274 } else
1275 OS << char('A' + MapEntry - 1);
Daniel Dunbar6b716532010-02-09 23:00:14 +00001276 }
1277 } else {
1278 // Otherwise, write out in binary.
1279 OS << "0b";
Jay Foad95c3e482011-06-23 09:09:15 +00001280 for (unsigned j = 8; j--;) {
Daniel Dunbar6b716532010-02-09 23:00:14 +00001281 unsigned Bit = (Code[i] >> j) & 1;
NAKAMURA Takumid6451512011-03-27 01:44:40 +00001282
Chris Lattner3170a3b2010-11-15 05:56:19 +00001283 unsigned FixupBit;
Bill Wendling99cb6222013-06-18 07:20:20 +00001284 if (MAI->isLittleEndian())
Chris Lattner3170a3b2010-11-15 05:56:19 +00001285 FixupBit = i * 8 + j;
1286 else
1287 FixupBit = i * 8 + (7-j);
NAKAMURA Takumid6451512011-03-27 01:44:40 +00001288
Jay Foad95c3e482011-06-23 09:09:15 +00001289 if (uint8_t MapEntry = FixupMap[FixupBit]) {
1290 assert(Bit == 0 && "Encoder wrote into fixed up bit!");
1291 OS << char('A' + MapEntry - 1);
Daniel Dunbar6b716532010-02-09 23:00:14 +00001292 } else
1293 OS << Bit;
1294 }
1295 }
1296 }
1297 OS << "]\n";
1298
1299 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1300 MCFixup &F = Fixups[i];
Daniel Dunbar2761fc42010-12-16 03:20:06 +00001301 const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
Daniel Dunbar6b716532010-02-09 23:00:14 +00001302 OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
Daniel Dunbar5d5a1e12010-02-10 04:47:08 +00001303 << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
Daniel Dunbar6b716532010-02-09 23:00:14 +00001304 }
1305}
1306
1307void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
Peter Collingbournedf39be62013-04-17 21:18:16 +00001308 assert(getCurrentSection().first &&
1309 "Cannot emit contents before setting section!");
Daniel Dunbar6b716532010-02-09 23:00:14 +00001310
1311 // Show the encoding in a comment if we have a code emitter.
1312 if (Emitter)
1313 AddEncodingComment(Inst);
1314
Chris Lattner30d9a642010-02-09 00:54:51 +00001315 // Show the MCInst if enabled.
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +00001316 if (ShowInst) {
Bill Wendling99cb6222013-06-18 07:20:20 +00001317 Inst.dump_pretty(GetCommentOS(), MAI, InstPrinter.get(), "\n ");
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +00001318 GetCommentOS() << "\n";
1319 }
1320
Daniel Dunbar67c076c2010-03-22 21:49:34 +00001321 // If we have an AsmPrinter, use that to print, otherwise print the MCInst.
Daniel Dunbar9dee8e32010-02-03 18:18:30 +00001322 if (InstPrinter)
Owen Anderson98c5dda2011-09-15 23:38:46 +00001323 InstPrinter->printInst(&Inst, OS, "");
Daniel Dunbar9dee8e32010-02-03 18:18:30 +00001324 else
Bill Wendling99cb6222013-06-18 07:20:20 +00001325 Inst.print(OS, MAI);
Chris Lattner7d1e49c2010-01-22 07:36:39 +00001326 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +00001327}
1328
Eli Bendersky4766ef42012-12-20 19:05:53 +00001329void MCAsmStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
1330 OS << "\t.bundle_align_mode " << AlignPow2;
1331 EmitEOL();
1332}
1333
Eli Bendersky6c1d4972013-01-07 21:51:08 +00001334void MCAsmStreamer::EmitBundleLock(bool AlignToEnd) {
Eli Bendersky4766ef42012-12-20 19:05:53 +00001335 OS << "\t.bundle_lock";
Eli Bendersky6c1d4972013-01-07 21:51:08 +00001336 if (AlignToEnd)
1337 OS << " align_to_end";
Eli Bendersky4766ef42012-12-20 19:05:53 +00001338 EmitEOL();
1339}
1340
1341void MCAsmStreamer::EmitBundleUnlock() {
1342 OS << "\t.bundle_unlock";
1343 EmitEOL();
1344}
1345
Jim Grosbachbd4ec842010-09-22 18:18:30 +00001346/// EmitRawText - If this file is backed by an assembly streamer, this dumps
Chris Lattner91bead72010-04-03 21:35:55 +00001347/// the specified string in the output .s file. This capability is
1348/// indicated by the hasRawTextSupport() predicate.
1349void MCAsmStreamer::EmitRawText(StringRef String) {
Chris Lattnerd5928dc2010-04-03 22:06:56 +00001350 if (!String.empty() && String.back() == '\n')
1351 String = String.substr(0, String.size()-1);
Chris Lattner91bead72010-04-03 21:35:55 +00001352 OS << String;
Chris Lattnerd5928dc2010-04-03 22:06:56 +00001353 EmitEOL();
Chris Lattner91bead72010-04-03 21:35:55 +00001354}
1355
Rafael Espindola99b42372012-01-07 03:13:18 +00001356void MCAsmStreamer::FinishImpl() {
Rafael Espindola489d6792012-02-28 21:13:05 +00001357 // FIXME: This header is duplicated with MCObjectStreamer
Rafael Espindola195a0ce2010-11-19 02:26:16 +00001358 // Dump out the dwarf file & directory tables and line tables.
Rafael Espindolae6ec02e2012-03-03 14:24:15 +00001359 const MCSymbol *LineSectionSymbol = NULL;
Rafael Espindola89b93722010-12-10 07:39:47 +00001360 if (getContext().hasDwarfFiles() && !UseLoc)
Rafael Espindola489d6792012-02-28 21:13:05 +00001361 LineSectionSymbol = MCDwarfFileTable::Emit(this);
Rafael Espindola5426a9e2011-05-01 04:49:54 +00001362
Kevin Enderby94c2e852011-12-09 18:09:40 +00001363 // If we are generating dwarf for assembly source files dump out the sections.
1364 if (getContext().getGenDwarfForAssembly())
Rafael Espindola489d6792012-02-28 21:13:05 +00001365 MCGenDwarfInfo::Emit(this, LineSectionSymbol);
Kevin Enderby94c2e852011-12-09 18:09:40 +00001366
Rafael Espindolac25dad82011-05-10 03:14:15 +00001367 if (!UseCFI)
Bill Wendlingda11df02013-09-09 19:48:37 +00001368 EmitFrames(AsmBackend.get(), false);
Daniel Dunbara11af532009-06-24 01:03:06 +00001369}
Bill Wendlingda11df02013-09-09 19:48:37 +00001370
Chris Lattner86e22112010-01-22 07:29:22 +00001371MCStreamer *llvm::createAsmStreamer(MCContext &Context,
Rafael Espindola320296a2013-10-08 13:08:17 +00001372 MCTargetStreamer *TargetStreamer,
Chris Lattner86e22112010-01-22 07:29:22 +00001373 formatted_raw_ostream &OS,
Rafael Espindola320296a2013-10-08 13:08:17 +00001374 bool isVerboseAsm, bool useLoc, bool useCFI,
1375 bool useDwarfDirectory, MCInstPrinter *IP,
1376 MCCodeEmitter *CE, MCAsmBackend *MAB,
1377 bool ShowInst) {
1378 return new MCAsmStreamer(Context, TargetStreamer, OS, isVerboseAsm, useLoc,
1379 useCFI, useDwarfDirectory, IP, CE, MAB, ShowInst);
Daniel Dunbara11af532009-06-24 01:03:06 +00001380}