blob: 79cb647429506296c5499d80b4b513ae2ed0a1da [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 Dunbar4a0abd82009-08-27 00:51:57 +000011#include "llvm/ADT/SmallString.h"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000012#include "llvm/MC/MCAsmInfo.h"
Daniel Dunbar4a0abd82009-08-27 00:51:57 +000013#include "llvm/MC/MCCodeEmitter.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000014#include "llvm/MC/MCContext.h"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000015#include "llvm/MC/MCExpr.h"
Daniel Dunbarabde2982009-07-01 06:35:03 +000016#include "llvm/MC/MCInst.h"
Chris Lattner90edac02009-09-14 03:02:37 +000017#include "llvm/MC/MCInstPrinter.h"
Chris Lattnerf9bdedd2009-08-10 18:15:01 +000018#include "llvm/MC/MCSectionMachO.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000019#include "llvm/MC/MCSymbol.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000020#include "llvm/Support/ErrorHandling.h"
Chris Lattner663c2d22009-08-19 06:12:02 +000021#include "llvm/Support/MathExtras.h"
Daniel Dunbar4a0abd82009-08-27 00:51:57 +000022#include "llvm/Support/Format.h"
Daniel Dunbara11af532009-06-24 01:03:06 +000023#include "llvm/Support/raw_ostream.h"
24using namespace llvm;
25
26namespace {
27
Chris Lattner46a947d2009-08-17 04:17:34 +000028class MCAsmStreamer : public MCStreamer {
29 raw_ostream &OS;
Chris Lattner33adcfb2009-08-22 21:43:10 +000030 const MCAsmInfo &MAI;
Chris Lattner07404412010-01-22 07:06:15 +000031 bool IsLittleEndian, IsVerboseAsm;
Chris Lattner90edac02009-09-14 03:02:37 +000032 MCInstPrinter *InstPrinter;
Daniel Dunbar4a0abd82009-08-27 00:51:57 +000033 MCCodeEmitter *Emitter;
Chris Lattner46a947d2009-08-17 04:17:34 +000034public:
Chris Lattner07404412010-01-22 07:06:15 +000035 MCAsmStreamer(MCContext &Context, raw_ostream &os, const MCAsmInfo &mai,
36 bool isLittleEndian, bool isVerboseAsm, MCInstPrinter *printer,
37 MCCodeEmitter *emitter)
38 : MCStreamer(Context), OS(os), MAI(mai), IsLittleEndian(isLittleEndian),
39 IsVerboseAsm(isVerboseAsm), InstPrinter(printer), Emitter(emitter) {}
Chris Lattner46a947d2009-08-17 04:17:34 +000040 ~MCAsmStreamer() {}
Daniel Dunbara11af532009-06-24 01:03:06 +000041
Chris Lattner16582022010-01-20 06:39:07 +000042 bool isLittleEndian() const { return IsLittleEndian; }
43
Chris Lattner46a947d2009-08-17 04:17:34 +000044 /// @name MCStreamer Interface
45 /// @{
Daniel Dunbara11af532009-06-24 01:03:06 +000046
Chris Lattner975780b2009-08-17 05:49:08 +000047 virtual void SwitchSection(const MCSection *Section);
Daniel Dunbara11af532009-06-24 01:03:06 +000048
Chris Lattner46a947d2009-08-17 04:17:34 +000049 virtual void EmitLabel(MCSymbol *Symbol);
Daniel Dunbara11af532009-06-24 01:03:06 +000050
Chris Lattner46a947d2009-08-17 04:17:34 +000051 virtual void EmitAssemblerFlag(AssemblerFlag Flag);
Daniel Dunbara11af532009-06-24 01:03:06 +000052
Daniel Dunbar821e3332009-08-31 08:09:28 +000053 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
Daniel Dunbara11af532009-06-24 01:03:06 +000054
Chris Lattner46a947d2009-08-17 04:17:34 +000055 virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
Kevin Enderbya5c78322009-07-13 21:03:15 +000056
Chris Lattner46a947d2009-08-17 04:17:34 +000057 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
Daniel Dunbara11af532009-06-24 01:03:06 +000058
Chris Lattner46a947d2009-08-17 04:17:34 +000059 virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +000060 unsigned ByteAlignment);
Kevin Enderby95cf30c2009-07-14 18:17:10 +000061
Daniel Dunbar8751b942009-08-28 05:48:22 +000062 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +000063 unsigned Size = 0, unsigned ByteAlignment = 0);
Kevin Enderby71148242009-07-14 21:35:03 +000064
Chris Lattneraaec2052010-01-19 19:46:13 +000065 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
Chris Lattner4e4db7a2009-07-07 20:30:46 +000066
Chris Lattneraaec2052010-01-19 19:46:13 +000067 virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
Chris Lattner32ae3fe2010-01-19 22:03:38 +000068 virtual void EmitIntValue(uint64_t Value, unsigned Size, unsigned AddrSpace);
69
Chris Lattneraaec2052010-01-19 19:46:13 +000070 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
71 unsigned AddrSpace);
Chris Lattner9be3fee2009-07-10 22:20:30 +000072
Chris Lattner46a947d2009-08-17 04:17:34 +000073 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
74 unsigned ValueSize = 1,
75 unsigned MaxBytesToEmit = 0);
Daniel Dunbara11af532009-06-24 01:03:06 +000076
Daniel Dunbar821e3332009-08-31 08:09:28 +000077 virtual void EmitValueToOffset(const MCExpr *Offset,
Chris Lattner46a947d2009-08-17 04:17:34 +000078 unsigned char Value = 0);
79
80 virtual void EmitInstruction(const MCInst &Inst);
Daniel Dunbara11af532009-06-24 01:03:06 +000081
Chris Lattner46a947d2009-08-17 04:17:34 +000082 virtual void Finish();
83
84 /// @}
85};
Daniel Dunbar84a29262009-06-24 19:25:34 +000086
Chris Lattner46a947d2009-08-17 04:17:34 +000087} // end anonymous namespace.
Daniel Dunbara11af532009-06-24 01:03:06 +000088
Daniel Dunbar304f6a42009-06-25 21:03:18 +000089static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
90 assert(Bytes && "Invalid size!");
91 return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
92}
93
Daniel Dunbar821e3332009-08-31 08:09:28 +000094static inline const MCExpr *truncateToSize(const MCExpr *Value,
95 unsigned Bytes) {
96 // FIXME: Do we really need this routine?
97 return Value;
Daniel Dunbar304f6a42009-06-25 21:03:18 +000098}
99
Chris Lattner975780b2009-08-17 05:49:08 +0000100void MCAsmStreamer::SwitchSection(const MCSection *Section) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000101 assert(Section && "Cannot switch to a null section!");
Daniel Dunbara11af532009-06-24 01:03:06 +0000102 if (Section != CurSection) {
103 CurSection = Section;
Chris Lattner33adcfb2009-08-22 21:43:10 +0000104 Section->PrintSwitchToSection(MAI, OS);
Daniel Dunbara11af532009-06-24 01:03:06 +0000105 }
106}
107
108void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000109 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000110 assert(CurSection && "Cannot emit before setting section!");
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000111
Chris Lattner10b318b2010-01-17 21:43:43 +0000112 OS << *Symbol << ":\n";
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000113 Symbol->setSection(*CurSection);
Daniel Dunbara11af532009-06-24 01:03:06 +0000114}
115
Kevin Enderbyf96db462009-07-16 17:56:39 +0000116void MCAsmStreamer::EmitAssemblerFlag(AssemblerFlag Flag) {
117 switch (Flag) {
Daniel Dunbar011e4db2009-08-13 23:36:34 +0000118 default: assert(0 && "Invalid flag!");
Kevin Enderbyf96db462009-07-16 17:56:39 +0000119 case SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
120 }
121 OS << '\n';
Kevin Enderbya5c78322009-07-13 21:03:15 +0000122}
123
Daniel Dunbar821e3332009-08-31 08:09:28 +0000124void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000125 // Only absolute symbols can be redefined.
126 assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
127 "Cannot define a symbol twice!");
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000128
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000129 OS << *Symbol << " = " << *Value << '\n';
Daniel Dunbarfffff912009-10-16 01:34:54 +0000130
131 // FIXME: Lift context changes into super class.
Daniel Dunbar75773ff2009-10-16 01:57:39 +0000132 // FIXME: Set associated section.
Daniel Dunbarfffff912009-10-16 01:34:54 +0000133 Symbol->setValue(Value);
Daniel Dunbara11af532009-06-24 01:03:06 +0000134}
135
Daniel Dunbarfffff912009-10-16 01:34:54 +0000136void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
Daniel Dunbara11af532009-06-24 01:03:06 +0000137 SymbolAttr Attribute) {
138 switch (Attribute) {
Chris Lattner32f6a8d2010-01-20 17:50:30 +0000139 case Global: OS << MAI.getGlobalDirective(); break; // .globl
140 case Hidden: OS << ".hidden "; break;
141 case IndirectSymbol: OS << ".indirect_symbol "; break;
142 case Internal: OS << ".internal "; break;
143 case LazyReference: OS << ".lazy_reference "; break;
144 case NoDeadStrip: OS << ".no_dead_strip "; break;
145 case PrivateExtern: OS << ".private_extern "; break;
146 case Protected: OS << ".protected "; break;
147 case Reference: OS << ".reference "; break;
148 case Weak: OS << ".weak "; break;
149 case WeakDefinition: OS << ".weak_definition "; break;
150 case WeakReference: OS << ".weak_reference "; break;
Daniel Dunbara11af532009-06-24 01:03:06 +0000151 }
152
Chris Lattner32f6a8d2010-01-20 17:50:30 +0000153 OS << *Symbol << '\n';
Daniel Dunbara11af532009-06-24 01:03:06 +0000154}
155
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000156void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Chris Lattner10b318b2010-01-17 21:43:43 +0000157 OS << ".desc" << ' ' << *Symbol << ',' << DescValue << '\n';
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000158}
159
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000160void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000161 unsigned ByteAlignment) {
Chris Lattner4ed54382010-01-19 06:01:04 +0000162 OS << MAI.getCOMMDirective() << *Symbol << ',' << Size;
163 if (ByteAlignment != 0 && MAI.getCOMMDirectiveTakesAlignment()) {
164 if (MAI.getAlignmentIsInBytes())
165 OS << ',' << ByteAlignment;
166 else
167 OS << ',' << Log2_32(ByteAlignment);
168 }
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000169 OS << '\n';
170}
171
Daniel Dunbar8751b942009-08-28 05:48:22 +0000172void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000173 unsigned Size, unsigned ByteAlignment) {
Daniel Dunbar011e4db2009-08-13 23:36:34 +0000174 // Note: a .zerofill directive does not switch sections.
Chris Lattner93b6db32009-08-08 23:39:42 +0000175 OS << ".zerofill ";
176
177 // This is a mach-o specific directive.
Chris Lattnerff4bc462009-08-10 01:39:42 +0000178 const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
Daniel Dunbar12de0df2009-08-14 18:51:45 +0000179 OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
Chris Lattner93b6db32009-08-08 23:39:42 +0000180
Chris Lattner9be3fee2009-07-10 22:20:30 +0000181 if (Symbol != NULL) {
Chris Lattner10b318b2010-01-17 21:43:43 +0000182 OS << ',' << *Symbol << ',' << Size;
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000183 if (ByteAlignment != 0)
184 OS << ',' << Log2_32(ByteAlignment);
Chris Lattner9be3fee2009-07-10 22:20:30 +0000185 }
186 OS << '\n';
187}
188
Chris Lattneraaec2052010-01-19 19:46:13 +0000189void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000190 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattneraaec2052010-01-19 19:46:13 +0000191 const char *Directive = MAI.getData8bitsDirective(AddrSpace);
Daniel Dunbar9a7e2cc2009-07-27 21:49:56 +0000192 for (unsigned i = 0, e = Data.size(); i != e; ++i)
Chris Lattneraaec2052010-01-19 19:46:13 +0000193 OS << Directive << (unsigned)(unsigned char)Data[i] << '\n';
Daniel Dunbara11af532009-06-24 01:03:06 +0000194}
195
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000196/// EmitIntValue - Special case of EmitValue that avoids the client having
197/// to pass in a MCExpr for constant integers.
198void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size,
199 unsigned AddrSpace) {
200 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000201 const char *Directive = 0;
202 switch (Size) {
203 default: break;
204 case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
205 case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
206 case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
Chris Lattner5eaa54e2010-01-20 06:45:39 +0000207 case 8:
208 Directive = MAI.getData64bitsDirective(AddrSpace);
209 // If the target doesn't support 64-bit data, emit as two 32-bit halves.
210 if (Directive) break;
211 if (isLittleEndian()) {
212 EmitIntValue((uint32_t)(Value >> 0 ), 4, AddrSpace);
213 EmitIntValue((uint32_t)(Value >> 32), 4, AddrSpace);
214 } else {
215 EmitIntValue((uint32_t)(Value >> 32), 4, AddrSpace);
216 EmitIntValue((uint32_t)(Value >> 0 ), 4, AddrSpace);
217 }
218 return;
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000219 }
220
221 assert(Directive && "Invalid size for machine code value!");
222 OS << Directive << truncateToSize(Value, Size) << '\n';
223}
224
Chris Lattneraaec2052010-01-19 19:46:13 +0000225void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
226 unsigned AddrSpace) {
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000227 assert(CurSection && "Cannot emit contents before setting section!");
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000228 const char *Directive = 0;
Daniel Dunbara11af532009-06-24 01:03:06 +0000229 switch (Size) {
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000230 default: break;
231 case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
232 case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
233 case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
234 case 8: Directive = MAI.getData64bitsDirective(AddrSpace); break;
Daniel Dunbara11af532009-06-24 01:03:06 +0000235 }
Chris Lattneraaec2052010-01-19 19:46:13 +0000236
Chris Lattner32ae3fe2010-01-19 22:03:38 +0000237 assert(Directive && "Invalid size for machine code value!");
238 OS << Directive << *truncateToSize(Value, Size) << '\n';
Daniel Dunbara11af532009-06-24 01:03:06 +0000239}
240
Chris Lattner6113b3d2010-01-19 18:52:28 +0000241/// EmitFill - Emit NumBytes bytes worth of the value specified by
242/// FillValue. This implements directives such as '.space'.
Chris Lattneraaec2052010-01-19 19:46:13 +0000243void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
244 unsigned AddrSpace) {
Chris Lattner8a6d7ac2010-01-19 18:58:52 +0000245 if (NumBytes == 0) return;
246
Chris Lattneraaec2052010-01-19 19:46:13 +0000247 if (AddrSpace == 0)
248 if (const char *ZeroDirective = MAI.getZeroDirective()) {
249 OS << ZeroDirective << NumBytes;
250 if (FillValue != 0)
251 OS << ',' << (int)FillValue;
252 OS << '\n';
253 return;
254 }
255
256 // Emit a byte at a time.
257 MCStreamer::EmitFill(NumBytes, FillValue, AddrSpace);
Chris Lattner6113b3d2010-01-19 18:52:28 +0000258}
259
Daniel Dunbar84a29262009-06-24 19:25:34 +0000260void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
261 unsigned ValueSize,
262 unsigned MaxBytesToEmit) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000263 // Some assemblers don't support non-power of two alignments, so we always
264 // emit alignments as a power of two if possible.
265 if (isPowerOf2_32(ByteAlignment)) {
Chris Lattner6e579c62009-08-19 06:35:36 +0000266 switch (ValueSize) {
267 default: llvm_unreachable("Invalid size for machine code value!");
Chris Lattner33adcfb2009-08-22 21:43:10 +0000268 case 1: OS << MAI.getAlignDirective(); break;
269 // FIXME: use MAI for this!
Chris Lattner6e579c62009-08-19 06:35:36 +0000270 case 2: OS << ".p2alignw "; break;
271 case 4: OS << ".p2alignl "; break;
272 case 8: llvm_unreachable("Unsupported alignment size!");
273 }
Chris Lattner663c2d22009-08-19 06:12:02 +0000274
Chris Lattner33adcfb2009-08-22 21:43:10 +0000275 if (MAI.getAlignmentIsInBytes())
Chris Lattner663c2d22009-08-19 06:12:02 +0000276 OS << ByteAlignment;
277 else
278 OS << Log2_32(ByteAlignment);
Daniel Dunbar84a29262009-06-24 19:25:34 +0000279
Chris Lattner663c2d22009-08-19 06:12:02 +0000280 if (Value || MaxBytesToEmit) {
Chris Lattner579531c2009-09-03 04:01:10 +0000281 OS << ", 0x";
282 OS.write_hex(truncateToSize(Value, ValueSize));
Chris Lattner663c2d22009-08-19 06:12:02 +0000283
284 if (MaxBytesToEmit)
285 OS << ", " << MaxBytesToEmit;
286 }
287 OS << '\n';
288 return;
289 }
290
291 // Non-power of two alignment. This is not widely supported by assemblers.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000292 // FIXME: Parameterize this based on MAI.
Daniel Dunbar84a29262009-06-24 19:25:34 +0000293 switch (ValueSize) {
Chris Lattner663c2d22009-08-19 06:12:02 +0000294 default: llvm_unreachable("Invalid size for machine code value!");
295 case 1: OS << ".balign"; break;
296 case 2: OS << ".balignw"; break;
297 case 4: OS << ".balignl"; break;
298 case 8: llvm_unreachable("Unsupported alignment size!");
Daniel Dunbar84a29262009-06-24 19:25:34 +0000299 }
300
Chris Lattner663c2d22009-08-19 06:12:02 +0000301 OS << ' ' << ByteAlignment;
Daniel Dunbar304f6a42009-06-25 21:03:18 +0000302 OS << ", " << truncateToSize(Value, ValueSize);
Daniel Dunbar84a29262009-06-24 19:25:34 +0000303 if (MaxBytesToEmit)
304 OS << ", " << MaxBytesToEmit;
305 OS << '\n';
306}
307
Daniel Dunbar821e3332009-08-31 08:09:28 +0000308void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
Daniel Dunbar84a29262009-06-24 19:25:34 +0000309 unsigned char Value) {
310 // FIXME: Verify that Offset is associated with the current section.
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000311 OS << ".org " << *Offset << ", " << (unsigned) Value << '\n';
Daniel Dunbar84a29262009-06-24 19:25:34 +0000312}
313
Daniel Dunbara11af532009-06-24 01:03:06 +0000314void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
Daniel Dunbar71d259b2009-06-24 17:00:42 +0000315 assert(CurSection && "Cannot emit contents before setting section!");
Daniel Dunbarc22e0b22009-08-14 03:48:55 +0000316
317 // If we have an AsmPrinter, use that to print.
Chris Lattner90edac02009-09-14 03:02:37 +0000318 if (InstPrinter) {
319 InstPrinter->printInst(&Inst);
Chris Lattner1b6570e2009-09-13 22:24:34 +0000320 OS << '\n';
Daniel Dunbara356aea2009-08-27 07:58:57 +0000321
322 // Show the encoding if we have a code emitter.
323 if (Emitter) {
324 SmallString<256> Code;
325 raw_svector_ostream VecOS(Code);
326 Emitter->EncodeInstruction(Inst, VecOS);
327 VecOS.flush();
328
329 OS.indent(20);
330 OS << " # encoding: [";
331 for (unsigned i = 0, e = Code.size(); i != e; ++i) {
332 if (i)
333 OS << ',';
334 OS << format("%#04x", uint8_t(Code[i]));
335 }
336 OS << "]\n";
337 }
338
Daniel Dunbarc22e0b22009-08-14 03:48:55 +0000339 return;
340 }
341
342 // Otherwise fall back to a structural printing for now. Eventually we should
343 // always have access to the target specific printer.
Chris Lattner684c593d2009-09-03 05:46:51 +0000344 Inst.print(OS, &MAI);
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000345 OS << '\n';
Daniel Dunbara11af532009-06-24 01:03:06 +0000346}
347
348void MCAsmStreamer::Finish() {
349 OS.flush();
350}
351
Daniel Dunbarc22e0b22009-08-14 03:48:55 +0000352MCStreamer *llvm::createAsmStreamer(MCContext &Context, raw_ostream &OS,
Chris Lattner16582022010-01-20 06:39:07 +0000353 const MCAsmInfo &MAI, bool isLittleEndian,
Chris Lattner07404412010-01-22 07:06:15 +0000354 bool isVerboseAsm, MCInstPrinter *IP,
Daniel Dunbar4a0abd82009-08-27 00:51:57 +0000355 MCCodeEmitter *CE) {
Chris Lattner07404412010-01-22 07:06:15 +0000356 return new MCAsmStreamer(Context, OS, MAI, isLittleEndian, isVerboseAsm,
357 IP, CE);
Daniel Dunbara11af532009-06-24 01:03:06 +0000358}