blob: b13a3dace1309239439c3932238b010f271ce7ca [file] [log] [blame]
Che-Liang Chioud77f2a42010-11-08 02:58:44 +00001//===- lib/Target/PTX/PTXMCAsmStreamer.cpp - PTX 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
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000010#include "llvm/ADT/OwningPtr.h"
11#include "llvm/ADT/SmallString.h"
12#include "llvm/ADT/Twine.h"
Che-Liang Chioud77f2a42010-11-08 02:58:44 +000013#include "llvm/MC/MCAsmInfo.h"
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000014#include "llvm/MC/MCCodeEmitter.h"
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000015#include "llvm/MC/MCContext.h"
Che-Liang Chioud77f2a42010-11-08 02:58:44 +000016#include "llvm/MC/MCExpr.h"
17#include "llvm/MC/MCInst.h"
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000018#include "llvm/MC/MCInstPrinter.h"
19#include "llvm/MC/MCStreamer.h"
Che-Liang Chioud77f2a42010-11-08 02:58:44 +000020#include "llvm/MC/MCSymbol.h"
Che-Liang Chioud77f2a42010-11-08 02:58:44 +000021#include "llvm/Support/ErrorHandling.h"
22#include "llvm/Support/MathExtras.h"
23#include "llvm/Support/Format.h"
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000024#include "llvm/Support/FormattedStream.h"
25#include "llvm/Support/raw_ostream.h"
Che-Liang Chioud77f2a42010-11-08 02:58:44 +000026
27using namespace llvm;
28
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000029namespace {
30class PTXMCAsmStreamer : public MCStreamer {
31 formatted_raw_ostream &OS;
32 const MCAsmInfo &MAI;
33 OwningPtr<MCInstPrinter> InstPrinter;
34 OwningPtr<MCCodeEmitter> Emitter;
35
36 SmallString<128> CommentToEmit;
37 raw_svector_ostream CommentStream;
38
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000039 unsigned IsVerboseAsm : 1;
40 unsigned ShowInst : 1;
41
42public:
43 PTXMCAsmStreamer(MCContext &Context,
44 formatted_raw_ostream &os,
Rafael Espindola89b93722010-12-10 07:39:47 +000045 bool isVerboseAsm, bool useLoc,
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000046 MCInstPrinter *printer,
47 MCCodeEmitter *emitter,
48 bool showInst)
49 : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()),
50 InstPrinter(printer), Emitter(emitter), CommentStream(CommentToEmit),
Rafael Espindola89b93722010-12-10 07:39:47 +000051 IsVerboseAsm(isVerboseAsm),
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000052 ShowInst(showInst) {
53 if (InstPrinter && IsVerboseAsm)
54 InstPrinter->setCommentStream(CommentStream);
55 }
56
57 ~PTXMCAsmStreamer() {}
58
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000059 inline void EmitEOL() {
60 // If we don't have any comments, just emit a \n.
61 if (!IsVerboseAsm) {
62 OS << '\n';
63 return;
64 }
65 EmitCommentsAndEOL();
66 }
67 void EmitCommentsAndEOL();
68
69 /// isVerboseAsm - Return true if this streamer supports verbose assembly at
70 /// all.
71 virtual bool isVerboseAsm() const { return IsVerboseAsm; }
72
73 /// hasRawTextSupport - We support EmitRawText.
74 virtual bool hasRawTextSupport() const { return true; }
75
76 /// AddComment - Add a comment that can be emitted to the generated .s
77 /// file if applicable as a QoI issue to make the output of the compiler
78 /// more readable. This only affects the MCAsmStreamer, and only when
79 /// verbose assembly output is enabled.
80 virtual void AddComment(const Twine &T);
81
82 /// AddEncodingComment - Add a comment showing the encoding of an instruction.
83 virtual void AddEncodingComment(const MCInst &Inst);
84
85 /// GetCommentOS - Return a raw_ostream that comments can be written to.
86 /// Unlike AddComment, you are required to terminate comments with \n if you
87 /// use this method.
88 virtual raw_ostream &GetCommentOS() {
89 if (!IsVerboseAsm)
90 return nulls(); // Discard comments unless in verbose asm mode.
91 return CommentStream;
92 }
93
94 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
95 virtual void AddBlankLine() {
96 EmitEOL();
97 }
98
99 /// @name MCStreamer Interface
100 /// @{
101
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000102 virtual void ChangeSection(const MCSection *Section);
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000103 virtual void InitSections() {}
Rafael Espindolaa484f2c2010-11-28 14:48:34 +0000104
105 virtual void EmitLabel(MCSymbol *Symbol);
106
107 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
108
109 virtual void EmitThumbFunc(MCSymbol *Func);
110
111 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
112
113 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
114
Rafael Espindola32a006e2010-12-03 00:55:40 +0000115 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
116 const MCSymbol *LastLabel,
Evan Cheng672b93a2011-07-14 05:43:07 +0000117 const MCSymbol *Label,
118 unsigned PointerSize);
Rafael Espindola32a006e2010-12-03 00:55:40 +0000119
Rafael Espindolaa484f2c2010-11-28 14:48:34 +0000120 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
121
122 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
123 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
124 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
125 virtual void EmitCOFFSymbolType(int Type);
126 virtual void EndCOFFSymbolDef();
127 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
128 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
129 unsigned ByteAlignment);
130
131 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
132 ///
133 /// @param Symbol - The common symbol to emit.
134 /// @param Size - The size of the common symbol.
135 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
136
137 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
138 unsigned Size = 0, unsigned ByteAlignment = 0);
139
140 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
141 uint64_t Size, unsigned ByteAlignment = 0);
142
143 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
144
Rafael Espindola89b93722010-12-10 07:39:47 +0000145 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
Rafael Espindoladebd7e42011-05-01 03:50:49 +0000146 unsigned AddrSpace);
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000147 virtual void EmitULEB128Value(const MCExpr *Value);
148 virtual void EmitSLEB128Value(const MCExpr *Value);
Rafael Espindolaa484f2c2010-11-28 14:48:34 +0000149 virtual void EmitGPRel32Value(const MCExpr *Value);
150
151
152 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
153 unsigned AddrSpace);
154
155 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
156 unsigned ValueSize = 1,
157 unsigned MaxBytesToEmit = 0);
158
159 virtual void EmitCodeAlignment(unsigned ByteAlignment,
160 unsigned MaxBytesToEmit = 0);
161
162 virtual void EmitValueToOffset(const MCExpr *Offset,
163 unsigned char Value = 0);
164
165 virtual void EmitFileDirective(StringRef Filename);
166 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename);
167
168 virtual void EmitInstruction(const MCInst &Inst);
169
170 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
171 /// the specified string in the output .s file. This capability is
172 /// indicated by the hasRawTextSupport() predicate.
173 virtual void EmitRawText(StringRef String);
174
175 virtual void Finish();
176
177 /// @}
178
179}; // class PTXMCAsmStreamer
180
181}
182
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000183/// TODO: Add appropriate implementation of Emit*() methods when needed
184
185void PTXMCAsmStreamer::AddComment(const Twine &T) {
186 if (!IsVerboseAsm) return;
187
188 // Make sure that CommentStream is flushed.
189 CommentStream.flush();
190
191 T.toVector(CommentToEmit);
192 // Each comment goes on its own line.
193 CommentToEmit.push_back('\n');
194
195 // Tell the comment stream that the vector changed underneath it.
196 CommentStream.resync();
197}
198
199void PTXMCAsmStreamer::EmitCommentsAndEOL() {
200 if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
201 OS << '\n';
202 return;
203 }
204
205 CommentStream.flush();
206 StringRef Comments = CommentToEmit.str();
207
208 assert(Comments.back() == '\n' &&
209 "Comment array not newline terminated");
210 do {
211 // Emit a line of comments.
212 OS.PadToColumn(MAI.getCommentColumn());
213 size_t Position = Comments.find('\n');
214 OS << MAI.getCommentString() << ' ' << Comments.substr(0, Position) << '\n';
215
216 Comments = Comments.substr(Position+1);
217 } while (!Comments.empty());
218
219 CommentToEmit.clear();
220 // Tell the comment stream that the vector changed underneath it.
221 CommentStream.resync();
222}
223
224static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
225 assert(Bytes && "Invalid size!");
226 return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
227}
228
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000229void PTXMCAsmStreamer::ChangeSection(const MCSection *Section) {
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000230 assert(Section && "Cannot switch to a null section!");
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000231}
232
233void PTXMCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
234 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
235 assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
Che-Liang Chiou88d33672011-03-18 11:08:52 +0000236 //assert(getCurrentSection() && "Cannot emit before setting section!");
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000237
238 OS << *Symbol << MAI.getLabelSuffix();
239 EmitEOL();
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000240 Symbol->setSection(*getCurrentSection());
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000241}
242
243void PTXMCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {}
244
245void PTXMCAsmStreamer::EmitThumbFunc(MCSymbol *Func) {}
246
247void PTXMCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
248 OS << *Symbol << " = " << *Value;
249 EmitEOL();
250
251 // FIXME: Lift context changes into super class.
252 Symbol->setVariableValue(Value);
253}
254
255void PTXMCAsmStreamer::EmitWeakReference(MCSymbol *Alias,
256 const MCSymbol *Symbol) {
257 OS << ".weakref " << *Alias << ", " << *Symbol;
258 EmitEOL();
259}
260
Rafael Espindola32a006e2010-12-03 00:55:40 +0000261void PTXMCAsmStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
262 const MCSymbol *LastLabel,
Evan Cheng672b93a2011-07-14 05:43:07 +0000263 const MCSymbol *Label,
264 unsigned PointerSize) {
Rafael Espindola32a006e2010-12-03 00:55:40 +0000265 report_fatal_error("Unimplemented.");
266}
267
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000268void PTXMCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
269 MCSymbolAttr Attribute) {}
270
271void PTXMCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
272
273void PTXMCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {}
274
275void PTXMCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {}
276
277void PTXMCAsmStreamer::EmitCOFFSymbolType (int Type) {}
278
279void PTXMCAsmStreamer::EndCOFFSymbolDef() {}
280
281void PTXMCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
282
283void PTXMCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
284 unsigned ByteAlignment) {}
285
286void PTXMCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {}
287
288void PTXMCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
289 unsigned Size, unsigned ByteAlignment) {}
290
291void PTXMCAsmStreamer::EmitTBSSSymbol(const MCSection *Section,
292 MCSymbol *Symbol,
293 uint64_t Size, unsigned ByteAlignment) {}
294
295static inline char toOctal(int X) { return (X&7)+'0'; }
296
297static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
298 OS << '"';
299
300 for (unsigned i = 0, e = Data.size(); i != e; ++i) {
301 unsigned char C = Data[i];
302 if (C == '"' || C == '\\') {
303 OS << '\\' << (char)C;
304 continue;
305 }
306
307 if (isprint((unsigned char)C)) {
308 OS << (char)C;
309 continue;
310 }
311
312 switch (C) {
313 case '\b': OS << "\\b"; break;
314 case '\f': OS << "\\f"; break;
315 case '\n': OS << "\\n"; break;
316 case '\r': OS << "\\r"; break;
317 case '\t': OS << "\\t"; break;
318 default:
319 OS << '\\';
320 OS << toOctal(C >> 6);
321 OS << toOctal(C >> 3);
322 OS << toOctal(C >> 0);
323 break;
324 }
325 }
326
327 OS << '"';
328}
329
330void PTXMCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000331 assert(getCurrentSection() && "Cannot emit contents before setting section!");
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000332 if (Data.empty()) return;
333
334 if (Data.size() == 1) {
335 OS << MAI.getData8bitsDirective(AddrSpace);
336 OS << (unsigned)(unsigned char)Data[0];
337 EmitEOL();
338 return;
339 }
340
341 // If the data ends with 0 and the target supports .asciz, use it, otherwise
342 // use .ascii
343 if (MAI.getAscizDirective() && Data.back() == 0) {
344 OS << MAI.getAscizDirective();
345 Data = Data.substr(0, Data.size()-1);
346 } else {
347 OS << MAI.getAsciiDirective();
348 }
349
350 OS << ' ';
351 PrintQuotedString(Data, OS);
352 EmitEOL();
353}
354
Rafael Espindola89b93722010-12-10 07:39:47 +0000355void PTXMCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
Rafael Espindoladebd7e42011-05-01 03:50:49 +0000356 unsigned AddrSpace) {
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000357 assert(getCurrentSection() && "Cannot emit contents before setting section!");
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000358 const char *Directive = 0;
359 switch (Size) {
360 default: break;
361 case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break;
362 case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break;
363 case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break;
364 case 8:
365 Directive = MAI.getData64bitsDirective(AddrSpace);
366 // If the target doesn't support 64-bit data, emit as two 32-bit halves.
367 if (Directive) break;
Rafael Espindolaec0b4282010-11-28 23:22:44 +0000368 int64_t IntValue;
369 if (!Value->EvaluateAsAbsolute(IntValue))
370 report_fatal_error("Don't know how to emit this value.");
Evan Cheng1be0e272011-07-15 02:09:41 +0000371 if (getContext().getAsmInfo().isLittleEndian()) {
Rafael Espindolaec0b4282010-11-28 23:22:44 +0000372 EmitIntValue((uint32_t)(IntValue >> 0 ), 4, AddrSpace);
373 EmitIntValue((uint32_t)(IntValue >> 32), 4, AddrSpace);
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000374 } else {
Rafael Espindolaec0b4282010-11-28 23:22:44 +0000375 EmitIntValue((uint32_t)(IntValue >> 32), 4, AddrSpace);
376 EmitIntValue((uint32_t)(IntValue >> 0 ), 4, AddrSpace);
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000377 }
378 return;
379 }
380
381 assert(Directive && "Invalid size for machine code value!");
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000382 OS << Directive << *Value;
383 EmitEOL();
384}
385
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000386void PTXMCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000387 assert(MAI.hasLEB128() && "Cannot print a .uleb");
388 OS << ".uleb128 " << *Value;
389 EmitEOL();
390}
391
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000392void PTXMCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000393 assert(MAI.hasLEB128() && "Cannot print a .sleb");
394 OS << ".sleb128 " << *Value;
395 EmitEOL();
396}
397
398void PTXMCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
399 assert(MAI.getGPRel32Directive() != 0);
400 OS << MAI.getGPRel32Directive() << *Value;
401 EmitEOL();
402}
403
404
405/// EmitFill - Emit NumBytes bytes worth of the value specified by
406/// FillValue. This implements directives such as '.space'.
407void PTXMCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
408 unsigned AddrSpace) {
409 if (NumBytes == 0) return;
410
411 if (AddrSpace == 0)
412 if (const char *ZeroDirective = MAI.getZeroDirective()) {
413 OS << ZeroDirective << NumBytes;
414 if (FillValue != 0)
415 OS << ',' << (int)FillValue;
416 EmitEOL();
417 return;
418 }
419
420 // Emit a byte at a time.
421 MCStreamer::EmitFill(NumBytes, FillValue, AddrSpace);
422}
423
Justin Holewinski12785e82011-03-03 13:34:29 +0000424void PTXMCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment,
425 int64_t Value,
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000426 unsigned ValueSize,
427 unsigned MaxBytesToEmit) {
428 // Some assemblers don't support non-power of two alignments, so we always
429 // emit alignments as a power of two if possible.
430 if (isPowerOf2_32(ByteAlignment)) {
431 switch (ValueSize) {
432 default: llvm_unreachable("Invalid size for machine code value!");
433 case 1: OS << MAI.getAlignDirective(); break;
434 // FIXME: use MAI for this!
435 case 2: OS << ".p2alignw "; break;
436 case 4: OS << ".p2alignl "; break;
437 case 8: llvm_unreachable("Unsupported alignment size!");
438 }
439
440 if (MAI.getAlignmentIsInBytes())
441 OS << ByteAlignment;
442 else
443 OS << Log2_32(ByteAlignment);
444
445 if (Value || MaxBytesToEmit) {
446 OS << ", 0x";
447 OS.write_hex(truncateToSize(Value, ValueSize));
448
449 if (MaxBytesToEmit)
450 OS << ", " << MaxBytesToEmit;
451 }
452 EmitEOL();
453 return;
454 }
455
456 // Non-power of two alignment. This is not widely supported by assemblers.
457 // FIXME: Parameterize this based on MAI.
458 switch (ValueSize) {
459 default: llvm_unreachable("Invalid size for machine code value!");
460 case 1: OS << ".balign"; break;
461 case 2: OS << ".balignw"; break;
462 case 4: OS << ".balignl"; break;
463 case 8: llvm_unreachable("Unsupported alignment size!");
464 }
465
466 OS << ' ' << ByteAlignment;
467 OS << ", " << truncateToSize(Value, ValueSize);
468 if (MaxBytesToEmit)
469 OS << ", " << MaxBytesToEmit;
470 EmitEOL();
471}
472
473void PTXMCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
474 unsigned MaxBytesToEmit) {}
475
476void PTXMCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
477 unsigned char Value) {}
478
479
480void PTXMCAsmStreamer::EmitFileDirective(StringRef Filename) {
481 assert(MAI.hasSingleParameterDotFile());
482 OS << "\t.file\t";
483 PrintQuotedString(Filename, OS);
484 EmitEOL();
485}
486
Rafael Espindolaaf6b58082010-11-16 21:20:32 +0000487// FIXME: should we inherit from MCAsmStreamer?
488bool PTXMCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo,
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000489 StringRef Filename){
490 OS << "\t.file\t" << FileNo << ' ';
491 PrintQuotedString(Filename, OS);
492 EmitEOL();
Rafael Espindolaaf6b58082010-11-16 21:20:32 +0000493 return this->MCStreamer::EmitDwarfFileDirective(FileNo, Filename);
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000494}
495
496void PTXMCAsmStreamer::AddEncodingComment(const MCInst &Inst) {}
497
498void PTXMCAsmStreamer::EmitInstruction(const MCInst &Inst) {
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000499 assert(getCurrentSection() && "Cannot emit contents before setting section!");
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000500
501 // Show the encoding in a comment if we have a code emitter.
502 if (Emitter)
503 AddEncodingComment(Inst);
504
505 // Show the MCInst if enabled.
506 if (ShowInst) {
507 Inst.dump_pretty(GetCommentOS(), &MAI, InstPrinter.get(), "\n ");
508 GetCommentOS() << "\n";
509 }
510
511 // If we have an AsmPrinter, use that to print, otherwise print the MCInst.
512 if (InstPrinter)
513 InstPrinter->printInst(&Inst, OS);
514 else
515 Inst.print(OS, &MAI);
516 EmitEOL();
517}
518
519/// EmitRawText - If this file is backed by an assembly streamer, this dumps
520/// the specified string in the output .s file. This capability is
521/// indicated by the hasRawTextSupport() predicate.
522void PTXMCAsmStreamer::EmitRawText(StringRef String) {
523 if (!String.empty() && String.back() == '\n')
524 String = String.substr(0, String.size()-1);
525 OS << String;
526 EmitEOL();
527}
528
529void PTXMCAsmStreamer::Finish() {}
530
Rafael Espindolaa484f2c2010-11-28 14:48:34 +0000531namespace llvm {
532 MCStreamer *createPTXAsmStreamer(MCContext &Context,
533 formatted_raw_ostream &OS,
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +0000534 bool isVerboseAsm, bool useLoc, bool useCFI,
Rafael Espindola89b93722010-12-10 07:39:47 +0000535 MCInstPrinter *IP,
Daniel Dunbar745dacc2010-12-16 03:05:59 +0000536 MCCodeEmitter *CE, TargetAsmBackend *TAB,
Bill Wendlinge266ce62011-06-17 20:55:01 +0000537 bool ShowInst) {
Rafael Espindola89b93722010-12-10 07:39:47 +0000538 return new PTXMCAsmStreamer(Context, OS, isVerboseAsm, useLoc,
Rafael Espindolaa484f2c2010-11-28 14:48:34 +0000539 IP, CE, ShowInst);
540 }
Che-Liang Chioud77f2a42010-11-08 02:58:44 +0000541}