blob: 6c240cf4148a77bf1bc5d1713104f62c89429938 [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"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000011#include "llvm/MC/MCAsmInfo.h"
Daniel Dunbar4a0abd82009-08-27 00:51:57 +000012#include "llvm/MC/MCCodeEmitter.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000013#include "llvm/MC/MCContext.h"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000014#include "llvm/MC/MCExpr.h"
Daniel Dunbarabde2982009-07-01 06:35:03 +000015#include "llvm/MC/MCInst.h"
Chris Lattner90edac02009-09-14 03:02:37 +000016#include "llvm/MC/MCInstPrinter.h"
Chris Lattnerf9bdedd2009-08-10 18:15:01 +000017#include "llvm/MC/MCSectionMachO.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000018#include "llvm/MC/MCSymbol.h"
Chris Lattner4c42a6d2010-03-19 05:48:53 +000019#include "llvm/ADT/OwningPtr.h"
Chris Lattner86e22112010-01-22 07:29:22 +000020#include "llvm/ADT/SmallString.h"
21#include "llvm/ADT/Twine.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000022#include "llvm/Support/ErrorHandling.h"
Chris Lattner663c2d22009-08-19 06:12:02 +000023#include "llvm/Support/MathExtras.h"
Daniel Dunbar4a0abd82009-08-27 00:51:57 +000024#include "llvm/Support/Format.h"
Chris Lattner86e22112010-01-22 07:29:22 +000025#include "llvm/Support/FormattedStream.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000026using namespace llvm;
27
28namespace {
29
Chris Lattner46a947d2009-08-17 04:17:34 +000030class MCAsmStreamer : public MCStreamer {
Chris Lattner86e22112010-01-22 07:29:22 +000031 formatted_raw_ostream &OS;
Chris Lattner33adcfb2009-08-22 21:43:10 +000032 const MCAsmInfo &MAI;
Chris Lattner4c42a6d2010-03-19 05:48:53 +000033 OwningPtr<MCInstPrinter> InstPrinter;
Benjamin Kramer1abcd062010-07-29 17:48:06 +000034 OwningPtr<MCCodeEmitter> Emitter;
Jim Grosbach00545e12010-09-22 18:16:55 +000035
Chris Lattner86e22112010-01-22 07:29:22 +000036 SmallString<128> CommentToEmit;
Chris Lattnerd79d9dc2010-01-22 19:17:48 +000037 raw_svector_ostream CommentStream;
Daniel Dunbar9dee8e32010-02-03 18:18:30 +000038
39 unsigned IsLittleEndian : 1;
40 unsigned IsVerboseAsm : 1;
41 unsigned ShowInst : 1;
42
Chris Lattner46a947d2009-08-17 04:17:34 +000043public:
Chris Lattner86e22112010-01-22 07:29:22 +000044 MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
Chris Lattner07404412010-01-22 07:06:15 +000045 bool isLittleEndian, bool isVerboseAsm, MCInstPrinter *printer,
Daniel Dunbar5532cf42010-02-10 01:41:14 +000046 MCCodeEmitter *emitter, bool showInst)
Chris Lattnerfdab14b2010-03-12 18:28:53 +000047 : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()),
48 InstPrinter(printer), Emitter(emitter), CommentStream(CommentToEmit),
Daniel Dunbar9dee8e32010-02-03 18:18:30 +000049 IsLittleEndian(isLittleEndian), IsVerboseAsm(isVerboseAsm),
Daniel Dunbar5532cf42010-02-10 01:41:14 +000050 ShowInst(showInst) {
Chris Lattner5d672cf2010-02-10 00:10:18 +000051 if (InstPrinter && IsVerboseAsm)
52 InstPrinter->setCommentStream(CommentStream);
53 }
Chris Lattner46a947d2009-08-17 04:17:34 +000054 ~MCAsmStreamer() {}
Daniel Dunbara11af532009-06-24 01:03:06 +000055
Chris Lattner16582022010-01-20 06:39:07 +000056 bool isLittleEndian() const { return IsLittleEndian; }
Daniel Dunbar6b716532010-02-09 23:00:14 +000057
Chris Lattner86e22112010-01-22 07:29:22 +000058 inline void EmitEOL() {
Chris Lattnerd79d9dc2010-01-22 19:17:48 +000059 // If we don't have any comments, just emit a \n.
60 if (!IsVerboseAsm) {
Chris Lattner86e22112010-01-22 07:29:22 +000061 OS << '\n';
62 return;
63 }
64 EmitCommentsAndEOL();
65 }
66 void EmitCommentsAndEOL();
Chris Lattner56591ab2010-02-02 23:37:42 +000067
68 /// isVerboseAsm - Return true if this streamer supports verbose assembly at
69 /// all.
70 virtual bool isVerboseAsm() const { return IsVerboseAsm; }
Jim Grosbach00545e12010-09-22 18:16:55 +000071
Chris Lattner91bead72010-04-03 21:35:55 +000072 /// hasRawTextSupport - We support EmitRawText.
73 virtual bool hasRawTextSupport() const { return true; }
Daniel Dunbar6b716532010-02-09 23:00:14 +000074
Chris Lattnerd32c7cf2010-01-22 18:21:35 +000075 /// AddComment - Add a comment that can be emitted to the generated .s
Chris Lattner86e22112010-01-22 07:29:22 +000076 /// file if applicable as a QoI issue to make the output of the compiler
77 /// more readable. This only affects the MCAsmStreamer, and only when
78 /// verbose assembly output is enabled.
Chris Lattnerd32c7cf2010-01-22 18:21:35 +000079 virtual void AddComment(const Twine &T);
Daniel Dunbar6b716532010-02-09 23:00:14 +000080
81 /// AddEncodingComment - Add a comment showing the encoding of an instruction.
82 virtual void AddEncodingComment(const MCInst &Inst);
83
Chris Lattnerd79d9dc2010-01-22 19:17:48 +000084 /// GetCommentOS - Return a raw_ostream that comments can be written to.
85 /// Unlike AddComment, you are required to terminate comments with \n if you
86 /// use this method.
87 virtual raw_ostream &GetCommentOS() {
88 if (!IsVerboseAsm)
89 return nulls(); // Discard comments unless in verbose asm mode.
90 return CommentStream;
91 }
Daniel Dunbar6b716532010-02-09 23:00:14 +000092
Chris Lattner0fd90fd2010-01-22 19:52:01 +000093 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
94 virtual void AddBlankLine() {
95 EmitEOL();
96 }
Daniel Dunbar6b716532010-02-09 23:00:14 +000097
Chris Lattner46a947d2009-08-17 04:17:34 +000098 /// @name MCStreamer Interface
99 /// @{
Daniel Dunbara11af532009-06-24 01:03:06 +0000100
Chris Lattner975780b2009-08-17 05:49:08 +0000101 virtual void SwitchSection(const MCSection *Section);
Daniel Dunbara11af532009-06-24 01:03:06 +0000102
Rafael Espindolad80781b2010-09-15 21:48:40 +0000103 virtual void InitSections() {
104 // FIXME, this is MachO specific, but the testsuite
105 // expects this.
106 SwitchSection(getContext().getMachOSection("__TEXT", "__text",
107 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
108 0, SectionKind::getText()));
109 }
110
Chris Lattner46a947d2009-08-17 04:17:34 +0000111 virtual void EmitLabel(MCSymbol *Symbol);
Daniel Dunbara11af532009-06-24 01:03:06 +0000112
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000113 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Daniel Dunbara11af532009-06-24 01:03:06 +0000114
Daniel Dunbar821e3332009-08-31 08:09:28 +0000115 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
Daniel Dunbara11af532009-06-24 01:03:06 +0000116
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000117 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
Kevin Enderbya5c78322009-07-13 21:03:15 +0000118
Chris Lattner46a947d2009-08-17 04:17:34 +0000119 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
Chris Lattnerb54b9dd2010-05-08 19:54:22 +0000120 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
121 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
122 virtual void EmitCOFFSymbolType(int Type);
123 virtual void EndCOFFSymbolDef();
Chris Lattner99328ad2010-01-25 07:52:13 +0000124 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
Chris Lattner9eb158d2010-01-23 07:47:02 +0000125 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000126 unsigned ByteAlignment);
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000127
Chris Lattner9eb158d2010-01-23 07:47:02 +0000128 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
129 ///
130 /// @param Symbol - The common symbol to emit.
131 /// @param Size - The size of the common symbol.
132 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
Jim Grosbach00545e12010-09-22 18:16:55 +0000133
Daniel Dunbar8751b942009-08-28 05:48:22 +0000134 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000135 unsigned Size = 0, unsigned ByteAlignment = 0);
Kevin Enderby71148242009-07-14 21:35:03 +0000136
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000137 virtual void EmitTBSSSymbol (const MCSection *Section, MCSymbol *Symbol,
138 uint64_t Size, unsigned ByteAlignment = 0);
Jim Grosbach00545e12010-09-22 18:16:55 +0000139
Chris Lattneraaec2052010-01-19 19:46:13 +0000140 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000141
Chris Lattneraaec2052010-01-19 19:46:13 +0000142 virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000143 virtual void EmitIntValue(uint64_t Value, unsigned Size, unsigned AddrSpace);
Chris Lattner718fb592010-01-25 21:28:50 +0000144 virtual void EmitGPRel32Value(const MCExpr *Value);
Jim Grosbach00545e12010-09-22 18:16:55 +0000145
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000146
Chris Lattneraaec2052010-01-19 19:46:13 +0000147 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
148 unsigned AddrSpace);
Chris Lattner9be3fee2009-07-10 22:20:30 +0000149
Chris Lattner46a947d2009-08-17 04:17:34 +0000150 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
151 unsigned ValueSize = 1,
152 unsigned MaxBytesToEmit = 0);
Daniel Dunbara11af532009-06-24 01:03:06 +0000153
Kevin Enderby6e720482010-02-23 18:26:34 +0000154 virtual void EmitCodeAlignment(unsigned ByteAlignment,
155 unsigned MaxBytesToEmit = 0);
156
Daniel Dunbar821e3332009-08-31 08:09:28 +0000157 virtual void EmitValueToOffset(const MCExpr *Offset,
Chris Lattner46a947d2009-08-17 04:17:34 +0000158 unsigned char Value = 0);
Daniel Dunbara11af532009-06-24 01:03:06 +0000159
Chris Lattnera6594fc2010-01-25 18:58:59 +0000160 virtual void EmitFileDirective(StringRef Filename);
161 virtual void EmitDwarfFileDirective(unsigned FileNo, StringRef Filename);
162
163 virtual void EmitInstruction(const MCInst &Inst);
Jim Grosbach00545e12010-09-22 18:16:55 +0000164
Jim Grosbachbd4ec842010-09-22 18:18:30 +0000165 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
Chris Lattner91bead72010-04-03 21:35:55 +0000166 /// the specified string in the output .s file. This capability is
167 /// indicated by the hasRawTextSupport() predicate.
168 virtual void EmitRawText(StringRef String);
Jim Grosbach00545e12010-09-22 18:16:55 +0000169
Chris Lattner46a947d2009-08-17 04:17:34 +0000170 virtual void Finish();
Jim Grosbach00545e12010-09-22 18:16:55 +0000171
Chris Lattner46a947d2009-08-17 04:17:34 +0000172 /// @}
173};
Daniel Dunbar84a29262009-06-24 19:25:34 +0000174
Chris Lattner46a947d2009-08-17 04:17:34 +0000175} // end anonymous namespace.
Daniel Dunbara11af532009-06-24 01:03:06 +0000176
Chris Lattnerd32c7cf2010-01-22 18:21:35 +0000177/// AddComment - Add a comment that can be emitted to the generated .s
Chris Lattner86e22112010-01-22 07:29:22 +0000178/// file if applicable as a QoI issue to make the output of the compiler
179/// more readable. This only affects the MCAsmStreamer, and only when
180/// verbose assembly output is enabled.
Chris Lattnerd32c7cf2010-01-22 18:21:35 +0000181void MCAsmStreamer::AddComment(const Twine &T) {
Chris Lattner86e22112010-01-22 07:29:22 +0000182 if (!IsVerboseAsm) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000183
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000184 // Make sure that CommentStream is flushed.
185 CommentStream.flush();
Jim Grosbach00545e12010-09-22 18:16:55 +0000186
Chris Lattner86e22112010-01-22 07:29:22 +0000187 T.toVector(CommentToEmit);
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000188 // Each comment goes on its own line.
189 CommentToEmit.push_back('\n');
Jim Grosbach00545e12010-09-22 18:16:55 +0000190
Chris Lattner14ca1772010-01-22 21:16:10 +0000191 // Tell the comment stream that the vector changed underneath it.
192 CommentStream.resync();
Chris Lattner86e22112010-01-22 07:29:22 +0000193}
194
195void MCAsmStreamer::EmitCommentsAndEOL() {
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000196 if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
197 OS << '\n';
198 return;
199 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000200
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000201 CommentStream.flush();
Chris Lattner86e22112010-01-22 07:29:22 +0000202 StringRef Comments = CommentToEmit.str();
Jim Grosbach00545e12010-09-22 18:16:55 +0000203
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000204 assert(Comments.back() == '\n' &&
205 "Comment array not newline terminated");
206 do {
Chris Lattner86e22112010-01-22 07:29:22 +0000207 // Emit a line of comments.
208 OS.PadToColumn(MAI.getCommentColumn());
209 size_t Position = Comments.find('\n');
210 OS << MAI.getCommentString() << ' ' << Comments.substr(0, Position) << '\n';
Jim Grosbach00545e12010-09-22 18:16:55 +0000211
Chris Lattner86e22112010-01-22 07:29:22 +0000212 Comments = Comments.substr(Position+1);
Chris Lattnerd79d9dc2010-01-22 19:17:48 +0000213 } while (!Comments.empty());
Jim Grosbach00545e12010-09-22 18:16:55 +0000214
Chris Lattner14ca1772010-01-22 21:16:10 +0000215 CommentToEmit.clear();
216 // Tell the comment stream that the vector changed underneath it.
217 CommentStream.resync();
Chris Lattner86e22112010-01-22 07:29:22 +0000218}
219
Daniel Dunbar304f6a42009-06-25 21:03:18 +0000220static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
221 assert(Bytes && "Invalid size!");
222 return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
223}
224
Chris Lattner975780b2009-08-17 05:49:08 +0000225void MCAsmStreamer::SwitchSection(const MCSection *Section) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000226 assert(Section && "Cannot switch to a null section!");
Daniel Dunbara11af532009-06-24 01:03:06 +0000227 if (Section != CurSection) {
Benjamin Kramer1674b0b2010-09-02 18:53:37 +0000228 PrevSection = CurSection;
Daniel Dunbara11af532009-06-24 01:03:06 +0000229 CurSection = Section;
Chris Lattner33adcfb2009-08-22 21:43:10 +0000230 Section->PrintSwitchToSection(MAI, OS);
Daniel Dunbara11af532009-06-24 01:03:06 +0000231 }
232}
233
234void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000235 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
Daniel Dunbarc3047182010-05-05 19:01:00 +0000236 assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000237 assert(CurSection && "Cannot emit before setting section!");
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000238
Chris Lattnere07b75e2010-09-22 22:19:53 +0000239 OS << *Symbol << MAI.getLabelSuffix();
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000240 EmitEOL();
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000241 Symbol->setSection(*CurSection);
Daniel Dunbara11af532009-06-24 01:03:06 +0000242}
243
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000244void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Kevin Enderbyf96db462009-07-16 17:56:39 +0000245 switch (Flag) {
Daniel Dunbar011e4db2009-08-13 23:36:34 +0000246 default: assert(0 && "Invalid flag!");
Jason W Kimafd1cc22010-09-30 02:45:56 +0000247 case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000248 case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
Kevin Enderbyf96db462009-07-16 17:56:39 +0000249 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000250 EmitEOL();
Kevin Enderbya5c78322009-07-13 21:03:15 +0000251}
252
Daniel Dunbar821e3332009-08-31 08:09:28 +0000253void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000254 OS << *Symbol << " = " << *Value;
255 EmitEOL();
Daniel Dunbarfffff912009-10-16 01:34:54 +0000256
257 // FIXME: Lift context changes into super class.
Daniel Dunbar08a408a2010-05-05 17:41:00 +0000258 Symbol->setVariableValue(Value);
Daniel Dunbara11af532009-06-24 01:03:06 +0000259}
260
Daniel Dunbarfffff912009-10-16 01:34:54 +0000261void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000262 MCSymbolAttr Attribute) {
Daniel Dunbara11af532009-06-24 01:03:06 +0000263 switch (Attribute) {
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000264 case MCSA_Invalid: assert(0 && "Invalid symbol attribute");
Chris Lattnered0ab152010-01-25 18:30:45 +0000265 case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function
266 case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
267 case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object
268 case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object
269 case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
270 case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
271 assert(MAI.hasDotTypeDotSizeDirective() && "Symbol Attr not supported");
Dan Gohman523d70e2010-02-04 01:42:13 +0000272 OS << "\t.type\t" << *Symbol << ','
Chris Lattnered0ab152010-01-25 18:30:45 +0000273 << ((MAI.getCommentString()[0] != '@') ? '@' : '%');
274 switch (Attribute) {
275 default: assert(0 && "Unknown ELF .type");
276 case MCSA_ELF_TypeFunction: OS << "function"; break;
277 case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
278 case MCSA_ELF_TypeObject: OS << "object"; break;
279 case MCSA_ELF_TypeTLS: OS << "tls_object"; break;
280 case MCSA_ELF_TypeCommon: OS << "common"; break;
281 case MCSA_ELF_TypeNoType: OS << "no_type"; break;
282 }
283 EmitEOL();
284 return;
285 case MCSA_Global: // .globl/.global
286 OS << MAI.getGlobalDirective();
287 break;
Chris Lattner61abd7b2010-06-21 20:35:01 +0000288 case MCSA_Hidden: OS << "\t.hidden\t"; break;
289 case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
290 case MCSA_Internal: OS << "\t.internal\t"; break;
291 case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break;
292 case MCSA_Local: OS << "\t.local\t"; break;
293 case MCSA_NoDeadStrip: OS << "\t.no_dead_strip\t"; break;
294 case MCSA_PrivateExtern: OS << "\t.private_extern\t"; break;
295 case MCSA_Protected: OS << "\t.protected\t"; break;
296 case MCSA_Reference: OS << "\t.reference\t"; break;
297 case MCSA_Weak: OS << "\t.weak\t"; break;
298 case MCSA_WeakDefinition: OS << "\t.weak_definition\t"; break;
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000299 // .weak_reference
300 case MCSA_WeakReference: OS << MAI.getWeakRefDirective(); break;
Kevin Enderbyf59cac52010-07-08 17:22:42 +0000301 case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
Daniel Dunbara11af532009-06-24 01:03:06 +0000302 }
303
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000304 OS << *Symbol;
305 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000306}
307
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000308void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000309 OS << ".desc" << ' ' << *Symbol << ',' << DescValue;
310 EmitEOL();
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000311}
312
Chris Lattnerb54b9dd2010-05-08 19:54:22 +0000313void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
314 OS << "\t.def\t " << *Symbol << ';';
315 EmitEOL();
316}
317
318void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
319 OS << "\t.scl\t" << StorageClass << ';';
320 EmitEOL();
321}
322
323void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
324 OS << "\t.type\t" << Type << ';';
325 EmitEOL();
326}
327
328void MCAsmStreamer::EndCOFFSymbolDef() {
329 OS << "\t.endef";
330 EmitEOL();
331}
332
Chris Lattner99328ad2010-01-25 07:52:13 +0000333void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
334 assert(MAI.hasDotTypeDotSizeDirective());
335 OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
336}
337
Chris Lattner9eb158d2010-01-23 07:47:02 +0000338void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000339 unsigned ByteAlignment) {
Chris Lattner9eb158d2010-01-23 07:47:02 +0000340 OS << "\t.comm\t" << *Symbol << ',' << Size;
Chris Lattner6559d762010-01-25 07:29:13 +0000341 if (ByteAlignment != 0) {
Rafael Espindola2e2563b2010-01-26 20:21:43 +0000342 if (MAI.getCOMMDirectiveAlignmentIsInBytes())
Chris Lattner4ed54382010-01-19 06:01:04 +0000343 OS << ',' << ByteAlignment;
344 else
345 OS << ',' << Log2_32(ByteAlignment);
346 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000347 EmitEOL();
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000348}
349
Chris Lattner9eb158d2010-01-23 07:47:02 +0000350/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
351///
352/// @param Symbol - The common symbol to emit.
353/// @param Size - The size of the common symbol.
354void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {
355 assert(MAI.hasLCOMMDirective() && "Doesn't have .lcomm, can't emit it!");
356 OS << "\t.lcomm\t" << *Symbol << ',' << Size;
357 EmitEOL();
358}
359
Daniel Dunbar8751b942009-08-28 05:48:22 +0000360void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000361 unsigned Size, unsigned ByteAlignment) {
Daniel Dunbar011e4db2009-08-13 23:36:34 +0000362 // Note: a .zerofill directive does not switch sections.
Chris Lattner93b6db32009-08-08 23:39:42 +0000363 OS << ".zerofill ";
Jim Grosbach00545e12010-09-22 18:16:55 +0000364
Chris Lattner93b6db32009-08-08 23:39:42 +0000365 // This is a mach-o specific directive.
Chris Lattnerff4bc462009-08-10 01:39:42 +0000366 const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
Daniel Dunbar12de0df2009-08-14 18:51:45 +0000367 OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
Jim Grosbach00545e12010-09-22 18:16:55 +0000368
Chris Lattner9be3fee2009-07-10 22:20:30 +0000369 if (Symbol != NULL) {
Chris Lattner10b318b2010-01-17 21:43:43 +0000370 OS << ',' << *Symbol << ',' << Size;
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000371 if (ByteAlignment != 0)
372 OS << ',' << Log2_32(ByteAlignment);
Chris Lattner9be3fee2009-07-10 22:20:30 +0000373 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000374 EmitEOL();
Chris Lattner9be3fee2009-07-10 22:20:30 +0000375}
376
Eric Christopherd04d98d2010-05-17 02:13:02 +0000377// .tbss sym, size, align
378// This depends that the symbol has already been mangled from the original,
379// e.g. _a.
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000380void MCAsmStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
381 uint64_t Size, unsigned ByteAlignment) {
Eric Christopher482eba02010-05-14 01:50:28 +0000382 assert(Symbol != NULL && "Symbol shouldn't be NULL!");
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000383 // Instead of using the Section we'll just use the shortcut.
384 // This is a mach-o specific directive and section.
Eric Christopherd04d98d2010-05-17 02:13:02 +0000385 OS << ".tbss " << *Symbol << ", " << Size;
Jim Grosbach00545e12010-09-22 18:16:55 +0000386
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000387 // Output align if we have it. We default to 1 so don't bother printing
388 // that.
389 if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
Jim Grosbach00545e12010-09-22 18:16:55 +0000390
Eric Christopher482eba02010-05-14 01:50:28 +0000391 EmitEOL();
392}
393
Chris Lattner12e555c2010-01-23 00:15:00 +0000394static inline char toOctal(int X) { return (X&7)+'0'; }
395
Chris Lattnera6594fc2010-01-25 18:58:59 +0000396static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
397 OS << '"';
Jim Grosbach00545e12010-09-22 18:16:55 +0000398
Chris Lattnera6594fc2010-01-25 18:58:59 +0000399 for (unsigned i = 0, e = Data.size(); i != e; ++i) {
400 unsigned char C = Data[i];
401 if (C == '"' || C == '\\') {
402 OS << '\\' << (char)C;
403 continue;
404 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000405
Chris Lattnera6594fc2010-01-25 18:58:59 +0000406 if (isprint((unsigned char)C)) {
407 OS << (char)C;
408 continue;
409 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000410
Chris Lattnera6594fc2010-01-25 18:58:59 +0000411 switch (C) {
412 case '\b': OS << "\\b"; break;
413 case '\f': OS << "\\f"; break;
414 case '\n': OS << "\\n"; break;
415 case '\r': OS << "\\r"; break;
416 case '\t': OS << "\\t"; break;
417 default:
418 OS << '\\';
419 OS << toOctal(C >> 6);
420 OS << toOctal(C >> 3);
421 OS << toOctal(C >> 0);
422 break;
423 }
424 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000425
Chris Lattnera6594fc2010-01-25 18:58:59 +0000426 OS << '"';
427}
428
429
Chris Lattneraaec2052010-01-19 19:46:13 +0000430void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000431 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner12e555c2010-01-23 00:15:00 +0000432 if (Data.empty()) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000433
Chris Lattner12e555c2010-01-23 00:15:00 +0000434 if (Data.size() == 1) {
435 OS << MAI.getData8bitsDirective(AddrSpace);
436 OS << (unsigned)(unsigned char)Data[0];
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000437 EmitEOL();
Chris Lattner12e555c2010-01-23 00:15:00 +0000438 return;
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000439 }
Chris Lattner12e555c2010-01-23 00:15:00 +0000440
441 // If the data ends with 0 and the target supports .asciz, use it, otherwise
442 // use .ascii
443 if (MAI.getAscizDirective() && Data.back() == 0) {
444 OS << MAI.getAscizDirective();
445 Data = Data.substr(0, Data.size()-1);
446 } else {
447 OS << MAI.getAsciiDirective();
448 }
449
Chris Lattnera6594fc2010-01-25 18:58:59 +0000450 OS << ' ';
451 PrintQuotedString(Data, OS);
Chris Lattner12e555c2010-01-23 00:15:00 +0000452 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000453}
454
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000455/// EmitIntValue - Special case of EmitValue that avoids the client having
456/// to pass in a MCExpr for constant integers.
457void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size,
458 unsigned AddrSpace) {
459 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000460 const char *Directive = 0;
461 switch (Size) {
462 default: break;
463 case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
464 case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
465 case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
Chris Lattner5eaa54e2010-01-20 06:45:39 +0000466 case 8:
467 Directive = MAI.getData64bitsDirective(AddrSpace);
468 // If the target doesn't support 64-bit data, emit as two 32-bit halves.
469 if (Directive) break;
470 if (isLittleEndian()) {
471 EmitIntValue((uint32_t)(Value >> 0 ), 4, AddrSpace);
472 EmitIntValue((uint32_t)(Value >> 32), 4, AddrSpace);
473 } else {
474 EmitIntValue((uint32_t)(Value >> 32), 4, AddrSpace);
475 EmitIntValue((uint32_t)(Value >> 0 ), 4, AddrSpace);
476 }
477 return;
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000478 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000479
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000480 assert(Directive && "Invalid size for machine code value!");
Chris Lattner86e22112010-01-22 07:29:22 +0000481 OS << Directive << truncateToSize(Value, Size);
482 EmitEOL();
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000483}
484
Chris Lattneraaec2052010-01-19 19:46:13 +0000485void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
486 unsigned AddrSpace) {
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000487 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000488 const char *Directive = 0;
Daniel Dunbara11af532009-06-24 01:03:06 +0000489 switch (Size) {
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000490 default: break;
491 case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
492 case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
493 case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
494 case 8: Directive = MAI.getData64bitsDirective(AddrSpace); break;
Daniel Dunbara11af532009-06-24 01:03:06 +0000495 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000496
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000497 assert(Directive && "Invalid size for machine code value!");
Chris Lattner718fb592010-01-25 21:28:50 +0000498 OS << Directive << *Value;
Chris Lattner86e22112010-01-22 07:29:22 +0000499 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000500}
501
Chris Lattner718fb592010-01-25 21:28:50 +0000502void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
503 assert(MAI.getGPRel32Directive() != 0);
504 OS << MAI.getGPRel32Directive() << *Value;
505 EmitEOL();
506}
507
508
Chris Lattner6113b3d2010-01-19 18:52:28 +0000509/// EmitFill - Emit NumBytes bytes worth of the value specified by
510/// FillValue. This implements directives such as '.space'.
Chris Lattneraaec2052010-01-19 19:46:13 +0000511void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
512 unsigned AddrSpace) {
Chris Lattner8a6d7ac2010-01-19 18:58:52 +0000513 if (NumBytes == 0) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000514
Chris Lattneraaec2052010-01-19 19:46:13 +0000515 if (AddrSpace == 0)
516 if (const char *ZeroDirective = MAI.getZeroDirective()) {
517 OS << ZeroDirective << NumBytes;
518 if (FillValue != 0)
519 OS << ',' << (int)FillValue;
Chris Lattner86e22112010-01-22 07:29:22 +0000520 EmitEOL();
Chris Lattneraaec2052010-01-19 19:46:13 +0000521 return;
522 }
523
524 // Emit a byte at a time.
525 MCStreamer::EmitFill(NumBytes, FillValue, AddrSpace);
Chris Lattner6113b3d2010-01-19 18:52:28 +0000526}
527
Daniel Dunbar84a29262009-06-24 19:25:34 +0000528void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
529 unsigned ValueSize,
530 unsigned MaxBytesToEmit) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000531 // Some assemblers don't support non-power of two alignments, so we always
532 // emit alignments as a power of two if possible.
533 if (isPowerOf2_32(ByteAlignment)) {
Chris Lattner6e579c62009-08-19 06:35:36 +0000534 switch (ValueSize) {
535 default: llvm_unreachable("Invalid size for machine code value!");
Chris Lattner33adcfb2009-08-22 21:43:10 +0000536 case 1: OS << MAI.getAlignDirective(); break;
537 // FIXME: use MAI for this!
Chris Lattner6e579c62009-08-19 06:35:36 +0000538 case 2: OS << ".p2alignw "; break;
539 case 4: OS << ".p2alignl "; break;
540 case 8: llvm_unreachable("Unsupported alignment size!");
541 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000542
Chris Lattner33adcfb2009-08-22 21:43:10 +0000543 if (MAI.getAlignmentIsInBytes())
Chris Lattner663c2d22009-08-19 06:12:02 +0000544 OS << ByteAlignment;
545 else
546 OS << Log2_32(ByteAlignment);
Daniel Dunbar84a29262009-06-24 19:25:34 +0000547
Chris Lattner663c2d22009-08-19 06:12:02 +0000548 if (Value || MaxBytesToEmit) {
Chris Lattner579531c2009-09-03 04:01:10 +0000549 OS << ", 0x";
550 OS.write_hex(truncateToSize(Value, ValueSize));
Chris Lattner663c2d22009-08-19 06:12:02 +0000551
Jim Grosbach00545e12010-09-22 18:16:55 +0000552 if (MaxBytesToEmit)
Chris Lattner663c2d22009-08-19 06:12:02 +0000553 OS << ", " << MaxBytesToEmit;
554 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000555 EmitEOL();
Chris Lattner663c2d22009-08-19 06:12:02 +0000556 return;
557 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000558
Chris Lattner663c2d22009-08-19 06:12:02 +0000559 // Non-power of two alignment. This is not widely supported by assemblers.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000560 // FIXME: Parameterize this based on MAI.
Daniel Dunbar84a29262009-06-24 19:25:34 +0000561 switch (ValueSize) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000562 default: llvm_unreachable("Invalid size for machine code value!");
563 case 1: OS << ".balign"; break;
564 case 2: OS << ".balignw"; break;
565 case 4: OS << ".balignl"; break;
566 case 8: llvm_unreachable("Unsupported alignment size!");
Daniel Dunbar84a29262009-06-24 19:25:34 +0000567 }
568
Chris Lattner663c2d22009-08-19 06:12:02 +0000569 OS << ' ' << ByteAlignment;
Daniel Dunbar304f6a42009-06-25 21:03:18 +0000570 OS << ", " << truncateToSize(Value, ValueSize);
Jim Grosbach00545e12010-09-22 18:16:55 +0000571 if (MaxBytesToEmit)
Daniel Dunbar84a29262009-06-24 19:25:34 +0000572 OS << ", " << MaxBytesToEmit;
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000573 EmitEOL();
Daniel Dunbar84a29262009-06-24 19:25:34 +0000574}
575
Kevin Enderby6e720482010-02-23 18:26:34 +0000576void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
577 unsigned MaxBytesToEmit) {
Chris Lattnerec167fd2010-02-23 18:44:31 +0000578 // Emit with a text fill value.
579 EmitValueToAlignment(ByteAlignment, MAI.getTextAlignFillValue(),
580 1, MaxBytesToEmit);
Kevin Enderby6e720482010-02-23 18:26:34 +0000581}
582
Daniel Dunbar821e3332009-08-31 08:09:28 +0000583void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
Daniel Dunbar84a29262009-06-24 19:25:34 +0000584 unsigned char Value) {
585 // FIXME: Verify that Offset is associated with the current section.
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000586 OS << ".org " << *Offset << ", " << (unsigned) Value;
587 EmitEOL();
Daniel Dunbar84a29262009-06-24 19:25:34 +0000588}
589
Chris Lattnera6594fc2010-01-25 18:58:59 +0000590
591void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
592 assert(MAI.hasSingleParameterDotFile());
593 OS << "\t.file\t";
594 PrintQuotedString(Filename, OS);
595 EmitEOL();
596}
597
598void MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Filename){
599 OS << "\t.file\t" << FileNo << ' ';
600 PrintQuotedString(Filename, OS);
601 EmitEOL();
602}
603
Daniel Dunbar6b716532010-02-09 23:00:14 +0000604void MCAsmStreamer::AddEncodingComment(const MCInst &Inst) {
605 raw_ostream &OS = GetCommentOS();
606 SmallString<256> Code;
607 SmallVector<MCFixup, 4> Fixups;
608 raw_svector_ostream VecOS(Code);
609 Emitter->EncodeInstruction(Inst, VecOS, Fixups);
610 VecOS.flush();
Chris Lattnera6594fc2010-01-25 18:58:59 +0000611
Daniel Dunbar6b716532010-02-09 23:00:14 +0000612 // If we are showing fixups, create symbolic markers in the encoded
613 // representation. We do this by making a per-bit map to the fixup item index,
614 // then trying to display it as nicely as possible.
Daniel Dunbar5532cf42010-02-10 01:41:14 +0000615 SmallVector<uint8_t, 64> FixupMap;
616 FixupMap.resize(Code.size() * 8);
Daniel Dunbar6b716532010-02-09 23:00:14 +0000617 for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
618 FixupMap[i] = 0;
619
620 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
621 MCFixup &F = Fixups[i];
Chris Lattner8d31de62010-02-11 21:27:18 +0000622 const MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
Daniel Dunbar6b716532010-02-09 23:00:14 +0000623 for (unsigned j = 0; j != Info.TargetSize; ++j) {
624 unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
625 assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
626 FixupMap[Index] = 1 + i;
627 }
628 }
629
630 OS << "encoding: [";
631 for (unsigned i = 0, e = Code.size(); i != e; ++i) {
632 if (i)
633 OS << ',';
634
635 // See if all bits are the same map entry.
636 uint8_t MapEntry = FixupMap[i * 8 + 0];
637 for (unsigned j = 1; j != 8; ++j) {
638 if (FixupMap[i * 8 + j] == MapEntry)
639 continue;
640
641 MapEntry = uint8_t(~0U);
642 break;
643 }
644
645 if (MapEntry != uint8_t(~0U)) {
646 if (MapEntry == 0) {
647 OS << format("0x%02x", uint8_t(Code[i]));
648 } else {
649 assert(Code[i] == 0 && "Encoder wrote into fixed up bit!");
650 OS << char('A' + MapEntry - 1);
651 }
652 } else {
653 // Otherwise, write out in binary.
654 OS << "0b";
655 for (unsigned j = 8; j--;) {
656 unsigned Bit = (Code[i] >> j) & 1;
657 if (uint8_t MapEntry = FixupMap[i * 8 + j]) {
658 assert(Bit == 0 && "Encoder wrote into fixed up bit!");
659 OS << char('A' + MapEntry - 1);
660 } else
661 OS << Bit;
662 }
663 }
664 }
665 OS << "]\n";
666
667 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
668 MCFixup &F = Fixups[i];
Chris Lattner8d31de62010-02-11 21:27:18 +0000669 const MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
Daniel Dunbar6b716532010-02-09 23:00:14 +0000670 OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
Daniel Dunbar5d5a1e12010-02-10 04:47:08 +0000671 << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
Daniel Dunbar6b716532010-02-09 23:00:14 +0000672 }
673}
674
675void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
676 assert(CurSection && "Cannot emit contents before setting section!");
677
678 // Show the encoding in a comment if we have a code emitter.
679 if (Emitter)
680 AddEncodingComment(Inst);
681
Chris Lattner30d9a642010-02-09 00:54:51 +0000682 // Show the MCInst if enabled.
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +0000683 if (ShowInst) {
Daniel Dunbar67c076c2010-03-22 21:49:34 +0000684 Inst.dump_pretty(GetCommentOS(), &MAI, InstPrinter.get(), "\n ");
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +0000685 GetCommentOS() << "\n";
686 }
687
Daniel Dunbar67c076c2010-03-22 21:49:34 +0000688 // If we have an AsmPrinter, use that to print, otherwise print the MCInst.
Daniel Dunbar9dee8e32010-02-03 18:18:30 +0000689 if (InstPrinter)
Chris Lattnerd3740872010-04-04 05:04:31 +0000690 InstPrinter->printInst(&Inst, OS);
Daniel Dunbar9dee8e32010-02-03 18:18:30 +0000691 else
692 Inst.print(OS, &MAI);
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000693 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000694}
695
Jim Grosbachbd4ec842010-09-22 18:18:30 +0000696/// EmitRawText - If this file is backed by an assembly streamer, this dumps
Chris Lattner91bead72010-04-03 21:35:55 +0000697/// the specified string in the output .s file. This capability is
698/// indicated by the hasRawTextSupport() predicate.
699void MCAsmStreamer::EmitRawText(StringRef String) {
Chris Lattnerd5928dc2010-04-03 22:06:56 +0000700 if (!String.empty() && String.back() == '\n')
701 String = String.substr(0, String.size()-1);
Chris Lattner91bead72010-04-03 21:35:55 +0000702 OS << String;
Chris Lattnerd5928dc2010-04-03 22:06:56 +0000703 EmitEOL();
Chris Lattner91bead72010-04-03 21:35:55 +0000704}
705
Daniel Dunbara11af532009-06-24 01:03:06 +0000706void MCAsmStreamer::Finish() {
Daniel Dunbara11af532009-06-24 01:03:06 +0000707}
Daniel Dunbar9dee8e32010-02-03 18:18:30 +0000708
Chris Lattner86e22112010-01-22 07:29:22 +0000709MCStreamer *llvm::createAsmStreamer(MCContext &Context,
710 formatted_raw_ostream &OS,
Chris Lattnerfdab14b2010-03-12 18:28:53 +0000711 bool isLittleEndian,
Chris Lattner07404412010-01-22 07:06:15 +0000712 bool isVerboseAsm, MCInstPrinter *IP,
Daniel Dunbar5532cf42010-02-10 01:41:14 +0000713 MCCodeEmitter *CE, bool ShowInst) {
Chris Lattnerfdab14b2010-03-12 18:28:53 +0000714 return new MCAsmStreamer(Context, OS, isLittleEndian, isVerboseAsm,
Daniel Dunbar5532cf42010-02-10 01:41:14 +0000715 IP, CE, ShowInst);
Daniel Dunbara11af532009-06-24 01:03:06 +0000716}