blob: 15bf72fd46055e90bb62a6403a5fe6ed726f961e [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
Chris Lattner91bead72010-04-03 21:35:55 +0000165 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
166 /// 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 Lattner7d1e49c2010-01-22 07:36:39 +0000239 OS << *Symbol << ":";
240 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!");
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000247 case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
Kevin Enderbyf96db462009-07-16 17:56:39 +0000248 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000249 EmitEOL();
Kevin Enderbya5c78322009-07-13 21:03:15 +0000250}
251
Daniel Dunbar821e3332009-08-31 08:09:28 +0000252void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000253 OS << *Symbol << " = " << *Value;
254 EmitEOL();
Daniel Dunbarfffff912009-10-16 01:34:54 +0000255
256 // FIXME: Lift context changes into super class.
Daniel Dunbar08a408a2010-05-05 17:41:00 +0000257 Symbol->setVariableValue(Value);
Daniel Dunbara11af532009-06-24 01:03:06 +0000258}
259
Daniel Dunbarfffff912009-10-16 01:34:54 +0000260void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000261 MCSymbolAttr Attribute) {
Daniel Dunbara11af532009-06-24 01:03:06 +0000262 switch (Attribute) {
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000263 case MCSA_Invalid: assert(0 && "Invalid symbol attribute");
Chris Lattnered0ab152010-01-25 18:30:45 +0000264 case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function
265 case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
266 case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object
267 case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object
268 case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
269 case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
270 assert(MAI.hasDotTypeDotSizeDirective() && "Symbol Attr not supported");
Dan Gohman523d70e2010-02-04 01:42:13 +0000271 OS << "\t.type\t" << *Symbol << ','
Chris Lattnered0ab152010-01-25 18:30:45 +0000272 << ((MAI.getCommentString()[0] != '@') ? '@' : '%');
273 switch (Attribute) {
274 default: assert(0 && "Unknown ELF .type");
275 case MCSA_ELF_TypeFunction: OS << "function"; break;
276 case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
277 case MCSA_ELF_TypeObject: OS << "object"; break;
278 case MCSA_ELF_TypeTLS: OS << "tls_object"; break;
279 case MCSA_ELF_TypeCommon: OS << "common"; break;
280 case MCSA_ELF_TypeNoType: OS << "no_type"; break;
281 }
282 EmitEOL();
283 return;
284 case MCSA_Global: // .globl/.global
285 OS << MAI.getGlobalDirective();
286 break;
Chris Lattner61abd7b2010-06-21 20:35:01 +0000287 case MCSA_Hidden: OS << "\t.hidden\t"; break;
288 case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
289 case MCSA_Internal: OS << "\t.internal\t"; break;
290 case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break;
291 case MCSA_Local: OS << "\t.local\t"; break;
292 case MCSA_NoDeadStrip: OS << "\t.no_dead_strip\t"; break;
293 case MCSA_PrivateExtern: OS << "\t.private_extern\t"; break;
294 case MCSA_Protected: OS << "\t.protected\t"; break;
295 case MCSA_Reference: OS << "\t.reference\t"; break;
296 case MCSA_Weak: OS << "\t.weak\t"; break;
297 case MCSA_WeakDefinition: OS << "\t.weak_definition\t"; break;
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000298 // .weak_reference
299 case MCSA_WeakReference: OS << MAI.getWeakRefDirective(); break;
Kevin Enderbyf59cac52010-07-08 17:22:42 +0000300 case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
Daniel Dunbara11af532009-06-24 01:03:06 +0000301 }
302
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000303 OS << *Symbol;
304 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000305}
306
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000307void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000308 OS << ".desc" << ' ' << *Symbol << ',' << DescValue;
309 EmitEOL();
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000310}
311
Chris Lattnerb54b9dd2010-05-08 19:54:22 +0000312void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
313 OS << "\t.def\t " << *Symbol << ';';
314 EmitEOL();
315}
316
317void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
318 OS << "\t.scl\t" << StorageClass << ';';
319 EmitEOL();
320}
321
322void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
323 OS << "\t.type\t" << Type << ';';
324 EmitEOL();
325}
326
327void MCAsmStreamer::EndCOFFSymbolDef() {
328 OS << "\t.endef";
329 EmitEOL();
330}
331
Chris Lattner99328ad2010-01-25 07:52:13 +0000332void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
333 assert(MAI.hasDotTypeDotSizeDirective());
334 OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
335}
336
Chris Lattner9eb158d2010-01-23 07:47:02 +0000337void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000338 unsigned ByteAlignment) {
Chris Lattner9eb158d2010-01-23 07:47:02 +0000339 OS << "\t.comm\t" << *Symbol << ',' << Size;
Chris Lattner6559d762010-01-25 07:29:13 +0000340 if (ByteAlignment != 0) {
Rafael Espindola2e2563b2010-01-26 20:21:43 +0000341 if (MAI.getCOMMDirectiveAlignmentIsInBytes())
Chris Lattner4ed54382010-01-19 06:01:04 +0000342 OS << ',' << ByteAlignment;
343 else
344 OS << ',' << Log2_32(ByteAlignment);
345 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000346 EmitEOL();
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000347}
348
Chris Lattner9eb158d2010-01-23 07:47:02 +0000349/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
350///
351/// @param Symbol - The common symbol to emit.
352/// @param Size - The size of the common symbol.
353void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {
354 assert(MAI.hasLCOMMDirective() && "Doesn't have .lcomm, can't emit it!");
355 OS << "\t.lcomm\t" << *Symbol << ',' << Size;
356 EmitEOL();
357}
358
Daniel Dunbar8751b942009-08-28 05:48:22 +0000359void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000360 unsigned Size, unsigned ByteAlignment) {
Daniel Dunbar011e4db2009-08-13 23:36:34 +0000361 // Note: a .zerofill directive does not switch sections.
Chris Lattner93b6db32009-08-08 23:39:42 +0000362 OS << ".zerofill ";
Jim Grosbach00545e12010-09-22 18:16:55 +0000363
Chris Lattner93b6db32009-08-08 23:39:42 +0000364 // This is a mach-o specific directive.
Chris Lattnerff4bc462009-08-10 01:39:42 +0000365 const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
Daniel Dunbar12de0df2009-08-14 18:51:45 +0000366 OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
Jim Grosbach00545e12010-09-22 18:16:55 +0000367
Chris Lattner9be3fee2009-07-10 22:20:30 +0000368 if (Symbol != NULL) {
Chris Lattner10b318b2010-01-17 21:43:43 +0000369 OS << ',' << *Symbol << ',' << Size;
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000370 if (ByteAlignment != 0)
371 OS << ',' << Log2_32(ByteAlignment);
Chris Lattner9be3fee2009-07-10 22:20:30 +0000372 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000373 EmitEOL();
Chris Lattner9be3fee2009-07-10 22:20:30 +0000374}
375
Eric Christopherd04d98d2010-05-17 02:13:02 +0000376// .tbss sym, size, align
377// This depends that the symbol has already been mangled from the original,
378// e.g. _a.
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000379void MCAsmStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
380 uint64_t Size, unsigned ByteAlignment) {
Eric Christopher482eba02010-05-14 01:50:28 +0000381 assert(Symbol != NULL && "Symbol shouldn't be NULL!");
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000382 // Instead of using the Section we'll just use the shortcut.
383 // This is a mach-o specific directive and section.
Eric Christopherd04d98d2010-05-17 02:13:02 +0000384 OS << ".tbss " << *Symbol << ", " << Size;
Jim Grosbach00545e12010-09-22 18:16:55 +0000385
Eric Christopher4d01cbe2010-05-18 21:16:04 +0000386 // Output align if we have it. We default to 1 so don't bother printing
387 // that.
388 if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
Jim Grosbach00545e12010-09-22 18:16:55 +0000389
Eric Christopher482eba02010-05-14 01:50:28 +0000390 EmitEOL();
391}
392
Chris Lattner12e555c2010-01-23 00:15:00 +0000393static inline char toOctal(int X) { return (X&7)+'0'; }
394
Chris Lattnera6594fc2010-01-25 18:58:59 +0000395static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
396 OS << '"';
Jim Grosbach00545e12010-09-22 18:16:55 +0000397
Chris Lattnera6594fc2010-01-25 18:58:59 +0000398 for (unsigned i = 0, e = Data.size(); i != e; ++i) {
399 unsigned char C = Data[i];
400 if (C == '"' || C == '\\') {
401 OS << '\\' << (char)C;
402 continue;
403 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000404
Chris Lattnera6594fc2010-01-25 18:58:59 +0000405 if (isprint((unsigned char)C)) {
406 OS << (char)C;
407 continue;
408 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000409
Chris Lattnera6594fc2010-01-25 18:58:59 +0000410 switch (C) {
411 case '\b': OS << "\\b"; break;
412 case '\f': OS << "\\f"; break;
413 case '\n': OS << "\\n"; break;
414 case '\r': OS << "\\r"; break;
415 case '\t': OS << "\\t"; break;
416 default:
417 OS << '\\';
418 OS << toOctal(C >> 6);
419 OS << toOctal(C >> 3);
420 OS << toOctal(C >> 0);
421 break;
422 }
423 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000424
Chris Lattnera6594fc2010-01-25 18:58:59 +0000425 OS << '"';
426}
427
428
Chris Lattneraaec2052010-01-19 19:46:13 +0000429void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000430 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner12e555c2010-01-23 00:15:00 +0000431 if (Data.empty()) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000432
Chris Lattner12e555c2010-01-23 00:15:00 +0000433 if (Data.size() == 1) {
434 OS << MAI.getData8bitsDirective(AddrSpace);
435 OS << (unsigned)(unsigned char)Data[0];
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000436 EmitEOL();
Chris Lattner12e555c2010-01-23 00:15:00 +0000437 return;
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000438 }
Chris Lattner12e555c2010-01-23 00:15:00 +0000439
440 // If the data ends with 0 and the target supports .asciz, use it, otherwise
441 // use .ascii
442 if (MAI.getAscizDirective() && Data.back() == 0) {
443 OS << MAI.getAscizDirective();
444 Data = Data.substr(0, Data.size()-1);
445 } else {
446 OS << MAI.getAsciiDirective();
447 }
448
Chris Lattnera6594fc2010-01-25 18:58:59 +0000449 OS << ' ';
450 PrintQuotedString(Data, OS);
Chris Lattner12e555c2010-01-23 00:15:00 +0000451 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000452}
453
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000454/// EmitIntValue - Special case of EmitValue that avoids the client having
455/// to pass in a MCExpr for constant integers.
456void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size,
457 unsigned AddrSpace) {
458 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000459 const char *Directive = 0;
460 switch (Size) {
461 default: break;
462 case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
463 case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
464 case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
Chris Lattner5eaa54e2010-01-20 06:45:39 +0000465 case 8:
466 Directive = MAI.getData64bitsDirective(AddrSpace);
467 // If the target doesn't support 64-bit data, emit as two 32-bit halves.
468 if (Directive) break;
469 if (isLittleEndian()) {
470 EmitIntValue((uint32_t)(Value >> 0 ), 4, AddrSpace);
471 EmitIntValue((uint32_t)(Value >> 32), 4, AddrSpace);
472 } else {
473 EmitIntValue((uint32_t)(Value >> 32), 4, AddrSpace);
474 EmitIntValue((uint32_t)(Value >> 0 ), 4, AddrSpace);
475 }
476 return;
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000477 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000478
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000479 assert(Directive && "Invalid size for machine code value!");
Chris Lattner86e22112010-01-22 07:29:22 +0000480 OS << Directive << truncateToSize(Value, Size);
481 EmitEOL();
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000482}
483
Chris Lattneraaec2052010-01-19 19:46:13 +0000484void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
485 unsigned AddrSpace) {
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000486 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000487 const char *Directive = 0;
Daniel Dunbara11af532009-06-24 01:03:06 +0000488 switch (Size) {
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000489 default: break;
490 case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
491 case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
492 case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
493 case 8: Directive = MAI.getData64bitsDirective(AddrSpace); break;
Daniel Dunbara11af532009-06-24 01:03:06 +0000494 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000495
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000496 assert(Directive && "Invalid size for machine code value!");
Chris Lattner718fb592010-01-25 21:28:50 +0000497 OS << Directive << *Value;
Chris Lattner86e22112010-01-22 07:29:22 +0000498 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000499}
500
Chris Lattner718fb592010-01-25 21:28:50 +0000501void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
502 assert(MAI.getGPRel32Directive() != 0);
503 OS << MAI.getGPRel32Directive() << *Value;
504 EmitEOL();
505}
506
507
Chris Lattner6113b3d2010-01-19 18:52:28 +0000508/// EmitFill - Emit NumBytes bytes worth of the value specified by
509/// FillValue. This implements directives such as '.space'.
Chris Lattneraaec2052010-01-19 19:46:13 +0000510void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
511 unsigned AddrSpace) {
Chris Lattner8a6d7ac2010-01-19 18:58:52 +0000512 if (NumBytes == 0) return;
Jim Grosbach00545e12010-09-22 18:16:55 +0000513
Chris Lattneraaec2052010-01-19 19:46:13 +0000514 if (AddrSpace == 0)
515 if (const char *ZeroDirective = MAI.getZeroDirective()) {
516 OS << ZeroDirective << NumBytes;
517 if (FillValue != 0)
518 OS << ',' << (int)FillValue;
Chris Lattner86e22112010-01-22 07:29:22 +0000519 EmitEOL();
Chris Lattneraaec2052010-01-19 19:46:13 +0000520 return;
521 }
522
523 // Emit a byte at a time.
524 MCStreamer::EmitFill(NumBytes, FillValue, AddrSpace);
Chris Lattner6113b3d2010-01-19 18:52:28 +0000525}
526
Daniel Dunbar84a29262009-06-24 19:25:34 +0000527void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
528 unsigned ValueSize,
529 unsigned MaxBytesToEmit) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000530 // Some assemblers don't support non-power of two alignments, so we always
531 // emit alignments as a power of two if possible.
532 if (isPowerOf2_32(ByteAlignment)) {
Chris Lattner6e579c62009-08-19 06:35:36 +0000533 switch (ValueSize) {
534 default: llvm_unreachable("Invalid size for machine code value!");
Chris Lattner33adcfb2009-08-22 21:43:10 +0000535 case 1: OS << MAI.getAlignDirective(); break;
536 // FIXME: use MAI for this!
Chris Lattner6e579c62009-08-19 06:35:36 +0000537 case 2: OS << ".p2alignw "; break;
538 case 4: OS << ".p2alignl "; break;
539 case 8: llvm_unreachable("Unsupported alignment size!");
540 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000541
Chris Lattner33adcfb2009-08-22 21:43:10 +0000542 if (MAI.getAlignmentIsInBytes())
Chris Lattner663c2d22009-08-19 06:12:02 +0000543 OS << ByteAlignment;
544 else
545 OS << Log2_32(ByteAlignment);
Daniel Dunbar84a29262009-06-24 19:25:34 +0000546
Chris Lattner663c2d22009-08-19 06:12:02 +0000547 if (Value || MaxBytesToEmit) {
Chris Lattner579531c2009-09-03 04:01:10 +0000548 OS << ", 0x";
549 OS.write_hex(truncateToSize(Value, ValueSize));
Chris Lattner663c2d22009-08-19 06:12:02 +0000550
Jim Grosbach00545e12010-09-22 18:16:55 +0000551 if (MaxBytesToEmit)
Chris Lattner663c2d22009-08-19 06:12:02 +0000552 OS << ", " << MaxBytesToEmit;
553 }
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000554 EmitEOL();
Chris Lattner663c2d22009-08-19 06:12:02 +0000555 return;
556 }
Jim Grosbach00545e12010-09-22 18:16:55 +0000557
Chris Lattner663c2d22009-08-19 06:12:02 +0000558 // Non-power of two alignment. This is not widely supported by assemblers.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000559 // FIXME: Parameterize this based on MAI.
Daniel Dunbar84a29262009-06-24 19:25:34 +0000560 switch (ValueSize) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000561 default: llvm_unreachable("Invalid size for machine code value!");
562 case 1: OS << ".balign"; break;
563 case 2: OS << ".balignw"; break;
564 case 4: OS << ".balignl"; break;
565 case 8: llvm_unreachable("Unsupported alignment size!");
Daniel Dunbar84a29262009-06-24 19:25:34 +0000566 }
567
Chris Lattner663c2d22009-08-19 06:12:02 +0000568 OS << ' ' << ByteAlignment;
Daniel Dunbar304f6a42009-06-25 21:03:18 +0000569 OS << ", " << truncateToSize(Value, ValueSize);
Jim Grosbach00545e12010-09-22 18:16:55 +0000570 if (MaxBytesToEmit)
Daniel Dunbar84a29262009-06-24 19:25:34 +0000571 OS << ", " << MaxBytesToEmit;
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000572 EmitEOL();
Daniel Dunbar84a29262009-06-24 19:25:34 +0000573}
574
Kevin Enderby6e720482010-02-23 18:26:34 +0000575void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
576 unsigned MaxBytesToEmit) {
Chris Lattnerec167fd2010-02-23 18:44:31 +0000577 // Emit with a text fill value.
578 EmitValueToAlignment(ByteAlignment, MAI.getTextAlignFillValue(),
579 1, MaxBytesToEmit);
Kevin Enderby6e720482010-02-23 18:26:34 +0000580}
581
Daniel Dunbar821e3332009-08-31 08:09:28 +0000582void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
Daniel Dunbar84a29262009-06-24 19:25:34 +0000583 unsigned char Value) {
584 // FIXME: Verify that Offset is associated with the current section.
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000585 OS << ".org " << *Offset << ", " << (unsigned) Value;
586 EmitEOL();
Daniel Dunbar84a29262009-06-24 19:25:34 +0000587}
588
Chris Lattnera6594fc2010-01-25 18:58:59 +0000589
590void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
591 assert(MAI.hasSingleParameterDotFile());
592 OS << "\t.file\t";
593 PrintQuotedString(Filename, OS);
594 EmitEOL();
595}
596
597void MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Filename){
598 OS << "\t.file\t" << FileNo << ' ';
599 PrintQuotedString(Filename, OS);
600 EmitEOL();
601}
602
Daniel Dunbar6b716532010-02-09 23:00:14 +0000603void MCAsmStreamer::AddEncodingComment(const MCInst &Inst) {
604 raw_ostream &OS = GetCommentOS();
605 SmallString<256> Code;
606 SmallVector<MCFixup, 4> Fixups;
607 raw_svector_ostream VecOS(Code);
608 Emitter->EncodeInstruction(Inst, VecOS, Fixups);
609 VecOS.flush();
Chris Lattnera6594fc2010-01-25 18:58:59 +0000610
Daniel Dunbar6b716532010-02-09 23:00:14 +0000611 // If we are showing fixups, create symbolic markers in the encoded
612 // representation. We do this by making a per-bit map to the fixup item index,
613 // then trying to display it as nicely as possible.
Daniel Dunbar5532cf42010-02-10 01:41:14 +0000614 SmallVector<uint8_t, 64> FixupMap;
615 FixupMap.resize(Code.size() * 8);
Daniel Dunbar6b716532010-02-09 23:00:14 +0000616 for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
617 FixupMap[i] = 0;
618
619 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
620 MCFixup &F = Fixups[i];
Chris Lattner8d31de62010-02-11 21:27:18 +0000621 const MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
Daniel Dunbar6b716532010-02-09 23:00:14 +0000622 for (unsigned j = 0; j != Info.TargetSize; ++j) {
623 unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
624 assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
625 FixupMap[Index] = 1 + i;
626 }
627 }
628
629 OS << "encoding: [";
630 for (unsigned i = 0, e = Code.size(); i != e; ++i) {
631 if (i)
632 OS << ',';
633
634 // See if all bits are the same map entry.
635 uint8_t MapEntry = FixupMap[i * 8 + 0];
636 for (unsigned j = 1; j != 8; ++j) {
637 if (FixupMap[i * 8 + j] == MapEntry)
638 continue;
639
640 MapEntry = uint8_t(~0U);
641 break;
642 }
643
644 if (MapEntry != uint8_t(~0U)) {
645 if (MapEntry == 0) {
646 OS << format("0x%02x", uint8_t(Code[i]));
647 } else {
648 assert(Code[i] == 0 && "Encoder wrote into fixed up bit!");
649 OS << char('A' + MapEntry - 1);
650 }
651 } else {
652 // Otherwise, write out in binary.
653 OS << "0b";
654 for (unsigned j = 8; j--;) {
655 unsigned Bit = (Code[i] >> j) & 1;
656 if (uint8_t MapEntry = FixupMap[i * 8 + j]) {
657 assert(Bit == 0 && "Encoder wrote into fixed up bit!");
658 OS << char('A' + MapEntry - 1);
659 } else
660 OS << Bit;
661 }
662 }
663 }
664 OS << "]\n";
665
666 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
667 MCFixup &F = Fixups[i];
Chris Lattner8d31de62010-02-11 21:27:18 +0000668 const MCFixupKindInfo &Info = Emitter->getFixupKindInfo(F.getKind());
Daniel Dunbar6b716532010-02-09 23:00:14 +0000669 OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
Daniel Dunbar5d5a1e12010-02-10 04:47:08 +0000670 << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
Daniel Dunbar6b716532010-02-09 23:00:14 +0000671 }
672}
673
674void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
675 assert(CurSection && "Cannot emit contents before setting section!");
676
677 // Show the encoding in a comment if we have a code emitter.
678 if (Emitter)
679 AddEncodingComment(Inst);
680
Chris Lattner30d9a642010-02-09 00:54:51 +0000681 // Show the MCInst if enabled.
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +0000682 if (ShowInst) {
Daniel Dunbar67c076c2010-03-22 21:49:34 +0000683 Inst.dump_pretty(GetCommentOS(), &MAI, InstPrinter.get(), "\n ");
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +0000684 GetCommentOS() << "\n";
685 }
686
Daniel Dunbar67c076c2010-03-22 21:49:34 +0000687 // If we have an AsmPrinter, use that to print, otherwise print the MCInst.
Daniel Dunbar9dee8e32010-02-03 18:18:30 +0000688 if (InstPrinter)
Chris Lattnerd3740872010-04-04 05:04:31 +0000689 InstPrinter->printInst(&Inst, OS);
Daniel Dunbar9dee8e32010-02-03 18:18:30 +0000690 else
691 Inst.print(OS, &MAI);
Chris Lattner7d1e49c2010-01-22 07:36:39 +0000692 EmitEOL();
Daniel Dunbara11af532009-06-24 01:03:06 +0000693}
694
Chris Lattner91bead72010-04-03 21:35:55 +0000695/// EmitRawText - If this file is backed by a assembly streamer, this dumps
696/// the specified string in the output .s file. This capability is
697/// indicated by the hasRawTextSupport() predicate.
698void MCAsmStreamer::EmitRawText(StringRef String) {
Chris Lattnerd5928dc2010-04-03 22:06:56 +0000699 if (!String.empty() && String.back() == '\n')
700 String = String.substr(0, String.size()-1);
Chris Lattner91bead72010-04-03 21:35:55 +0000701 OS << String;
Chris Lattnerd5928dc2010-04-03 22:06:56 +0000702 EmitEOL();
Chris Lattner91bead72010-04-03 21:35:55 +0000703}
704
Daniel Dunbara11af532009-06-24 01:03:06 +0000705void MCAsmStreamer::Finish() {
Daniel Dunbara11af532009-06-24 01:03:06 +0000706}
Daniel Dunbar9dee8e32010-02-03 18:18:30 +0000707
Chris Lattner86e22112010-01-22 07:29:22 +0000708MCStreamer *llvm::createAsmStreamer(MCContext &Context,
709 formatted_raw_ostream &OS,
Chris Lattnerfdab14b2010-03-12 18:28:53 +0000710 bool isLittleEndian,
Chris Lattner07404412010-01-22 07:06:15 +0000711 bool isVerboseAsm, MCInstPrinter *IP,
Daniel Dunbar5532cf42010-02-10 01:41:14 +0000712 MCCodeEmitter *CE, bool ShowInst) {
Chris Lattnerfdab14b2010-03-12 18:28:53 +0000713 return new MCAsmStreamer(Context, OS, isLittleEndian, isVerboseAsm,
Daniel Dunbar5532cf42010-02-10 01:41:14 +0000714 IP, CE, ShowInst);
Daniel Dunbara11af532009-06-24 01:03:06 +0000715}