]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCAsmStreamer.cpp
Merge lld trunk r321017 to contrib/llvm/tools/lld.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / MC / MCAsmStreamer.cpp
1 //===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output ----------*- C++ -*-===//
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/ADT/STLExtras.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/StringExtras.h"
13 #include "llvm/ADT/Twine.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCCodeEmitter.h"
17 #include "llvm/MC/MCCodeView.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCFixupKindInfo.h"
21 #include "llvm/MC/MCInst.h"
22 #include "llvm/MC/MCInstPrinter.h"
23 #include "llvm/MC/MCObjectFileInfo.h"
24 #include "llvm/MC/MCRegisterInfo.h"
25 #include "llvm/MC/MCSectionMachO.h"
26 #include "llvm/MC/MCStreamer.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/Format.h"
29 #include "llvm/Support/FormattedStream.h"
30 #include "llvm/Support/LEB128.h"
31 #include "llvm/Support/MathExtras.h"
32 #include "llvm/Support/Path.h"
33 #include <cctype>
34
35 using namespace llvm;
36
37 namespace {
38
39 class MCAsmStreamer final : public MCStreamer {
40   std::unique_ptr<formatted_raw_ostream> OSOwner;
41   formatted_raw_ostream &OS;
42   const MCAsmInfo *MAI;
43   std::unique_ptr<MCInstPrinter> InstPrinter;
44   std::unique_ptr<MCCodeEmitter> Emitter;
45   std::unique_ptr<MCAsmBackend> AsmBackend;
46
47   SmallString<128> ExplicitCommentToEmit;
48   SmallString<128> CommentToEmit;
49   raw_svector_ostream CommentStream;
50
51   unsigned IsVerboseAsm : 1;
52   unsigned ShowInst : 1;
53   unsigned UseDwarfDirectory : 1;
54
55   void EmitRegisterName(int64_t Register);
56   void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
57   void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
58
59 public:
60   MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
61                 bool isVerboseAsm, bool useDwarfDirectory,
62                 MCInstPrinter *printer, MCCodeEmitter *emitter,
63                 MCAsmBackend *asmbackend, bool showInst)
64       : MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
65         MAI(Context.getAsmInfo()), InstPrinter(printer), Emitter(emitter),
66         AsmBackend(asmbackend), CommentStream(CommentToEmit),
67         IsVerboseAsm(isVerboseAsm), ShowInst(showInst),
68         UseDwarfDirectory(useDwarfDirectory) {
69     assert(InstPrinter);
70     if (IsVerboseAsm)
71         InstPrinter->setCommentStream(CommentStream);
72   }
73
74   inline void EmitEOL() {
75     // Dump Explicit Comments here.
76     emitExplicitComments();
77     // If we don't have any comments, just emit a \n.
78     if (!IsVerboseAsm) {
79       OS << '\n';
80       return;
81     }
82     EmitCommentsAndEOL();
83   }
84
85   void EmitSyntaxDirective() override;
86
87   void EmitCommentsAndEOL();
88
89   /// isVerboseAsm - Return true if this streamer supports verbose assembly at
90   /// all.
91   bool isVerboseAsm() const override { return IsVerboseAsm; }
92
93   /// hasRawTextSupport - We support EmitRawText.
94   bool hasRawTextSupport() const override { return true; }
95
96   /// AddComment - Add a comment that can be emitted to the generated .s
97   /// file if applicable as a QoI issue to make the output of the compiler
98   /// more readable.  This only affects the MCAsmStreamer, and only when
99   /// verbose assembly output is enabled.
100   void AddComment(const Twine &T, bool EOL = true) override;
101
102   /// AddEncodingComment - Add a comment showing the encoding of an instruction.
103   /// If PrintSchedInfo - is true then the comment sched:[x:y] should
104   //    be added to output if it's being supported by target
105   void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &,
106                           bool PrintSchedInfo);
107
108   /// GetCommentOS - Return a raw_ostream that comments can be written to.
109   /// Unlike AddComment, you are required to terminate comments with \n if you
110   /// use this method.
111   raw_ostream &GetCommentOS() override {
112     if (!IsVerboseAsm)
113       return nulls();  // Discard comments unless in verbose asm mode.
114     return CommentStream;
115   }
116
117   void emitRawComment(const Twine &T, bool TabPrefix = true) override;
118
119   void addExplicitComment(const Twine &T) override;
120   void emitExplicitComments() override;
121
122   /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
123   void AddBlankLine() override {
124     EmitEOL();
125   }
126
127   /// @name MCStreamer Interface
128   /// @{
129
130   void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
131
132   void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
133   void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
134
135   void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
136   void EmitLinkerOptions(ArrayRef<std::string> Options) override;
137   void EmitDataRegion(MCDataRegionType Kind) override;
138   void EmitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
139                       unsigned Update) override;
140   void EmitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
141                         unsigned Update) override;
142   void EmitThumbFunc(MCSymbol *Func) override;
143
144   void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
145   void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
146   bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
147
148   void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
149   void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
150   void EmitCOFFSymbolStorageClass(int StorageClass) override;
151   void EmitCOFFSymbolType(int Type) override;
152   void EndCOFFSymbolDef() override;
153   void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
154   void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
155   void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override;
156   void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
157   void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
158                         unsigned ByteAlignment) override;
159
160   /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
161   ///
162   /// @param Symbol - The common symbol to emit.
163   /// @param Size - The size of the common symbol.
164   /// @param ByteAlignment - The alignment of the common symbol in bytes.
165   void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
166                              unsigned ByteAlignment) override;
167
168   void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
169                     uint64_t Size = 0, unsigned ByteAlignment = 0) override;
170
171   void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
172                       unsigned ByteAlignment = 0) override;
173
174   void EmitBinaryData(StringRef Data) override;
175
176   void EmitBytes(StringRef Data) override;
177
178   void EmitValueImpl(const MCExpr *Value, unsigned Size,
179                      SMLoc Loc = SMLoc()) override;
180   void EmitIntValue(uint64_t Value, unsigned Size) override;
181
182   void EmitULEB128Value(const MCExpr *Value) override;
183
184   void EmitSLEB128Value(const MCExpr *Value) override;
185
186   void EmitDTPRel32Value(const MCExpr *Value) override;
187   void EmitDTPRel64Value(const MCExpr *Value) override;
188   void EmitTPRel32Value(const MCExpr *Value) override;
189   void EmitTPRel64Value(const MCExpr *Value) override;
190
191   void EmitGPRel64Value(const MCExpr *Value) override;
192
193   void EmitGPRel32Value(const MCExpr *Value) override;
194
195
196   void emitFill(uint64_t NumBytes, uint8_t FillValue) override;
197
198   void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
199                 SMLoc Loc = SMLoc()) override;
200
201   void emitFill(uint64_t NumValues, int64_t Size, int64_t Expr) override;
202
203   void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
204                 SMLoc Loc = SMLoc()) override;
205
206   void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
207                             unsigned ValueSize = 1,
208                             unsigned MaxBytesToEmit = 0) override;
209
210   void EmitCodeAlignment(unsigned ByteAlignment,
211                          unsigned MaxBytesToEmit = 0) override;
212
213   void emitValueToOffset(const MCExpr *Offset,
214                          unsigned char Value,
215                          SMLoc Loc) override;
216
217   void EmitFileDirective(StringRef Filename) override;
218   unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
219                                   StringRef Filename,
220                                   unsigned CUID = 0) override;
221   void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
222                              unsigned Column, unsigned Flags,
223                              unsigned Isa, unsigned Discriminator,
224                              StringRef FileName) override;
225   MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
226
227   bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
228                            ArrayRef<uint8_t> Checksum,
229                            unsigned ChecksumKind) override;
230   bool EmitCVFuncIdDirective(unsigned FuncId) override;
231   bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
232                                    unsigned IAFile, unsigned IALine,
233                                    unsigned IACol, SMLoc Loc) override;
234   void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
235                           unsigned Column, bool PrologueEnd, bool IsStmt,
236                           StringRef FileName, SMLoc Loc) override;
237   void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart,
238                                 const MCSymbol *FnEnd) override;
239   void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
240                                       unsigned SourceFileId,
241                                       unsigned SourceLineNum,
242                                       const MCSymbol *FnStartSym,
243                                       const MCSymbol *FnEndSym) override;
244   void EmitCVDefRangeDirective(
245       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
246       StringRef FixedSizePortion) override;
247   void EmitCVStringTableDirective() override;
248   void EmitCVFileChecksumsDirective() override;
249   void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override;
250   void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) override;
251
252   void EmitIdent(StringRef IdentString) override;
253   void EmitCFISections(bool EH, bool Debug) override;
254   void EmitCFIDefCfa(int64_t Register, int64_t Offset) override;
255   void EmitCFIDefCfaOffset(int64_t Offset) override;
256   void EmitCFIDefCfaRegister(int64_t Register) override;
257   void EmitCFIOffset(int64_t Register, int64_t Offset) override;
258   void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) override;
259   void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) override;
260   void EmitCFIRememberState() override;
261   void EmitCFIRestoreState() override;
262   void EmitCFIRestore(int64_t Register) override;
263   void EmitCFISameValue(int64_t Register) override;
264   void EmitCFIRelOffset(int64_t Register, int64_t Offset) override;
265   void EmitCFIAdjustCfaOffset(int64_t Adjustment) override;
266   void EmitCFIEscape(StringRef Values) override;
267   void EmitCFIGnuArgsSize(int64_t Size) override;
268   void EmitCFISignalFrame() override;
269   void EmitCFIUndefined(int64_t Register) override;
270   void EmitCFIRegister(int64_t Register1, int64_t Register2) override;
271   void EmitCFIWindowSave() override;
272   void EmitCFIReturnColumn(int64_t Register) override;
273
274   void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) override;
275   void EmitWinCFIEndProc(SMLoc Loc) override;
276   void EmitWinCFIStartChained(SMLoc Loc) override;
277   void EmitWinCFIEndChained(SMLoc Loc) override;
278   void EmitWinCFIPushReg(unsigned Register, SMLoc Loc) override;
279   void EmitWinCFISetFrame(unsigned Register, unsigned Offset,
280                           SMLoc Loc) override;
281   void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) override;
282   void EmitWinCFISaveReg(unsigned Register, unsigned Offset,
283                          SMLoc Loc) override;
284   void EmitWinCFISaveXMM(unsigned Register, unsigned Offset,
285                          SMLoc Loc) override;
286   void EmitWinCFIPushFrame(bool Code, SMLoc Loc) override;
287   void EmitWinCFIEndProlog(SMLoc Loc) override;
288
289   void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
290                         SMLoc Loc) override;
291   void EmitWinEHHandlerData(SMLoc Loc) override;
292
293   void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
294                        bool PrintSchedInfo) override;
295
296   void EmitBundleAlignMode(unsigned AlignPow2) override;
297   void EmitBundleLock(bool AlignToEnd) override;
298   void EmitBundleUnlock() override;
299
300   bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
301                           const MCExpr *Expr, SMLoc Loc) override;
302
303   /// EmitRawText - If this file is backed by an assembly streamer, this dumps
304   /// the specified string in the output .s file.  This capability is
305   /// indicated by the hasRawTextSupport() predicate.
306   void EmitRawTextImpl(StringRef String) override;
307
308   void FinishImpl() override;
309 };
310
311 } // end anonymous namespace.
312
313 /// AddComment - Add a comment that can be emitted to the generated .s
314 /// file if applicable as a QoI issue to make the output of the compiler
315 /// more readable.  This only affects the MCAsmStreamer, and only when
316 /// verbose assembly output is enabled.
317 /// By deafult EOL is set to true so that each comment goes on its own line.
318 void MCAsmStreamer::AddComment(const Twine &T, bool EOL) {
319   if (!IsVerboseAsm) return;
320
321   T.toVector(CommentToEmit);
322  
323   if (EOL)
324     CommentToEmit.push_back('\n'); // Place comment in a new line.
325 }
326
327 void MCAsmStreamer::EmitCommentsAndEOL() {
328   if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
329     OS << '\n';
330     return;
331   }
332
333   StringRef Comments = CommentToEmit;
334
335   assert(Comments.back() == '\n' &&
336          "Comment array not newline terminated");
337   do {
338     // Emit a line of comments.
339     OS.PadToColumn(MAI->getCommentColumn());
340     size_t Position = Comments.find('\n');
341     OS << MAI->getCommentString() << ' ' << Comments.substr(0, Position) <<'\n';
342
343     Comments = Comments.substr(Position+1);
344   } while (!Comments.empty());
345
346   CommentToEmit.clear();
347 }
348
349 static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
350   assert(Bytes > 0 && Bytes <= 8 && "Invalid size!");
351   return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
352 }
353
354 void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) {
355   if (TabPrefix)
356     OS << '\t';
357   OS << MAI->getCommentString() << T;
358   EmitEOL();
359 }
360
361 void MCAsmStreamer::addExplicitComment(const Twine &T) {
362   StringRef c = T.getSingleStringRef();
363   if (c.equals(StringRef(MAI->getSeparatorString())))
364     return;
365   if (c.startswith(StringRef("//"))) {
366     ExplicitCommentToEmit.append("\t");
367     ExplicitCommentToEmit.append(MAI->getCommentString());
368     // drop //
369     ExplicitCommentToEmit.append(c.slice(2, c.size()).str());
370   } else if (c.startswith(StringRef("/*"))) {
371     size_t p = 2, len = c.size() - 2;
372     // emit each line in comment as separate newline.
373     do {
374       size_t newp = std::min(len, c.find_first_of("\r\n", p));
375       ExplicitCommentToEmit.append("\t");
376       ExplicitCommentToEmit.append(MAI->getCommentString());
377       ExplicitCommentToEmit.append(c.slice(p, newp).str());
378       // If we have another line in this comment add line
379       if (newp < len)
380         ExplicitCommentToEmit.append("\n");
381       p = newp + 1;
382     } while (p < len);
383   } else if (c.startswith(StringRef(MAI->getCommentString()))) {
384     ExplicitCommentToEmit.append("\t");
385     ExplicitCommentToEmit.append(c.str());
386   } else if (c.front() == '#') {
387
388     ExplicitCommentToEmit.append("\t");
389     ExplicitCommentToEmit.append(MAI->getCommentString());
390     ExplicitCommentToEmit.append(c.slice(1, c.size()).str());
391   } else
392     assert(false && "Unexpected Assembly Comment");
393   // full line comments immediately output
394   if (c.back() == '\n')
395     emitExplicitComments();
396 }
397
398 void MCAsmStreamer::emitExplicitComments() {
399   StringRef Comments = ExplicitCommentToEmit;
400   if (!Comments.empty())
401     OS << Comments;
402   ExplicitCommentToEmit.clear();
403 }
404
405 void MCAsmStreamer::ChangeSection(MCSection *Section,
406                                   const MCExpr *Subsection) {
407   assert(Section && "Cannot switch to a null section!");
408   Section->PrintSwitchToSection(
409       *MAI, getContext().getObjectFileInfo()->getTargetTriple(), OS,
410       Subsection);
411 }
412
413 void MCAsmStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
414   MCStreamer::EmitLabel(Symbol, Loc);
415
416   Symbol->print(OS, MAI);
417   OS << MAI->getLabelSuffix();
418
419   EmitEOL();
420 }
421
422 void MCAsmStreamer::EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {
423   StringRef str = MCLOHIdToName(Kind);
424
425 #ifndef NDEBUG
426   int NbArgs = MCLOHIdToNbArgs(Kind);
427   assert(NbArgs != -1 && ((size_t)NbArgs) == Args.size() && "Malformed LOH!");
428   assert(str != "" && "Invalid LOH name");
429 #endif
430
431   OS << "\t" << MCLOHDirectiveName() << " " << str << "\t";
432   bool IsFirst = true;
433   for (const MCSymbol *Arg : Args) {
434     if (!IsFirst)
435       OS << ", ";
436     IsFirst = false;
437     Arg->print(OS, MAI);
438   }
439   EmitEOL();
440 }
441
442 void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
443   switch (Flag) {
444   case MCAF_SyntaxUnified:         OS << "\t.syntax unified"; break;
445   case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
446   case MCAF_Code16:                OS << '\t'<< MAI->getCode16Directive();break;
447   case MCAF_Code32:                OS << '\t'<< MAI->getCode32Directive();break;
448   case MCAF_Code64:                OS << '\t'<< MAI->getCode64Directive();break;
449   }
450   EmitEOL();
451 }
452
453 void MCAsmStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
454   assert(!Options.empty() && "At least one option is required!");
455   OS << "\t.linker_option \"" << Options[0] << '"';
456   for (ArrayRef<std::string>::iterator it = Options.begin() + 1,
457          ie = Options.end(); it != ie; ++it) {
458     OS << ", " << '"' << *it << '"';
459   }
460   EmitEOL();
461 }
462
463 void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
464   if (!MAI->doesSupportDataRegionDirectives())
465     return;
466   switch (Kind) {
467   case MCDR_DataRegion:            OS << "\t.data_region"; break;
468   case MCDR_DataRegionJT8:         OS << "\t.data_region jt8"; break;
469   case MCDR_DataRegionJT16:        OS << "\t.data_region jt16"; break;
470   case MCDR_DataRegionJT32:        OS << "\t.data_region jt32"; break;
471   case MCDR_DataRegionEnd:         OS << "\t.end_data_region"; break;
472   }
473   EmitEOL();
474 }
475
476 static const char *getVersionMinDirective(MCVersionMinType Type) {
477   switch (Type) {
478   case MCVM_WatchOSVersionMin: return ".watchos_version_min";
479   case MCVM_TvOSVersionMin:    return ".tvos_version_min";
480   case MCVM_IOSVersionMin:     return ".ios_version_min";
481   case MCVM_OSXVersionMin:     return ".macosx_version_min";
482   }
483   llvm_unreachable("Invalid MC version min type");
484 }
485
486 void MCAsmStreamer::EmitVersionMin(MCVersionMinType Type, unsigned Major,
487                                    unsigned Minor, unsigned Update) {
488   OS << '\t' << getVersionMinDirective(Type) << ' ' << Major << ", " << Minor;
489   if (Update)
490     OS << ", " << Update;
491   EmitEOL();
492 }
493
494 static const char *getPlatformName(MachO::PlatformType Type) {
495   switch (Type) {
496   case MachO::PLATFORM_MACOS:    return "macos";
497   case MachO::PLATFORM_IOS:      return "ios";
498   case MachO::PLATFORM_TVOS:     return "tvos";
499   case MachO::PLATFORM_WATCHOS:  return "watchos";
500   case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
501   }
502   llvm_unreachable("Invalid Mach-O platform type");
503 }
504
505 void MCAsmStreamer::EmitBuildVersion(unsigned Platform, unsigned Major,
506                                      unsigned Minor, unsigned Update) {
507   const char *PlatformName = getPlatformName((MachO::PlatformType)Platform);
508   OS << "\t.build_version " << PlatformName << ", " << Major << ", " << Minor;
509   if (Update)
510     OS << ", " << Update;
511   EmitEOL();
512 }
513
514 void MCAsmStreamer::EmitThumbFunc(MCSymbol *Func) {
515   // This needs to emit to a temporary string to get properly quoted
516   // MCSymbols when they have spaces in them.
517   OS << "\t.thumb_func";
518   // Only Mach-O hasSubsectionsViaSymbols()
519   if (MAI->hasSubsectionsViaSymbols()) {
520     OS << '\t';
521     Func->print(OS, MAI);
522   }
523   EmitEOL();
524 }
525
526 void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
527   Symbol->print(OS, MAI);
528   OS << " = ";
529   Value->print(OS, MAI);
530
531   EmitEOL();
532
533   MCStreamer::EmitAssignment(Symbol, Value);
534 }
535
536 void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
537   OS << ".weakref ";
538   Alias->print(OS, MAI);
539   OS << ", ";
540   Symbol->print(OS, MAI);
541   EmitEOL();
542 }
543
544 bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
545                                         MCSymbolAttr Attribute) {
546   switch (Attribute) {
547   case MCSA_Invalid: llvm_unreachable("Invalid symbol attribute");
548   case MCSA_ELF_TypeFunction:    /// .type _foo, STT_FUNC  # aka @function
549   case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
550   case MCSA_ELF_TypeObject:      /// .type _foo, STT_OBJECT  # aka @object
551   case MCSA_ELF_TypeTLS:         /// .type _foo, STT_TLS     # aka @tls_object
552   case MCSA_ELF_TypeCommon:      /// .type _foo, STT_COMMON  # aka @common
553   case MCSA_ELF_TypeNoType:      /// .type _foo, STT_NOTYPE  # aka @notype
554   case MCSA_ELF_TypeGnuUniqueObject:  /// .type _foo, @gnu_unique_object
555     if (!MAI->hasDotTypeDotSizeDirective())
556       return false; // Symbol attribute not supported
557     OS << "\t.type\t";
558     Symbol->print(OS, MAI);
559     OS << ',' << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
560     switch (Attribute) {
561     default: return false;
562     case MCSA_ELF_TypeFunction:    OS << "function"; break;
563     case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
564     case MCSA_ELF_TypeObject:      OS << "object"; break;
565     case MCSA_ELF_TypeTLS:         OS << "tls_object"; break;
566     case MCSA_ELF_TypeCommon:      OS << "common"; break;
567     case MCSA_ELF_TypeNoType:      OS << "no_type"; break;
568     case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
569     }
570     EmitEOL();
571     return true;
572   case MCSA_Global: // .globl/.global
573     OS << MAI->getGlobalDirective();
574     break;
575   case MCSA_Hidden:         OS << "\t.hidden\t";          break;
576   case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
577   case MCSA_Internal:       OS << "\t.internal\t";        break;
578   case MCSA_LazyReference:  OS << "\t.lazy_reference\t";  break;
579   case MCSA_Local:          OS << "\t.local\t";           break;
580   case MCSA_NoDeadStrip:
581     if (!MAI->hasNoDeadStrip())
582       return false;
583     OS << "\t.no_dead_strip\t";
584     break;
585   case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break;
586   case MCSA_AltEntry:       OS << "\t.alt_entry\t";       break;
587   case MCSA_PrivateExtern:
588     OS << "\t.private_extern\t";
589     break;
590   case MCSA_Protected:      OS << "\t.protected\t";       break;
591   case MCSA_Reference:      OS << "\t.reference\t";       break;
592   case MCSA_Weak:           OS << MAI->getWeakDirective(); break;
593   case MCSA_WeakDefinition:
594     OS << "\t.weak_definition\t";
595     break;
596       // .weak_reference
597   case MCSA_WeakReference:  OS << MAI->getWeakRefDirective(); break;
598   case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
599   }
600
601   Symbol->print(OS, MAI);
602   EmitEOL();
603
604   return true;
605 }
606
607 void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
608   OS << ".desc" << ' ';
609   Symbol->print(OS, MAI);
610   OS << ',' << DescValue;
611   EmitEOL();
612 }
613
614 void MCAsmStreamer::EmitSyntaxDirective() {
615   if (MAI->getAssemblerDialect() == 1) {
616     OS << "\t.intel_syntax noprefix";
617     EmitEOL();
618   }
619   // FIXME: Currently emit unprefix'ed registers.
620   // The intel_syntax directive has one optional argument 
621   // with may have a value of prefix or noprefix.
622 }
623
624 void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
625   OS << "\t.def\t ";
626   Symbol->print(OS, MAI);
627   OS << ';';
628   EmitEOL();
629 }
630
631 void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
632   OS << "\t.scl\t" << StorageClass << ';';
633   EmitEOL();
634 }
635
636 void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
637   OS << "\t.type\t" << Type << ';';
638   EmitEOL();
639 }
640
641 void MCAsmStreamer::EndCOFFSymbolDef() {
642   OS << "\t.endef";
643   EmitEOL();
644 }
645
646 void MCAsmStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
647   OS << "\t.safeseh\t";
648   Symbol->print(OS, MAI);
649   EmitEOL();
650 }
651
652 void MCAsmStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
653   OS << "\t.secidx\t";
654   Symbol->print(OS, MAI);
655   EmitEOL();
656 }
657
658 void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) {
659   OS << "\t.secrel32\t";
660   Symbol->print(OS, MAI);
661   if (Offset != 0)
662     OS << '+' << Offset;
663   EmitEOL();
664 }
665
666 void MCAsmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
667   assert(MAI->hasDotTypeDotSizeDirective());
668   OS << "\t.size\t";
669   Symbol->print(OS, MAI);
670   OS << ", ";
671   Value->print(OS, MAI);
672   EmitEOL();
673 }
674
675 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
676                                      unsigned ByteAlignment) {
677   OS << "\t.comm\t";
678   Symbol->print(OS, MAI);
679   OS << ',' << Size;
680
681   if (ByteAlignment != 0) {
682     if (MAI->getCOMMDirectiveAlignmentIsInBytes())
683       OS << ',' << ByteAlignment;
684     else
685       OS << ',' << Log2_32(ByteAlignment);
686   }
687   EmitEOL();
688 }
689
690 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
691 ///
692 /// @param Symbol - The common symbol to emit.
693 /// @param Size - The size of the common symbol.
694 void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
695                                           unsigned ByteAlign) {
696   OS << "\t.lcomm\t";
697   Symbol->print(OS, MAI);
698   OS << ',' << Size;
699
700   if (ByteAlign > 1) {
701     switch (MAI->getLCOMMDirectiveAlignmentType()) {
702     case LCOMM::NoAlignment:
703       llvm_unreachable("alignment not supported on .lcomm!");
704     case LCOMM::ByteAlignment:
705       OS << ',' << ByteAlign;
706       break;
707     case LCOMM::Log2Alignment:
708       assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2");
709       OS << ',' << Log2_32(ByteAlign);
710       break;
711     }
712   }
713   EmitEOL();
714 }
715
716 void MCAsmStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
717                                  uint64_t Size, unsigned ByteAlignment) {
718   if (Symbol)
719     AssignFragment(Symbol, &Section->getDummyFragment());
720
721   // Note: a .zerofill directive does not switch sections.
722   OS << ".zerofill ";
723
724   // This is a mach-o specific directive.
725   const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
726   OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
727
728   if (Symbol) {
729     OS << ',';
730     Symbol->print(OS, MAI);
731     OS << ',' << Size;
732     if (ByteAlignment != 0)
733       OS << ',' << Log2_32(ByteAlignment);
734   }
735   EmitEOL();
736 }
737
738 // .tbss sym, size, align
739 // This depends that the symbol has already been mangled from the original,
740 // e.g. _a.
741 void MCAsmStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
742                                    uint64_t Size, unsigned ByteAlignment) {
743   AssignFragment(Symbol, &Section->getDummyFragment());
744
745   assert(Symbol && "Symbol shouldn't be NULL!");
746   // Instead of using the Section we'll just use the shortcut.
747   // This is a mach-o specific directive and section.
748   OS << ".tbss ";
749   Symbol->print(OS, MAI);
750   OS << ", " << Size;
751
752   // Output align if we have it.  We default to 1 so don't bother printing
753   // that.
754   if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
755
756   EmitEOL();
757 }
758
759 static inline char toOctal(int X) { return (X&7)+'0'; }
760
761 static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
762   OS << '"';
763
764   for (unsigned i = 0, e = Data.size(); i != e; ++i) {
765     unsigned char C = Data[i];
766     if (C == '"' || C == '\\') {
767       OS << '\\' << (char)C;
768       continue;
769     }
770
771     if (isprint((unsigned char)C)) {
772       OS << (char)C;
773       continue;
774     }
775
776     switch (C) {
777       case '\b': OS << "\\b"; break;
778       case '\f': OS << "\\f"; break;
779       case '\n': OS << "\\n"; break;
780       case '\r': OS << "\\r"; break;
781       case '\t': OS << "\\t"; break;
782       default:
783         OS << '\\';
784         OS << toOctal(C >> 6);
785         OS << toOctal(C >> 3);
786         OS << toOctal(C >> 0);
787         break;
788     }
789   }
790
791   OS << '"';
792 }
793
794 void MCAsmStreamer::EmitBytes(StringRef Data) {
795   assert(getCurrentSectionOnly() &&
796          "Cannot emit contents before setting section!");
797   if (Data.empty()) return;
798
799   if (Data.size() == 1) {
800     OS << MAI->getData8bitsDirective();
801     OS << (unsigned)(unsigned char)Data[0];
802     EmitEOL();
803     return;
804   }
805
806   // If the data ends with 0 and the target supports .asciz, use it, otherwise
807   // use .ascii
808   if (MAI->getAscizDirective() && Data.back() == 0) {
809     OS << MAI->getAscizDirective();
810     Data = Data.substr(0, Data.size()-1);
811   } else {
812     OS << MAI->getAsciiDirective();
813   }
814
815   PrintQuotedString(Data, OS);
816   EmitEOL();
817 }
818
819 void MCAsmStreamer::EmitBinaryData(StringRef Data) {
820   // This is binary data. Print it in a grid of hex bytes for readability.
821   const size_t Cols = 4;
822   for (size_t I = 0, EI = alignTo(Data.size(), Cols); I < EI; I += Cols) {
823     size_t J = I, EJ = std::min(I + Cols, Data.size());
824     assert(EJ > 0);
825     OS << MAI->getData8bitsDirective();
826     for (; J < EJ - 1; ++J)
827       OS << format("0x%02x", uint8_t(Data[J])) << ", ";
828     OS << format("0x%02x", uint8_t(Data[J]));
829     EmitEOL();
830   }
831 }
832
833 void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
834   EmitValue(MCConstantExpr::create(Value, getContext()), Size);
835 }
836
837 void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
838                                   SMLoc Loc) {
839   assert(Size <= 8 && "Invalid size");
840   assert(getCurrentSectionOnly() &&
841          "Cannot emit contents before setting section!");
842   const char *Directive = nullptr;
843   switch (Size) {
844   default: break;
845   case 1: Directive = MAI->getData8bitsDirective();  break;
846   case 2: Directive = MAI->getData16bitsDirective(); break;
847   case 4: Directive = MAI->getData32bitsDirective(); break;
848   case 8: Directive = MAI->getData64bitsDirective(); break;
849   }
850
851   if (!Directive) {
852     int64_t IntValue;
853     if (!Value->evaluateAsAbsolute(IntValue))
854       report_fatal_error("Don't know how to emit this value.");
855
856     // We couldn't handle the requested integer size so we fallback by breaking
857     // the request down into several, smaller, integers.
858     // Since sizes greater or equal to "Size" are invalid, we use the greatest
859     // power of 2 that is less than "Size" as our largest piece of granularity.
860     bool IsLittleEndian = MAI->isLittleEndian();
861     for (unsigned Emitted = 0; Emitted != Size;) {
862       unsigned Remaining = Size - Emitted;
863       // The size of our partial emission must be a power of two less than
864       // Size.
865       unsigned EmissionSize = PowerOf2Floor(std::min(Remaining, Size - 1));
866       // Calculate the byte offset of our partial emission taking into account
867       // the endianness of the target.
868       unsigned ByteOffset =
869           IsLittleEndian ? Emitted : (Remaining - EmissionSize);
870       uint64_t ValueToEmit = IntValue >> (ByteOffset * 8);
871       // We truncate our partial emission to fit within the bounds of the
872       // emission domain.  This produces nicer output and silences potential
873       // truncation warnings when round tripping through another assembler.
874       uint64_t Shift = 64 - EmissionSize * 8;
875       assert(Shift < static_cast<uint64_t>(
876                          std::numeric_limits<unsigned long long>::digits) &&
877              "undefined behavior");
878       ValueToEmit &= ~0ULL >> Shift;
879       EmitIntValue(ValueToEmit, EmissionSize);
880       Emitted += EmissionSize;
881     }
882     return;
883   }
884
885   assert(Directive && "Invalid size for machine code value!");
886   OS << Directive;
887   Value->print(OS, MAI);
888   EmitEOL();
889 }
890
891 void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
892   int64_t IntValue;
893   if (Value->evaluateAsAbsolute(IntValue)) {
894     EmitULEB128IntValue(IntValue);
895     return;
896   }
897   OS << ".uleb128 ";
898   Value->print(OS, MAI);
899   EmitEOL();
900 }
901
902 void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
903   int64_t IntValue;
904   if (Value->evaluateAsAbsolute(IntValue)) {
905     EmitSLEB128IntValue(IntValue);
906     return;
907   }
908   OS << ".sleb128 ";
909   Value->print(OS, MAI);
910   EmitEOL();
911 }
912
913 void MCAsmStreamer::EmitDTPRel64Value(const MCExpr *Value) {
914   assert(MAI->getDTPRel64Directive() != nullptr);
915   OS << MAI->getDTPRel64Directive();
916   Value->print(OS, MAI);
917   EmitEOL();
918 }
919
920 void MCAsmStreamer::EmitDTPRel32Value(const MCExpr *Value) {
921   assert(MAI->getDTPRel32Directive() != nullptr);
922   OS << MAI->getDTPRel32Directive();
923   Value->print(OS, MAI);
924   EmitEOL();
925 }
926
927 void MCAsmStreamer::EmitTPRel64Value(const MCExpr *Value) {
928   assert(MAI->getTPRel64Directive() != nullptr);
929   OS << MAI->getTPRel64Directive();
930   Value->print(OS, MAI);
931   EmitEOL();
932 }
933
934 void MCAsmStreamer::EmitTPRel32Value(const MCExpr *Value) {
935   assert(MAI->getTPRel32Directive() != nullptr);
936   OS << MAI->getTPRel32Directive();
937   Value->print(OS, MAI);
938   EmitEOL();
939 }
940
941 void MCAsmStreamer::EmitGPRel64Value(const MCExpr *Value) {
942   assert(MAI->getGPRel64Directive() != nullptr);
943   OS << MAI->getGPRel64Directive();
944   Value->print(OS, MAI);
945   EmitEOL();
946 }
947
948 void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
949   assert(MAI->getGPRel32Directive() != nullptr);
950   OS << MAI->getGPRel32Directive();
951   Value->print(OS, MAI);
952   EmitEOL();
953 }
954
955 /// emitFill - Emit NumBytes bytes worth of the value specified by
956 /// FillValue.  This implements directives such as '.space'.
957 void MCAsmStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
958   if (NumBytes == 0) return;
959
960   const MCExpr *E = MCConstantExpr::create(NumBytes, getContext());
961   emitFill(*E, FillValue);
962 }
963
964 void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
965                              SMLoc Loc) {
966   if (const char *ZeroDirective = MAI->getZeroDirective()) {
967     // FIXME: Emit location directives
968     OS << ZeroDirective;
969     NumBytes.print(OS, MAI);
970     if (FillValue != 0)
971       OS << ',' << (int)FillValue;
972     EmitEOL();
973     return;
974   }
975
976   MCStreamer::emitFill(NumBytes, FillValue);
977 }
978
979 void MCAsmStreamer::emitFill(uint64_t NumValues, int64_t Size, int64_t Expr) {
980   if (NumValues == 0)
981     return;
982
983   const MCExpr *E = MCConstantExpr::create(NumValues, getContext());
984   emitFill(*E, Size, Expr);
985 }
986
987 void MCAsmStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
988                              int64_t Expr, SMLoc Loc) {
989   // FIXME: Emit location directives
990   OS << "\t.fill\t";
991   NumValues.print(OS, MAI);
992   OS << ", " << Size << ", 0x";
993   OS.write_hex(truncateToSize(Expr, 4));
994   EmitEOL();
995 }
996
997 void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
998                                          unsigned ValueSize,
999                                          unsigned MaxBytesToEmit) {
1000   // Some assemblers don't support non-power of two alignments, so we always
1001   // emit alignments as a power of two if possible.
1002   if (isPowerOf2_32(ByteAlignment)) {
1003     switch (ValueSize) {
1004     default:
1005       llvm_unreachable("Invalid size for machine code value!");
1006     case 1:
1007       OS << "\t.p2align\t";
1008       break;
1009     case 2:
1010       OS << ".p2alignw ";
1011       break;
1012     case 4:
1013       OS << ".p2alignl ";
1014       break;
1015     case 8:
1016       llvm_unreachable("Unsupported alignment size!");
1017     }
1018
1019     OS << Log2_32(ByteAlignment);
1020
1021     if (Value || MaxBytesToEmit) {
1022       OS << ", 0x";
1023       OS.write_hex(truncateToSize(Value, ValueSize));
1024
1025       if (MaxBytesToEmit)
1026         OS << ", " << MaxBytesToEmit;
1027     }
1028     EmitEOL();
1029     return;
1030   }
1031
1032   // Non-power of two alignment.  This is not widely supported by assemblers.
1033   // FIXME: Parameterize this based on MAI.
1034   switch (ValueSize) {
1035   default: llvm_unreachable("Invalid size for machine code value!");
1036   case 1: OS << ".balign";  break;
1037   case 2: OS << ".balignw"; break;
1038   case 4: OS << ".balignl"; break;
1039   case 8: llvm_unreachable("Unsupported alignment size!");
1040   }
1041
1042   OS << ' ' << ByteAlignment;
1043   OS << ", " << truncateToSize(Value, ValueSize);
1044   if (MaxBytesToEmit)
1045     OS << ", " << MaxBytesToEmit;
1046   EmitEOL();
1047 }
1048
1049 void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
1050                                       unsigned MaxBytesToEmit) {
1051   // Emit with a text fill value.
1052   EmitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(),
1053                        1, MaxBytesToEmit);
1054 }
1055
1056 void MCAsmStreamer::emitValueToOffset(const MCExpr *Offset,
1057                                       unsigned char Value,
1058                                       SMLoc Loc) {
1059   // FIXME: Verify that Offset is associated with the current section.
1060   OS << ".org ";
1061   Offset->print(OS, MAI);
1062   OS << ", " << (unsigned)Value;
1063   EmitEOL();
1064 }
1065
1066 void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
1067   assert(MAI->hasSingleParameterDotFile());
1068   OS << "\t.file\t";
1069   PrintQuotedString(Filename, OS);
1070   EmitEOL();
1071 }
1072
1073 unsigned MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo,
1074                                                StringRef Directory,
1075                                                StringRef Filename,
1076                                                unsigned CUID) {
1077   assert(CUID == 0);
1078
1079   MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
1080   unsigned NumFiles = Table.getMCDwarfFiles().size();
1081   FileNo = Table.getFile(Directory, Filename, FileNo);
1082   if (FileNo == 0)
1083     return 0;
1084   if (NumFiles == Table.getMCDwarfFiles().size())
1085     return FileNo;
1086
1087   SmallString<128> FullPathName;
1088
1089   if (!UseDwarfDirectory && !Directory.empty()) {
1090     if (sys::path::is_absolute(Filename))
1091       Directory = "";
1092     else {
1093       FullPathName = Directory;
1094       sys::path::append(FullPathName, Filename);
1095       Directory = "";
1096       Filename = FullPathName;
1097     }
1098   }
1099
1100   OS << "\t.file\t" << FileNo << ' ';
1101   if (!Directory.empty()) {
1102     PrintQuotedString(Directory, OS);
1103     OS << ' ';
1104   }
1105   PrintQuotedString(Filename, OS);
1106   EmitEOL();
1107
1108   return FileNo;
1109 }
1110
1111 void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
1112                                           unsigned Column, unsigned Flags,
1113                                           unsigned Isa,
1114                                           unsigned Discriminator,
1115                                           StringRef FileName) {
1116   OS << "\t.loc\t" << FileNo << " " << Line << " " << Column;
1117   if (Flags & DWARF2_FLAG_BASIC_BLOCK)
1118     OS << " basic_block";
1119   if (Flags & DWARF2_FLAG_PROLOGUE_END)
1120     OS << " prologue_end";
1121   if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
1122     OS << " epilogue_begin";
1123
1124   unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags();
1125   if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
1126     OS << " is_stmt ";
1127
1128     if (Flags & DWARF2_FLAG_IS_STMT)
1129       OS << "1";
1130     else
1131       OS << "0";
1132   }
1133
1134   if (Isa)
1135     OS << " isa " << Isa;
1136   if (Discriminator)
1137     OS << " discriminator " << Discriminator;
1138
1139   if (IsVerboseAsm) {
1140     OS.PadToColumn(MAI->getCommentColumn());
1141     OS << MAI->getCommentString() << ' ' << FileName << ':'
1142        << Line << ':' << Column;
1143   }
1144   EmitEOL();
1145   this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
1146                                           Isa, Discriminator, FileName);
1147 }
1148
1149 MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(unsigned CUID) {
1150   // Always use the zeroth line table, since asm syntax only supports one line
1151   // table for now.
1152   return MCStreamer::getDwarfLineTableSymbol(0);
1153 }
1154
1155 bool MCAsmStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename,
1156                                         ArrayRef<uint8_t> Checksum,
1157                                         unsigned ChecksumKind) {
1158   if (!getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum,
1159                                            ChecksumKind))
1160     return false;
1161
1162   OS << "\t.cv_file\t" << FileNo << ' ';
1163   PrintQuotedString(Filename, OS);
1164
1165   if (!ChecksumKind) {
1166     EmitEOL();
1167     return true;
1168   }
1169
1170   OS << ' ';
1171   PrintQuotedString(toHex(Checksum), OS);
1172   OS << ' ' << ChecksumKind;
1173
1174   EmitEOL();
1175   return true;
1176 }
1177
1178 bool MCAsmStreamer::EmitCVFuncIdDirective(unsigned FuncId) {
1179   OS << "\t.cv_func_id " << FuncId << '\n';
1180   return MCStreamer::EmitCVFuncIdDirective(FuncId);
1181 }
1182
1183 bool MCAsmStreamer::EmitCVInlineSiteIdDirective(unsigned FunctionId,
1184                                                 unsigned IAFunc,
1185                                                 unsigned IAFile,
1186                                                 unsigned IALine, unsigned IACol,
1187                                                 SMLoc Loc) {
1188   OS << "\t.cv_inline_site_id " << FunctionId << " within " << IAFunc
1189      << " inlined_at " << IAFile << ' ' << IALine << ' ' << IACol << '\n';
1190   return MCStreamer::EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
1191                                                  IALine, IACol, Loc);
1192 }
1193
1194 void MCAsmStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
1195                                        unsigned Line, unsigned Column,
1196                                        bool PrologueEnd, bool IsStmt,
1197                                        StringRef FileName, SMLoc Loc) {
1198   OS << "\t.cv_loc\t" << FunctionId << " " << FileNo << " " << Line << " "
1199      << Column;
1200   if (PrologueEnd)
1201     OS << " prologue_end";
1202
1203   unsigned OldIsStmt = getContext().getCVContext().getCurrentCVLoc().isStmt();
1204   if (IsStmt != OldIsStmt) {
1205     OS << " is_stmt ";
1206
1207     if (IsStmt)
1208       OS << "1";
1209     else
1210       OS << "0";
1211   }
1212
1213   if (IsVerboseAsm) {
1214     OS.PadToColumn(MAI->getCommentColumn());
1215     OS << MAI->getCommentString() << ' ' << FileName << ':' << Line << ':'
1216        << Column;
1217   }
1218   EmitEOL();
1219   this->MCStreamer::EmitCVLocDirective(FunctionId, FileNo, Line, Column,
1220                                        PrologueEnd, IsStmt, FileName, Loc);
1221 }
1222
1223 void MCAsmStreamer::EmitCVLinetableDirective(unsigned FunctionId,
1224                                              const MCSymbol *FnStart,
1225                                              const MCSymbol *FnEnd) {
1226   OS << "\t.cv_linetable\t" << FunctionId << ", ";
1227   FnStart->print(OS, MAI);
1228   OS << ", ";
1229   FnEnd->print(OS, MAI);
1230   EmitEOL();
1231   this->MCStreamer::EmitCVLinetableDirective(FunctionId, FnStart, FnEnd);
1232 }
1233
1234 void MCAsmStreamer::EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
1235                                                    unsigned SourceFileId,
1236                                                    unsigned SourceLineNum,
1237                                                    const MCSymbol *FnStartSym,
1238                                                    const MCSymbol *FnEndSym) {
1239   OS << "\t.cv_inline_linetable\t" << PrimaryFunctionId << ' ' << SourceFileId
1240      << ' ' << SourceLineNum << ' ';
1241   FnStartSym->print(OS, MAI);
1242   OS << ' ';
1243   FnEndSym->print(OS, MAI);
1244   EmitEOL();
1245   this->MCStreamer::EmitCVInlineLinetableDirective(
1246       PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
1247 }
1248
1249 void MCAsmStreamer::EmitCVDefRangeDirective(
1250     ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1251     StringRef FixedSizePortion) {
1252   OS << "\t.cv_def_range\t";
1253   for (std::pair<const MCSymbol *, const MCSymbol *> Range : Ranges) {
1254     OS << ' ';
1255     Range.first->print(OS, MAI);
1256     OS << ' ';
1257     Range.second->print(OS, MAI);
1258   }
1259   OS << ", ";
1260   PrintQuotedString(FixedSizePortion, OS);
1261   EmitEOL();
1262   this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
1263 }
1264
1265 void MCAsmStreamer::EmitCVStringTableDirective() {
1266   OS << "\t.cv_stringtable";
1267   EmitEOL();
1268 }
1269
1270 void MCAsmStreamer::EmitCVFileChecksumsDirective() {
1271   OS << "\t.cv_filechecksums";
1272   EmitEOL();
1273 }
1274
1275 void MCAsmStreamer::EmitCVFileChecksumOffsetDirective(unsigned FileNo) {
1276   OS << "\t.cv_filechecksumoffset\t" << FileNo;
1277   EmitEOL();
1278 }
1279
1280 void MCAsmStreamer::EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) {
1281   OS << "\t.cv_fpo_data\t";
1282   ProcSym->print(OS, MAI);
1283   EmitEOL();
1284 }
1285
1286 void MCAsmStreamer::EmitIdent(StringRef IdentString) {
1287   assert(MAI->hasIdentDirective() && ".ident directive not supported");
1288   OS << "\t.ident\t";
1289   PrintQuotedString(IdentString, OS);
1290   EmitEOL();
1291 }
1292
1293 void MCAsmStreamer::EmitCFISections(bool EH, bool Debug) {
1294   MCStreamer::EmitCFISections(EH, Debug);
1295   OS << "\t.cfi_sections ";
1296   if (EH) {
1297     OS << ".eh_frame";
1298     if (Debug)
1299       OS << ", .debug_frame";
1300   } else if (Debug) {
1301     OS << ".debug_frame";
1302   }
1303
1304   EmitEOL();
1305 }
1306
1307 void MCAsmStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
1308   OS << "\t.cfi_startproc";
1309   if (Frame.IsSimple)
1310     OS << " simple";
1311   EmitEOL();
1312 }
1313
1314 void MCAsmStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
1315   MCStreamer::EmitCFIEndProcImpl(Frame);
1316   OS << "\t.cfi_endproc";
1317   EmitEOL();
1318 }
1319
1320 void MCAsmStreamer::EmitRegisterName(int64_t Register) {
1321   if (!MAI->useDwarfRegNumForCFI()) {
1322     // User .cfi_* directives can use arbitrary DWARF register numbers, not
1323     // just ones that map to LLVM register numbers and have known names.
1324     // Fall back to using the original number directly if no name is known.
1325     const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1326     int LLVMRegister = MRI->getLLVMRegNumFromEH(Register);
1327     if (LLVMRegister != -1) {
1328       InstPrinter->printRegName(OS, LLVMRegister);
1329       return;
1330     }
1331   }
1332   OS << Register;
1333 }
1334
1335 void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
1336   MCStreamer::EmitCFIDefCfa(Register, Offset);
1337   OS << "\t.cfi_def_cfa ";
1338   EmitRegisterName(Register);
1339   OS << ", " << Offset;
1340   EmitEOL();
1341 }
1342
1343 void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
1344   MCStreamer::EmitCFIDefCfaOffset(Offset);
1345   OS << "\t.cfi_def_cfa_offset " << Offset;
1346   EmitEOL();
1347 }
1348
1349 static void PrintCFIEscape(llvm::formatted_raw_ostream &OS, StringRef Values) {
1350   OS << "\t.cfi_escape ";
1351   if (!Values.empty()) {
1352     size_t e = Values.size() - 1;
1353     for (size_t i = 0; i < e; ++i)
1354       OS << format("0x%02x", uint8_t(Values[i])) << ", ";
1355     OS << format("0x%02x", uint8_t(Values[e]));
1356   }
1357 }
1358
1359 void MCAsmStreamer::EmitCFIEscape(StringRef Values) {
1360   MCStreamer::EmitCFIEscape(Values);
1361   PrintCFIEscape(OS, Values);
1362   EmitEOL();
1363 }
1364
1365 void MCAsmStreamer::EmitCFIGnuArgsSize(int64_t Size) {
1366   MCStreamer::EmitCFIGnuArgsSize(Size);
1367
1368   uint8_t Buffer[16] = { dwarf::DW_CFA_GNU_args_size };
1369   unsigned Len = encodeULEB128(Size, Buffer + 1) + 1;
1370
1371   PrintCFIEscape(OS, StringRef((const char *)&Buffer[0], Len));
1372   EmitEOL();
1373 }
1374
1375 void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
1376   MCStreamer::EmitCFIDefCfaRegister(Register);
1377   OS << "\t.cfi_def_cfa_register ";
1378   EmitRegisterName(Register);
1379   EmitEOL();
1380 }
1381
1382 void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
1383   this->MCStreamer::EmitCFIOffset(Register, Offset);
1384   OS << "\t.cfi_offset ";
1385   EmitRegisterName(Register);
1386   OS << ", " << Offset;
1387   EmitEOL();
1388 }
1389
1390 void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
1391                                        unsigned Encoding) {
1392   MCStreamer::EmitCFIPersonality(Sym, Encoding);
1393   OS << "\t.cfi_personality " << Encoding << ", ";
1394   Sym->print(OS, MAI);
1395   EmitEOL();
1396 }
1397
1398 void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
1399   MCStreamer::EmitCFILsda(Sym, Encoding);
1400   OS << "\t.cfi_lsda " << Encoding << ", ";
1401   Sym->print(OS, MAI);
1402   EmitEOL();
1403 }
1404
1405 void MCAsmStreamer::EmitCFIRememberState() {
1406   MCStreamer::EmitCFIRememberState();
1407   OS << "\t.cfi_remember_state";
1408   EmitEOL();
1409 }
1410
1411 void MCAsmStreamer::EmitCFIRestoreState() {
1412   MCStreamer::EmitCFIRestoreState();
1413   OS << "\t.cfi_restore_state";
1414   EmitEOL();
1415 }
1416
1417 void MCAsmStreamer::EmitCFIRestore(int64_t Register) {
1418   MCStreamer::EmitCFIRestore(Register);
1419   OS << "\t.cfi_restore ";
1420   EmitRegisterName(Register);
1421   EmitEOL();
1422 }
1423
1424 void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
1425   MCStreamer::EmitCFISameValue(Register);
1426   OS << "\t.cfi_same_value ";
1427   EmitRegisterName(Register);
1428   EmitEOL();
1429 }
1430
1431 void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
1432   MCStreamer::EmitCFIRelOffset(Register, Offset);
1433   OS << "\t.cfi_rel_offset ";
1434   EmitRegisterName(Register);
1435   OS << ", " << Offset;
1436   EmitEOL();
1437 }
1438
1439 void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
1440   MCStreamer::EmitCFIAdjustCfaOffset(Adjustment);
1441   OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
1442   EmitEOL();
1443 }
1444
1445 void MCAsmStreamer::EmitCFISignalFrame() {
1446   MCStreamer::EmitCFISignalFrame();
1447   OS << "\t.cfi_signal_frame";
1448   EmitEOL();
1449 }
1450
1451 void MCAsmStreamer::EmitCFIUndefined(int64_t Register) {
1452   MCStreamer::EmitCFIUndefined(Register);
1453   OS << "\t.cfi_undefined " << Register;
1454   EmitEOL();
1455 }
1456
1457 void MCAsmStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
1458   MCStreamer::EmitCFIRegister(Register1, Register2);
1459   OS << "\t.cfi_register " << Register1 << ", " << Register2;
1460   EmitEOL();
1461 }
1462
1463 void MCAsmStreamer::EmitCFIWindowSave() {
1464   MCStreamer::EmitCFIWindowSave();
1465   OS << "\t.cfi_window_save";
1466   EmitEOL();
1467 }
1468
1469 void MCAsmStreamer::EmitCFIReturnColumn(int64_t Register) {
1470   MCStreamer::EmitCFIReturnColumn(Register);
1471   OS << "\t.cfi_return_column " << Register;
1472   EmitEOL();
1473 }
1474
1475 void MCAsmStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) {
1476   MCStreamer::EmitWinCFIStartProc(Symbol, Loc);
1477
1478   OS << ".seh_proc ";
1479   Symbol->print(OS, MAI);
1480   EmitEOL();
1481 }
1482
1483 void MCAsmStreamer::EmitWinCFIEndProc(SMLoc Loc) {
1484   MCStreamer::EmitWinCFIEndProc(Loc);
1485
1486   OS << "\t.seh_endproc";
1487   EmitEOL();
1488 }
1489
1490 void MCAsmStreamer::EmitWinCFIStartChained(SMLoc Loc) {
1491   MCStreamer::EmitWinCFIStartChained(Loc);
1492
1493   OS << "\t.seh_startchained";
1494   EmitEOL();
1495 }
1496
1497 void MCAsmStreamer::EmitWinCFIEndChained(SMLoc Loc) {
1498   MCStreamer::EmitWinCFIEndChained(Loc);
1499
1500   OS << "\t.seh_endchained";
1501   EmitEOL();
1502 }
1503
1504 void MCAsmStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
1505                                      bool Except, SMLoc Loc) {
1506   MCStreamer::EmitWinEHHandler(Sym, Unwind, Except, Loc);
1507
1508   OS << "\t.seh_handler ";
1509   Sym->print(OS, MAI);
1510   if (Unwind)
1511     OS << ", @unwind";
1512   if (Except)
1513     OS << ", @except";
1514   EmitEOL();
1515 }
1516
1517 void MCAsmStreamer::EmitWinEHHandlerData(SMLoc Loc) {
1518   MCStreamer::EmitWinEHHandlerData(Loc);
1519
1520   // Switch sections. Don't call SwitchSection directly, because that will
1521   // cause the section switch to be visible in the emitted assembly.
1522   // We only do this so the section switch that terminates the handler
1523   // data block is visible.
1524   WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
1525   MCSection *TextSec = &CurFrame->Function->getSection();
1526   MCSection *XData = getAssociatedXDataSection(TextSec);
1527   SwitchSectionNoChange(XData);
1528
1529   OS << "\t.seh_handlerdata";
1530   EmitEOL();
1531 }
1532
1533 void MCAsmStreamer::EmitWinCFIPushReg(unsigned Register, SMLoc Loc) {
1534   MCStreamer::EmitWinCFIPushReg(Register, Loc);
1535
1536   OS << "\t.seh_pushreg " << Register;
1537   EmitEOL();
1538 }
1539
1540 void MCAsmStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset,
1541                                        SMLoc Loc) {
1542   MCStreamer::EmitWinCFISetFrame(Register, Offset, Loc);
1543
1544   OS << "\t.seh_setframe " << Register << ", " << Offset;
1545   EmitEOL();
1546 }
1547
1548 void MCAsmStreamer::EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) {
1549   MCStreamer::EmitWinCFIAllocStack(Size, Loc);
1550
1551   OS << "\t.seh_stackalloc " << Size;
1552   EmitEOL();
1553 }
1554
1555 void MCAsmStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset,
1556                                       SMLoc Loc) {
1557   MCStreamer::EmitWinCFISaveReg(Register, Offset, Loc);
1558
1559   OS << "\t.seh_savereg " << Register << ", " << Offset;
1560   EmitEOL();
1561 }
1562
1563 void MCAsmStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset,
1564                                       SMLoc Loc) {
1565   MCStreamer::EmitWinCFISaveXMM(Register, Offset, Loc);
1566
1567   OS << "\t.seh_savexmm " << Register << ", " << Offset;
1568   EmitEOL();
1569 }
1570
1571 void MCAsmStreamer::EmitWinCFIPushFrame(bool Code, SMLoc Loc) {
1572   MCStreamer::EmitWinCFIPushFrame(Code, Loc);
1573
1574   OS << "\t.seh_pushframe";
1575   if (Code)
1576     OS << " @code";
1577   EmitEOL();
1578 }
1579
1580 void MCAsmStreamer::EmitWinCFIEndProlog(SMLoc Loc) {
1581   MCStreamer::EmitWinCFIEndProlog(Loc);
1582
1583   OS << "\t.seh_endprologue";
1584   EmitEOL();
1585 }
1586
1587 void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
1588                                        const MCSubtargetInfo &STI,
1589                                        bool PrintSchedInfo) {
1590   raw_ostream &OS = GetCommentOS();
1591   SmallString<256> Code;
1592   SmallVector<MCFixup, 4> Fixups;
1593   raw_svector_ostream VecOS(Code);
1594   Emitter->encodeInstruction(Inst, VecOS, Fixups, STI);
1595
1596   // If we are showing fixups, create symbolic markers in the encoded
1597   // representation. We do this by making a per-bit map to the fixup item index,
1598   // then trying to display it as nicely as possible.
1599   SmallVector<uint8_t, 64> FixupMap;
1600   FixupMap.resize(Code.size() * 8);
1601   for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
1602     FixupMap[i] = 0;
1603
1604   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1605     MCFixup &F = Fixups[i];
1606     const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
1607     for (unsigned j = 0; j != Info.TargetSize; ++j) {
1608       unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
1609       assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
1610       FixupMap[Index] = 1 + i;
1611     }
1612   }
1613
1614   // FIXME: Note the fixup comments for Thumb2 are completely bogus since the
1615   // high order halfword of a 32-bit Thumb2 instruction is emitted first.
1616   OS << "encoding: [";
1617   for (unsigned i = 0, e = Code.size(); i != e; ++i) {
1618     if (i)
1619       OS << ',';
1620
1621     // See if all bits are the same map entry.
1622     uint8_t MapEntry = FixupMap[i * 8 + 0];
1623     for (unsigned j = 1; j != 8; ++j) {
1624       if (FixupMap[i * 8 + j] == MapEntry)
1625         continue;
1626
1627       MapEntry = uint8_t(~0U);
1628       break;
1629     }
1630
1631     if (MapEntry != uint8_t(~0U)) {
1632       if (MapEntry == 0) {
1633         OS << format("0x%02x", uint8_t(Code[i]));
1634       } else {
1635         if (Code[i]) {
1636           // FIXME: Some of the 8 bits require fix up.
1637           OS << format("0x%02x", uint8_t(Code[i])) << '\''
1638              << char('A' + MapEntry - 1) << '\'';
1639         } else
1640           OS << char('A' + MapEntry - 1);
1641       }
1642     } else {
1643       // Otherwise, write out in binary.
1644       OS << "0b";
1645       for (unsigned j = 8; j--;) {
1646         unsigned Bit = (Code[i] >> j) & 1;
1647
1648         unsigned FixupBit;
1649         if (MAI->isLittleEndian())
1650           FixupBit = i * 8 + j;
1651         else
1652           FixupBit = i * 8 + (7-j);
1653
1654         if (uint8_t MapEntry = FixupMap[FixupBit]) {
1655           assert(Bit == 0 && "Encoder wrote into fixed up bit!");
1656           OS << char('A' + MapEntry - 1);
1657         } else
1658           OS << Bit;
1659       }
1660     }
1661   }
1662   OS << "]";
1663   // If we are not going to add fixup or schedule comments after this point
1664   // then we have to end the current comment line with "\n".
1665   if (Fixups.size() || !PrintSchedInfo)
1666     OS << "\n";
1667
1668   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1669     MCFixup &F = Fixups[i];
1670     const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
1671     OS << "  fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
1672        << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
1673   }
1674 }
1675
1676 void MCAsmStreamer::EmitInstruction(const MCInst &Inst,
1677                                     const MCSubtargetInfo &STI,
1678                                     bool PrintSchedInfo) {
1679   assert(getCurrentSectionOnly() &&
1680          "Cannot emit contents before setting section!");
1681
1682   // Show the encoding in a comment if we have a code emitter.
1683   if (Emitter)
1684     AddEncodingComment(Inst, STI, PrintSchedInfo);
1685
1686   // Show the MCInst if enabled.
1687   if (ShowInst) {
1688     if (PrintSchedInfo)
1689       GetCommentOS() << "\n";
1690     Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n ");
1691     GetCommentOS() << "\n";
1692   }
1693
1694   if(getTargetStreamer())
1695     getTargetStreamer()->prettyPrintAsm(*InstPrinter, OS, Inst, STI);
1696   else
1697     InstPrinter->printInst(&Inst, OS, "", STI);
1698
1699   if (PrintSchedInfo) {
1700     std::string SI = STI.getSchedInfoStr(Inst);
1701     if (!SI.empty())
1702       GetCommentOS() << SI;
1703   }
1704
1705   StringRef Comments = CommentToEmit;
1706   if (Comments.size() && Comments.back() != '\n')
1707     GetCommentOS() << "\n";
1708
1709   EmitEOL();
1710 }
1711
1712 void MCAsmStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
1713   OS << "\t.bundle_align_mode " << AlignPow2;
1714   EmitEOL();
1715 }
1716
1717 void MCAsmStreamer::EmitBundleLock(bool AlignToEnd) {
1718   OS << "\t.bundle_lock";
1719   if (AlignToEnd)
1720     OS << " align_to_end";
1721   EmitEOL();
1722 }
1723
1724 void MCAsmStreamer::EmitBundleUnlock() {
1725   OS << "\t.bundle_unlock";
1726   EmitEOL();
1727 }
1728
1729 bool MCAsmStreamer::EmitRelocDirective(const MCExpr &Offset, StringRef Name,
1730                                        const MCExpr *Expr, SMLoc) {
1731   OS << "\t.reloc ";
1732   Offset.print(OS, MAI);
1733   OS << ", " << Name;
1734   if (Expr) {
1735     OS << ", ";
1736     Expr->print(OS, MAI);
1737   }
1738   EmitEOL();
1739   return false;
1740 }
1741
1742 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
1743 /// the specified string in the output .s file.  This capability is
1744 /// indicated by the hasRawTextSupport() predicate.
1745 void MCAsmStreamer::EmitRawTextImpl(StringRef String) {
1746   if (!String.empty() && String.back() == '\n')
1747     String = String.substr(0, String.size()-1);
1748   OS << String;
1749   EmitEOL();
1750 }
1751
1752 void MCAsmStreamer::FinishImpl() {
1753   // If we are generating dwarf for assembly source files dump out the sections.
1754   if (getContext().getGenDwarfForAssembly())
1755     MCGenDwarfInfo::Emit(this);
1756
1757   // Emit the label for the line table, if requested - since the rest of the
1758   // line table will be defined by .loc/.file directives, and not emitted
1759   // directly, the label is the only work required here.
1760   auto &Tables = getContext().getMCDwarfLineTables();
1761   if (!Tables.empty()) {
1762     assert(Tables.size() == 1 && "asm output only supports one line table");
1763     if (auto *Label = Tables.begin()->second.getLabel()) {
1764       SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
1765       EmitLabel(Label);
1766     }
1767   }
1768 }
1769
1770 MCStreamer *llvm::createAsmStreamer(MCContext &Context,
1771                                     std::unique_ptr<formatted_raw_ostream> OS,
1772                                     bool isVerboseAsm, bool useDwarfDirectory,
1773                                     MCInstPrinter *IP, MCCodeEmitter *CE,
1774                                     MCAsmBackend *MAB, bool ShowInst) {
1775   return new MCAsmStreamer(Context, std::move(OS), isVerboseAsm,
1776                            useDwarfDirectory, IP, CE, MAB, ShowInst);
1777 }