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