1 //===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output ----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/Optional.h"
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/DebugInfo/CodeView/SymbolRecord.h"
15 #include "llvm/MC/MCAsmBackend.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCAssembler.h"
18 #include "llvm/MC/MCCodeEmitter.h"
19 #include "llvm/MC/MCCodeView.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCFixupKindInfo.h"
23 #include "llvm/MC/MCInst.h"
24 #include "llvm/MC/MCInstPrinter.h"
25 #include "llvm/MC/MCObjectFileInfo.h"
26 #include "llvm/MC/MCObjectWriter.h"
27 #include "llvm/MC/MCRegister.h"
28 #include "llvm/MC/MCRegisterInfo.h"
29 #include "llvm/MC/MCSectionMachO.h"
30 #include "llvm/MC/MCStreamer.h"
31 #include "llvm/MC/MCSymbolXCOFF.h"
32 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/Format.h"
34 #include "llvm/Support/FormattedStream.h"
35 #include "llvm/Support/LEB128.h"
36 #include "llvm/Support/MathExtras.h"
37 #include "llvm/Support/Path.h"
38 #include "llvm/Support/TargetRegistry.h"
45 class MCAsmStreamer final : public MCStreamer {
46 std::unique_ptr<formatted_raw_ostream> OSOwner;
47 formatted_raw_ostream &OS;
49 std::unique_ptr<MCInstPrinter> InstPrinter;
50 std::unique_ptr<MCAssembler> Assembler;
52 SmallString<128> ExplicitCommentToEmit;
53 SmallString<128> CommentToEmit;
54 raw_svector_ostream CommentStream;
55 raw_null_ostream NullStream;
57 unsigned IsVerboseAsm : 1;
58 unsigned ShowInst : 1;
59 unsigned UseDwarfDirectory : 1;
61 void EmitRegisterName(int64_t Register);
62 void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
63 void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
66 MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
67 bool isVerboseAsm, bool useDwarfDirectory,
68 MCInstPrinter *printer, std::unique_ptr<MCCodeEmitter> emitter,
69 std::unique_ptr<MCAsmBackend> asmbackend, bool showInst)
70 : MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
71 MAI(Context.getAsmInfo()), InstPrinter(printer),
72 Assembler(std::make_unique<MCAssembler>(
73 Context, std::move(asmbackend), std::move(emitter),
74 (asmbackend) ? asmbackend->createObjectWriter(NullStream)
76 CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
77 ShowInst(showInst), UseDwarfDirectory(useDwarfDirectory) {
80 InstPrinter->setCommentStream(CommentStream);
81 if (Assembler->getBackendPtr())
82 setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
84 Context.setUseNamesOnTempLabels(true);
87 MCAssembler &getAssembler() { return *Assembler; }
88 MCAssembler *getAssemblerPtr() override { return nullptr; }
90 inline void EmitEOL() {
91 // Dump Explicit Comments here.
92 emitExplicitComments();
93 // If we don't have any comments, just emit a \n.
101 void emitSyntaxDirective() override;
103 void EmitCommentsAndEOL();
105 /// Return true if this streamer supports verbose assembly at all.
106 bool isVerboseAsm() const override { return IsVerboseAsm; }
108 /// Do we support EmitRawText?
109 bool hasRawTextSupport() const override { return true; }
111 /// Add a comment that can be emitted to the generated .s file to make the
112 /// output of the compiler more readable. This only affects the MCAsmStreamer
113 /// and only when verbose assembly output is enabled.
114 void AddComment(const Twine &T, bool EOL = true) override;
116 /// Add a comment showing the encoding of an instruction.
117 void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &);
119 /// Return a raw_ostream that comments can be written to.
120 /// Unlike AddComment, you are required to terminate comments with \n if you
122 raw_ostream &GetCommentOS() override {
124 return nulls(); // Discard comments unless in verbose asm mode.
125 return CommentStream;
128 void emitRawComment(const Twine &T, bool TabPrefix = true) override;
130 void addExplicitComment(const Twine &T) override;
131 void emitExplicitComments() override;
133 /// Emit a blank line to a .s file to pretty it up.
134 void AddBlankLine() override {
138 /// @name MCStreamer Interface
141 void changeSection(MCSection *Section, const MCExpr *Subsection) override;
143 void emitELFSymverDirective(StringRef AliasName,
144 const MCSymbol *Aliasee) override;
146 void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
147 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
149 void emitAssemblerFlag(MCAssemblerFlag Flag) override;
150 void emitLinkerOptions(ArrayRef<std::string> Options) override;
151 void emitDataRegion(MCDataRegionType Kind) override;
152 void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
153 unsigned Update, VersionTuple SDKVersion) override;
154 void emitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
155 unsigned Update, VersionTuple SDKVersion) override;
156 void emitThumbFunc(MCSymbol *Func) override;
158 void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
159 void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
160 bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
162 void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
163 void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
164 void EmitCOFFSymbolStorageClass(int StorageClass) override;
165 void EmitCOFFSymbolType(int Type) override;
166 void EndCOFFSymbolDef() override;
167 void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
168 void EmitCOFFSymbolIndex(MCSymbol const *Symbol) override;
169 void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
170 void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override;
171 void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) override;
172 void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
174 unsigned ByteAlign) override;
175 void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
176 MCSymbolAttr Linakge,
177 MCSymbolAttr Visibility) override;
178 void emitXCOFFRenameDirective(const MCSymbol *Name,
179 StringRef Rename) override;
181 void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
182 void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
183 unsigned ByteAlignment) override;
185 /// Emit a local common (.lcomm) symbol.
187 /// @param Symbol - The common symbol to emit.
188 /// @param Size - The size of the common symbol.
189 /// @param ByteAlignment - The alignment of the common symbol in bytes.
190 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
191 unsigned ByteAlignment) override;
193 void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
194 uint64_t Size = 0, unsigned ByteAlignment = 0,
195 SMLoc Loc = SMLoc()) override;
197 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
198 unsigned ByteAlignment = 0) override;
200 void emitBinaryData(StringRef Data) override;
202 void emitBytes(StringRef Data) override;
204 void emitValueImpl(const MCExpr *Value, unsigned Size,
205 SMLoc Loc = SMLoc()) override;
206 void emitIntValue(uint64_t Value, unsigned Size) override;
207 void emitIntValueInHex(uint64_t Value, unsigned Size) override;
208 void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) override;
210 void emitULEB128Value(const MCExpr *Value) override;
212 void emitSLEB128Value(const MCExpr *Value) override;
214 void emitDTPRel32Value(const MCExpr *Value) override;
215 void emitDTPRel64Value(const MCExpr *Value) override;
216 void emitTPRel32Value(const MCExpr *Value) override;
217 void emitTPRel64Value(const MCExpr *Value) override;
219 void emitGPRel64Value(const MCExpr *Value) override;
221 void emitGPRel32Value(const MCExpr *Value) override;
223 void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
224 SMLoc Loc = SMLoc()) override;
226 void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
227 SMLoc Loc = SMLoc()) override;
229 void emitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
230 unsigned ValueSize = 1,
231 unsigned MaxBytesToEmit = 0) override;
233 void emitCodeAlignment(unsigned ByteAlignment,
234 unsigned MaxBytesToEmit = 0) override;
236 void emitValueToOffset(const MCExpr *Offset,
240 void emitFileDirective(StringRef Filename) override;
241 Expected<unsigned> tryEmitDwarfFileDirective(unsigned FileNo,
244 Optional<MD5::MD5Result> Checksum = None,
245 Optional<StringRef> Source = None,
246 unsigned CUID = 0) override;
247 void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
248 Optional<MD5::MD5Result> Checksum,
249 Optional<StringRef> Source,
250 unsigned CUID = 0) override;
251 void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column,
252 unsigned Flags, unsigned Isa,
253 unsigned Discriminator,
254 StringRef FileName) override;
255 MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
257 bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
258 ArrayRef<uint8_t> Checksum,
259 unsigned ChecksumKind) override;
260 bool EmitCVFuncIdDirective(unsigned FuncId) override;
261 bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
262 unsigned IAFile, unsigned IALine,
263 unsigned IACol, SMLoc Loc) override;
264 void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
265 unsigned Column, bool PrologueEnd, bool IsStmt,
266 StringRef FileName, SMLoc Loc) override;
267 void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart,
268 const MCSymbol *FnEnd) override;
269 void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
270 unsigned SourceFileId,
271 unsigned SourceLineNum,
272 const MCSymbol *FnStartSym,
273 const MCSymbol *FnEndSym) override;
275 void PrintCVDefRangePrefix(
276 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges);
278 void emitCVDefRangeDirective(
279 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
280 codeview::DefRangeRegisterRelHeader DRHdr) override;
282 void emitCVDefRangeDirective(
283 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
284 codeview::DefRangeSubfieldRegisterHeader DRHdr) override;
286 void emitCVDefRangeDirective(
287 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
288 codeview::DefRangeRegisterHeader DRHdr) override;
290 void emitCVDefRangeDirective(
291 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
292 codeview::DefRangeFramePointerRelHeader DRHdr) override;
294 void emitCVStringTableDirective() override;
295 void emitCVFileChecksumsDirective() override;
296 void emitCVFileChecksumOffsetDirective(unsigned FileNo) override;
297 void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) override;
299 void emitIdent(StringRef IdentString) override;
300 void emitCFIBKeyFrame() override;
301 void emitCFISections(bool EH, bool Debug) override;
302 void emitCFIDefCfa(int64_t Register, int64_t Offset) override;
303 void emitCFIDefCfaOffset(int64_t Offset) override;
304 void emitCFIDefCfaRegister(int64_t Register) override;
305 void emitCFIOffset(int64_t Register, int64_t Offset) override;
306 void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) override;
307 void emitCFILsda(const MCSymbol *Sym, unsigned Encoding) override;
308 void emitCFIRememberState() override;
309 void emitCFIRestoreState() override;
310 void emitCFIRestore(int64_t Register) override;
311 void emitCFISameValue(int64_t Register) override;
312 void emitCFIRelOffset(int64_t Register, int64_t Offset) override;
313 void emitCFIAdjustCfaOffset(int64_t Adjustment) override;
314 void emitCFIEscape(StringRef Values) override;
315 void emitCFIGnuArgsSize(int64_t Size) override;
316 void emitCFISignalFrame() override;
317 void emitCFIUndefined(int64_t Register) override;
318 void emitCFIRegister(int64_t Register1, int64_t Register2) override;
319 void emitCFIWindowSave() override;
320 void emitCFINegateRAState() override;
321 void emitCFIReturnColumn(int64_t Register) override;
323 void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) override;
324 void EmitWinCFIEndProc(SMLoc Loc) override;
325 void EmitWinCFIFuncletOrFuncEnd(SMLoc Loc) override;
326 void EmitWinCFIStartChained(SMLoc Loc) override;
327 void EmitWinCFIEndChained(SMLoc Loc) override;
328 void EmitWinCFIPushReg(MCRegister Register, SMLoc Loc) override;
329 void EmitWinCFISetFrame(MCRegister Register, unsigned Offset,
331 void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) override;
332 void EmitWinCFISaveReg(MCRegister Register, unsigned Offset,
334 void EmitWinCFISaveXMM(MCRegister Register, unsigned Offset,
336 void EmitWinCFIPushFrame(bool Code, SMLoc Loc) override;
337 void EmitWinCFIEndProlog(SMLoc Loc) override;
339 void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
341 void EmitWinEHHandlerData(SMLoc Loc) override;
343 void emitCGProfileEntry(const MCSymbolRefExpr *From,
344 const MCSymbolRefExpr *To, uint64_t Count) override;
346 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
348 void emitBundleAlignMode(unsigned AlignPow2) override;
349 void emitBundleLock(bool AlignToEnd) override;
350 void emitBundleUnlock() override;
352 Optional<std::pair<bool, std::string>>
353 emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
354 SMLoc Loc, const MCSubtargetInfo &STI) override;
356 void emitAddrsig() override;
357 void emitAddrsigSym(const MCSymbol *Sym) override;
359 /// If this file is backed by an assembly streamer, this dumps the specified
360 /// string in the output .s file. This capability is indicated by the
361 /// hasRawTextSupport() predicate.
362 void emitRawTextImpl(StringRef String) override;
364 void finishImpl() override;
367 } // end anonymous namespace.
369 void MCAsmStreamer::AddComment(const Twine &T, bool EOL) {
370 if (!IsVerboseAsm) return;
372 T.toVector(CommentToEmit);
375 CommentToEmit.push_back('\n'); // Place comment in a new line.
378 void MCAsmStreamer::EmitCommentsAndEOL() {
379 if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
384 StringRef Comments = CommentToEmit;
386 assert(Comments.back() == '\n' &&
387 "Comment array not newline terminated");
389 // Emit a line of comments.
390 OS.PadToColumn(MAI->getCommentColumn());
391 size_t Position = Comments.find('\n');
392 OS << MAI->getCommentString() << ' ' << Comments.substr(0, Position) <<'\n';
394 Comments = Comments.substr(Position+1);
395 } while (!Comments.empty());
397 CommentToEmit.clear();
400 static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
401 assert(Bytes > 0 && Bytes <= 8 && "Invalid size!");
402 return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
405 void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) {
408 OS << MAI->getCommentString() << T;
412 void MCAsmStreamer::addExplicitComment(const Twine &T) {
413 StringRef c = T.getSingleStringRef();
414 if (c.equals(StringRef(MAI->getSeparatorString())))
416 if (c.startswith(StringRef("//"))) {
417 ExplicitCommentToEmit.append("\t");
418 ExplicitCommentToEmit.append(MAI->getCommentString());
420 ExplicitCommentToEmit.append(c.slice(2, c.size()).str());
421 } else if (c.startswith(StringRef("/*"))) {
422 size_t p = 2, len = c.size() - 2;
423 // emit each line in comment as separate newline.
425 size_t newp = std::min(len, c.find_first_of("\r\n", p));
426 ExplicitCommentToEmit.append("\t");
427 ExplicitCommentToEmit.append(MAI->getCommentString());
428 ExplicitCommentToEmit.append(c.slice(p, newp).str());
429 // If we have another line in this comment add line
431 ExplicitCommentToEmit.append("\n");
434 } else if (c.startswith(StringRef(MAI->getCommentString()))) {
435 ExplicitCommentToEmit.append("\t");
436 ExplicitCommentToEmit.append(c.str());
437 } else if (c.front() == '#') {
439 ExplicitCommentToEmit.append("\t");
440 ExplicitCommentToEmit.append(MAI->getCommentString());
441 ExplicitCommentToEmit.append(c.slice(1, c.size()).str());
443 assert(false && "Unexpected Assembly Comment");
444 // full line comments immediately output
445 if (c.back() == '\n')
446 emitExplicitComments();
449 void MCAsmStreamer::emitExplicitComments() {
450 StringRef Comments = ExplicitCommentToEmit;
451 if (!Comments.empty())
453 ExplicitCommentToEmit.clear();
456 void MCAsmStreamer::changeSection(MCSection *Section,
457 const MCExpr *Subsection) {
458 assert(Section && "Cannot switch to a null section!");
459 if (MCTargetStreamer *TS = getTargetStreamer()) {
460 TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);
462 Section->PrintSwitchToSection(
463 *MAI, getContext().getObjectFileInfo()->getTargetTriple(), OS,
468 void MCAsmStreamer::emitELFSymverDirective(StringRef AliasName,
469 const MCSymbol *Aliasee) {
471 Aliasee->print(OS, MAI);
472 OS << ", " << AliasName;
476 void MCAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
477 MCStreamer::emitLabel(Symbol, Loc);
479 Symbol->print(OS, MAI);
480 OS << MAI->getLabelSuffix();
485 void MCAsmStreamer::emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {
486 StringRef str = MCLOHIdToName(Kind);
489 int NbArgs = MCLOHIdToNbArgs(Kind);
490 assert(NbArgs != -1 && ((size_t)NbArgs) == Args.size() && "Malformed LOH!");
491 assert(str != "" && "Invalid LOH name");
494 OS << "\t" << MCLOHDirectiveName() << " " << str << "\t";
496 for (const MCSymbol *Arg : Args) {
505 void MCAsmStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
507 case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
508 case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
509 case MCAF_Code16: OS << '\t'<< MAI->getCode16Directive();break;
510 case MCAF_Code32: OS << '\t'<< MAI->getCode32Directive();break;
511 case MCAF_Code64: OS << '\t'<< MAI->getCode64Directive();break;
516 void MCAsmStreamer::emitLinkerOptions(ArrayRef<std::string> Options) {
517 assert(!Options.empty() && "At least one option is required!");
518 OS << "\t.linker_option \"" << Options[0] << '"';
519 for (ArrayRef<std::string>::iterator it = Options.begin() + 1,
520 ie = Options.end(); it != ie; ++it) {
521 OS << ", " << '"' << *it << '"';
526 void MCAsmStreamer::emitDataRegion(MCDataRegionType Kind) {
527 if (!MAI->doesSupportDataRegionDirectives())
530 case MCDR_DataRegion: OS << "\t.data_region"; break;
531 case MCDR_DataRegionJT8: OS << "\t.data_region jt8"; break;
532 case MCDR_DataRegionJT16: OS << "\t.data_region jt16"; break;
533 case MCDR_DataRegionJT32: OS << "\t.data_region jt32"; break;
534 case MCDR_DataRegionEnd: OS << "\t.end_data_region"; break;
539 static const char *getVersionMinDirective(MCVersionMinType Type) {
541 case MCVM_WatchOSVersionMin: return ".watchos_version_min";
542 case MCVM_TvOSVersionMin: return ".tvos_version_min";
543 case MCVM_IOSVersionMin: return ".ios_version_min";
544 case MCVM_OSXVersionMin: return ".macosx_version_min";
546 llvm_unreachable("Invalid MC version min type");
549 static void EmitSDKVersionSuffix(raw_ostream &OS,
550 const VersionTuple &SDKVersion) {
551 if (SDKVersion.empty())
553 OS << '\t' << "sdk_version " << SDKVersion.getMajor();
554 if (auto Minor = SDKVersion.getMinor()) {
555 OS << ", " << *Minor;
556 if (auto Subminor = SDKVersion.getSubminor()) {
557 OS << ", " << *Subminor;
562 void MCAsmStreamer::emitVersionMin(MCVersionMinType Type, unsigned Major,
563 unsigned Minor, unsigned Update,
564 VersionTuple SDKVersion) {
565 OS << '\t' << getVersionMinDirective(Type) << ' ' << Major << ", " << Minor;
567 OS << ", " << Update;
568 EmitSDKVersionSuffix(OS, SDKVersion);
572 static const char *getPlatformName(MachO::PlatformType Type) {
574 case MachO::PLATFORM_MACOS: return "macos";
575 case MachO::PLATFORM_IOS: return "ios";
576 case MachO::PLATFORM_TVOS: return "tvos";
577 case MachO::PLATFORM_WATCHOS: return "watchos";
578 case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
579 case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
580 case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
581 case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
582 case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
584 llvm_unreachable("Invalid Mach-O platform type");
587 void MCAsmStreamer::emitBuildVersion(unsigned Platform, unsigned Major,
588 unsigned Minor, unsigned Update,
589 VersionTuple SDKVersion) {
590 const char *PlatformName = getPlatformName((MachO::PlatformType)Platform);
591 OS << "\t.build_version " << PlatformName << ", " << Major << ", " << Minor;
593 OS << ", " << Update;
594 EmitSDKVersionSuffix(OS, SDKVersion);
598 void MCAsmStreamer::emitThumbFunc(MCSymbol *Func) {
599 // This needs to emit to a temporary string to get properly quoted
600 // MCSymbols when they have spaces in them.
601 OS << "\t.thumb_func";
602 // Only Mach-O hasSubsectionsViaSymbols()
603 if (MAI->hasSubsectionsViaSymbols()) {
605 Func->print(OS, MAI);
610 void MCAsmStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
611 // Do not emit a .set on inlined target assignments.
613 if (auto *E = dyn_cast<MCTargetExpr>(Value))
614 if (E->inlineAssignedExpr())
618 Symbol->print(OS, MAI);
620 Value->print(OS, MAI);
625 MCStreamer::emitAssignment(Symbol, Value);
628 void MCAsmStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
630 Alias->print(OS, MAI);
632 Symbol->print(OS, MAI);
636 bool MCAsmStreamer::emitSymbolAttribute(MCSymbol *Symbol,
637 MCSymbolAttr Attribute) {
639 case MCSA_Invalid: llvm_unreachable("Invalid symbol attribute");
640 case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function
641 case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
642 case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object
643 case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object
644 case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
645 case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
646 case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
647 if (!MAI->hasDotTypeDotSizeDirective())
648 return false; // Symbol attribute not supported
650 Symbol->print(OS, MAI);
651 OS << ',' << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
653 default: return false;
654 case MCSA_ELF_TypeFunction: OS << "function"; break;
655 case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
656 case MCSA_ELF_TypeObject: OS << "object"; break;
657 case MCSA_ELF_TypeTLS: OS << "tls_object"; break;
658 case MCSA_ELF_TypeCommon: OS << "common"; break;
659 case MCSA_ELF_TypeNoType: OS << "notype"; break;
660 case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
664 case MCSA_Global: // .globl/.global
665 OS << MAI->getGlobalDirective();
667 case MCSA_LGlobal: OS << "\t.lglobl\t"; break;
668 case MCSA_Hidden: OS << "\t.hidden\t"; break;
669 case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
670 case MCSA_Internal: OS << "\t.internal\t"; break;
671 case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break;
672 case MCSA_Local: OS << "\t.local\t"; break;
673 case MCSA_NoDeadStrip:
674 if (!MAI->hasNoDeadStrip())
676 OS << "\t.no_dead_strip\t";
678 case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break;
679 case MCSA_AltEntry: OS << "\t.alt_entry\t"; break;
680 case MCSA_PrivateExtern:
681 OS << "\t.private_extern\t";
683 case MCSA_Protected: OS << "\t.protected\t"; break;
684 case MCSA_Reference: OS << "\t.reference\t"; break;
688 case MCSA_Weak: OS << MAI->getWeakDirective(); break;
689 case MCSA_WeakDefinition:
690 OS << "\t.weak_definition\t";
693 case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break;
694 case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
696 // Assemblers currently do not support a .cold directive.
700 Symbol->print(OS, MAI);
706 void MCAsmStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
707 OS << ".desc" << ' ';
708 Symbol->print(OS, MAI);
709 OS << ',' << DescValue;
713 void MCAsmStreamer::emitSyntaxDirective() {
714 if (MAI->getAssemblerDialect() == 1) {
715 OS << "\t.intel_syntax noprefix";
718 // FIXME: Currently emit unprefix'ed registers.
719 // The intel_syntax directive has one optional argument
720 // with may have a value of prefix or noprefix.
723 void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
725 Symbol->print(OS, MAI);
730 void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
731 OS << "\t.scl\t" << StorageClass << ';';
735 void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
736 OS << "\t.type\t" << Type << ';';
740 void MCAsmStreamer::EndCOFFSymbolDef() {
745 void MCAsmStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
746 OS << "\t.safeseh\t";
747 Symbol->print(OS, MAI);
751 void MCAsmStreamer::EmitCOFFSymbolIndex(MCSymbol const *Symbol) {
753 Symbol->print(OS, MAI);
757 void MCAsmStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
759 Symbol->print(OS, MAI);
763 void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) {
764 OS << "\t.secrel32\t";
765 Symbol->print(OS, MAI);
771 void MCAsmStreamer::EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) {
773 Symbol->print(OS, MAI);
777 OS << '-' << -Offset;
781 // We need an XCOFF-specific version of this directive as the AIX syntax
782 // requires a QualName argument identifying the csect name and storage mapping
783 // class to appear before the alignment if we are specifying it.
784 void MCAsmStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym,
787 unsigned ByteAlignment) {
788 assert(MAI->getLCOMMDirectiveAlignmentType() == LCOMM::Log2Alignment &&
789 "We only support writing log base-2 alignment format with XCOFF.");
790 assert(isPowerOf2_32(ByteAlignment) && "Alignment must be a power of 2.");
793 LabelSym->print(OS, MAI);
794 OS << ',' << Size << ',';
795 CsectSym->print(OS, MAI);
796 OS << ',' << Log2_32(ByteAlignment);
801 void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility(
802 MCSymbol *Symbol, MCSymbolAttr Linkage, MCSymbolAttr Visibility) {
803 // Print symbol's rename (original name contains invalid character(s)) if
805 if (cast<MCSymbolXCOFF>(Symbol)->hasRename())
806 emitXCOFFRenameDirective(Symbol,
807 cast<MCSymbolXCOFF>(Symbol)->getSymbolTableName());
811 OS << MAI->getGlobalDirective();
814 OS << MAI->getWeakDirective();
823 report_fatal_error("unhandled linkage type");
826 Symbol->print(OS, MAI);
828 switch (Visibility) {
839 report_fatal_error("unexpected value for Visibility type");
844 void MCAsmStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,
847 Name->print(OS, MAI);
850 for (char C : Rename) {
851 // To escape a double quote character, the character should be doubled.
860 void MCAsmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
861 assert(MAI->hasDotTypeDotSizeDirective());
863 Symbol->print(OS, MAI);
865 Value->print(OS, MAI);
869 void MCAsmStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
870 unsigned ByteAlignment) {
871 // Print symbol's rename (original name contains invalid character(s)) if
873 MCSymbolXCOFF *XSym = dyn_cast<MCSymbolXCOFF>(Symbol);
874 if (XSym && XSym->hasRename())
875 emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName());
878 Symbol->print(OS, MAI);
881 if (ByteAlignment != 0) {
882 if (MAI->getCOMMDirectiveAlignmentIsInBytes())
883 OS << ',' << ByteAlignment;
885 OS << ',' << Log2_32(ByteAlignment);
890 void MCAsmStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
891 unsigned ByteAlign) {
893 Symbol->print(OS, MAI);
897 switch (MAI->getLCOMMDirectiveAlignmentType()) {
898 case LCOMM::NoAlignment:
899 llvm_unreachable("alignment not supported on .lcomm!");
900 case LCOMM::ByteAlignment:
901 OS << ',' << ByteAlign;
903 case LCOMM::Log2Alignment:
904 assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2");
905 OS << ',' << Log2_32(ByteAlign);
912 void MCAsmStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
913 uint64_t Size, unsigned ByteAlignment,
916 AssignFragment(Symbol, &Section->getDummyFragment());
918 // Note: a .zerofill directive does not switch sections.
921 assert(Section->getVariant() == MCSection::SV_MachO &&
922 ".zerofill is a Mach-O specific directive");
923 // This is a mach-o specific directive.
925 const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
926 OS << MOSection->getSegmentName() << "," << MOSection->getName();
930 Symbol->print(OS, MAI);
932 if (ByteAlignment != 0)
933 OS << ',' << Log2_32(ByteAlignment);
938 // .tbss sym, size, align
939 // This depends that the symbol has already been mangled from the original,
941 void MCAsmStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
942 uint64_t Size, unsigned ByteAlignment) {
943 AssignFragment(Symbol, &Section->getDummyFragment());
945 assert(Symbol && "Symbol shouldn't be NULL!");
946 // Instead of using the Section we'll just use the shortcut.
948 assert(Section->getVariant() == MCSection::SV_MachO &&
949 ".zerofill is a Mach-O specific directive");
950 // This is a mach-o specific directive and section.
953 Symbol->print(OS, MAI);
956 // Output align if we have it. We default to 1 so don't bother printing
958 if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
963 static inline char toOctal(int X) { return (X&7)+'0'; }
965 static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
968 for (unsigned i = 0, e = Data.size(); i != e; ++i) {
969 unsigned char C = Data[i];
970 if (C == '"' || C == '\\') {
971 OS << '\\' << (char)C;
975 if (isPrint((unsigned char)C)) {
981 case '\b': OS << "\\b"; break;
982 case '\f': OS << "\\f"; break;
983 case '\n': OS << "\\n"; break;
984 case '\r': OS << "\\r"; break;
985 case '\t': OS << "\\t"; break;
988 OS << toOctal(C >> 6);
989 OS << toOctal(C >> 3);
990 OS << toOctal(C >> 0);
998 void MCAsmStreamer::emitBytes(StringRef Data) {
999 assert(getCurrentSectionOnly() &&
1000 "Cannot emit contents before setting section!");
1001 if (Data.empty()) return;
1003 // If only single byte is provided or no ascii or asciz directives is
1004 // supported, emit as vector of 8bits data.
1005 if (Data.size() == 1 ||
1006 !(MAI->getAscizDirective() || MAI->getAsciiDirective())) {
1007 if (MCTargetStreamer *TS = getTargetStreamer()) {
1008 TS->emitRawBytes(Data);
1010 const char *Directive = MAI->getData8bitsDirective();
1011 for (const unsigned char C : Data.bytes()) {
1012 OS << Directive << (unsigned)C;
1019 // If the data ends with 0 and the target supports .asciz, use it, otherwise
1021 if (MAI->getAscizDirective() && Data.back() == 0) {
1022 OS << MAI->getAscizDirective();
1023 Data = Data.substr(0, Data.size()-1);
1025 OS << MAI->getAsciiDirective();
1028 PrintQuotedString(Data, OS);
1032 void MCAsmStreamer::emitBinaryData(StringRef Data) {
1033 // This is binary data. Print it in a grid of hex bytes for readability.
1034 const size_t Cols = 4;
1035 for (size_t I = 0, EI = alignTo(Data.size(), Cols); I < EI; I += Cols) {
1036 size_t J = I, EJ = std::min(I + Cols, Data.size());
1038 OS << MAI->getData8bitsDirective();
1039 for (; J < EJ - 1; ++J)
1040 OS << format("0x%02x", uint8_t(Data[J])) << ", ";
1041 OS << format("0x%02x", uint8_t(Data[J]));
1046 void MCAsmStreamer::emitIntValue(uint64_t Value, unsigned Size) {
1047 emitValue(MCConstantExpr::create(Value, getContext()), Size);
1050 void MCAsmStreamer::emitIntValueInHex(uint64_t Value, unsigned Size) {
1051 emitValue(MCConstantExpr::create(Value, getContext(), true), Size);
1054 void MCAsmStreamer::emitIntValueInHexWithPadding(uint64_t Value,
1056 emitValue(MCConstantExpr::create(Value, getContext(), true, Size), Size);
1059 void MCAsmStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
1061 assert(Size <= 8 && "Invalid size");
1062 assert(getCurrentSectionOnly() &&
1063 "Cannot emit contents before setting section!");
1064 const char *Directive = nullptr;
1067 case 1: Directive = MAI->getData8bitsDirective(); break;
1068 case 2: Directive = MAI->getData16bitsDirective(); break;
1069 case 4: Directive = MAI->getData32bitsDirective(); break;
1070 case 8: Directive = MAI->getData64bitsDirective(); break;
1075 if (!Value->evaluateAsAbsolute(IntValue))
1076 report_fatal_error("Don't know how to emit this value.");
1078 // We couldn't handle the requested integer size so we fallback by breaking
1079 // the request down into several, smaller, integers.
1080 // Since sizes greater or equal to "Size" are invalid, we use the greatest
1081 // power of 2 that is less than "Size" as our largest piece of granularity.
1082 bool IsLittleEndian = MAI->isLittleEndian();
1083 for (unsigned Emitted = 0; Emitted != Size;) {
1084 unsigned Remaining = Size - Emitted;
1085 // The size of our partial emission must be a power of two less than
1087 unsigned EmissionSize = PowerOf2Floor(std::min(Remaining, Size - 1));
1088 // Calculate the byte offset of our partial emission taking into account
1089 // the endianness of the target.
1090 unsigned ByteOffset =
1091 IsLittleEndian ? Emitted : (Remaining - EmissionSize);
1092 uint64_t ValueToEmit = IntValue >> (ByteOffset * 8);
1093 // We truncate our partial emission to fit within the bounds of the
1094 // emission domain. This produces nicer output and silences potential
1095 // truncation warnings when round tripping through another assembler.
1096 uint64_t Shift = 64 - EmissionSize * 8;
1097 assert(Shift < static_cast<uint64_t>(
1098 std::numeric_limits<unsigned long long>::digits) &&
1099 "undefined behavior");
1100 ValueToEmit &= ~0ULL >> Shift;
1101 emitIntValue(ValueToEmit, EmissionSize);
1102 Emitted += EmissionSize;
1107 assert(Directive && "Invalid size for machine code value!");
1109 if (MCTargetStreamer *TS = getTargetStreamer()) {
1110 TS->emitValue(Value);
1112 Value->print(OS, MAI);
1117 void MCAsmStreamer::emitULEB128Value(const MCExpr *Value) {
1119 if (Value->evaluateAsAbsolute(IntValue)) {
1120 emitULEB128IntValue(IntValue);
1123 OS << "\t.uleb128 ";
1124 Value->print(OS, MAI);
1128 void MCAsmStreamer::emitSLEB128Value(const MCExpr *Value) {
1130 if (Value->evaluateAsAbsolute(IntValue)) {
1131 emitSLEB128IntValue(IntValue);
1134 OS << "\t.sleb128 ";
1135 Value->print(OS, MAI);
1139 void MCAsmStreamer::emitDTPRel64Value(const MCExpr *Value) {
1140 assert(MAI->getDTPRel64Directive() != nullptr);
1141 OS << MAI->getDTPRel64Directive();
1142 Value->print(OS, MAI);
1146 void MCAsmStreamer::emitDTPRel32Value(const MCExpr *Value) {
1147 assert(MAI->getDTPRel32Directive() != nullptr);
1148 OS << MAI->getDTPRel32Directive();
1149 Value->print(OS, MAI);
1153 void MCAsmStreamer::emitTPRel64Value(const MCExpr *Value) {
1154 assert(MAI->getTPRel64Directive() != nullptr);
1155 OS << MAI->getTPRel64Directive();
1156 Value->print(OS, MAI);
1160 void MCAsmStreamer::emitTPRel32Value(const MCExpr *Value) {
1161 assert(MAI->getTPRel32Directive() != nullptr);
1162 OS << MAI->getTPRel32Directive();
1163 Value->print(OS, MAI);
1167 void MCAsmStreamer::emitGPRel64Value(const MCExpr *Value) {
1168 assert(MAI->getGPRel64Directive() != nullptr);
1169 OS << MAI->getGPRel64Directive();
1170 Value->print(OS, MAI);
1174 void MCAsmStreamer::emitGPRel32Value(const MCExpr *Value) {
1175 assert(MAI->getGPRel32Directive() != nullptr);
1176 OS << MAI->getGPRel32Directive();
1177 Value->print(OS, MAI);
1181 void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
1183 int64_t IntNumBytes;
1184 const bool IsAbsolute = NumBytes.evaluateAsAbsolute(IntNumBytes);
1185 if (IsAbsolute && IntNumBytes == 0)
1188 if (const char *ZeroDirective = MAI->getZeroDirective()) {
1189 if (MAI->doesZeroDirectiveSupportNonZeroValue() || FillValue == 0) {
1190 // FIXME: Emit location directives
1191 OS << ZeroDirective;
1192 NumBytes.print(OS, MAI);
1194 OS << ',' << (int)FillValue;
1199 "Cannot emit non-absolute expression lengths of fill.");
1200 for (int i = 0; i < IntNumBytes; ++i) {
1201 OS << MAI->getData8bitsDirective() << (int)FillValue;
1208 MCStreamer::emitFill(NumBytes, FillValue);
1211 void MCAsmStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
1212 int64_t Expr, SMLoc Loc) {
1213 // FIXME: Emit location directives
1215 NumValues.print(OS, MAI);
1216 OS << ", " << Size << ", 0x";
1217 OS.write_hex(truncateToSize(Expr, 4));
1221 void MCAsmStreamer::emitValueToAlignment(unsigned ByteAlignment, int64_t Value,
1223 unsigned MaxBytesToEmit) {
1224 if (MAI->useDotAlignForAlignment()) {
1225 if (!isPowerOf2_32(ByteAlignment))
1226 report_fatal_error("Only power-of-two alignments are supported "
1229 OS << Log2_32(ByteAlignment);
1234 // Some assemblers don't support non-power of two alignments, so we always
1235 // emit alignments as a power of two if possible.
1236 if (isPowerOf2_32(ByteAlignment)) {
1237 switch (ValueSize) {
1239 llvm_unreachable("Invalid size for machine code value!");
1241 OS << "\t.p2align\t";
1250 llvm_unreachable("Unsupported alignment size!");
1253 OS << Log2_32(ByteAlignment);
1255 if (Value || MaxBytesToEmit) {
1257 OS.write_hex(truncateToSize(Value, ValueSize));
1260 OS << ", " << MaxBytesToEmit;
1266 // Non-power of two alignment. This is not widely supported by assemblers.
1267 // FIXME: Parameterize this based on MAI.
1268 switch (ValueSize) {
1269 default: llvm_unreachable("Invalid size for machine code value!");
1270 case 1: OS << ".balign"; break;
1271 case 2: OS << ".balignw"; break;
1272 case 4: OS << ".balignl"; break;
1273 case 8: llvm_unreachable("Unsupported alignment size!");
1276 OS << ' ' << ByteAlignment;
1277 OS << ", " << truncateToSize(Value, ValueSize);
1279 OS << ", " << MaxBytesToEmit;
1283 void MCAsmStreamer::emitCodeAlignment(unsigned ByteAlignment,
1284 unsigned MaxBytesToEmit) {
1285 // Emit with a text fill value.
1286 emitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(),
1290 void MCAsmStreamer::emitValueToOffset(const MCExpr *Offset,
1291 unsigned char Value,
1293 // FIXME: Verify that Offset is associated with the current section.
1295 Offset->print(OS, MAI);
1296 OS << ", " << (unsigned)Value;
1300 void MCAsmStreamer::emitFileDirective(StringRef Filename) {
1301 assert(MAI->hasSingleParameterDotFile());
1303 PrintQuotedString(Filename, OS);
1307 static void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
1309 Optional<MD5::MD5Result> Checksum,
1310 Optional<StringRef> Source,
1311 bool UseDwarfDirectory,
1312 raw_svector_ostream &OS) {
1313 SmallString<128> FullPathName;
1315 if (!UseDwarfDirectory && !Directory.empty()) {
1316 if (sys::path::is_absolute(Filename))
1319 FullPathName = Directory;
1320 sys::path::append(FullPathName, Filename);
1322 Filename = FullPathName;
1326 OS << "\t.file\t" << FileNo << ' ';
1327 if (!Directory.empty()) {
1328 PrintQuotedString(Directory, OS);
1331 PrintQuotedString(Filename, OS);
1333 OS << " md5 0x" << Checksum->digest();
1336 PrintQuotedString(*Source, OS);
1340 Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
1341 unsigned FileNo, StringRef Directory, StringRef Filename,
1342 Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source, unsigned CUID) {
1343 assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer");
1345 MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
1346 unsigned NumFiles = Table.getMCDwarfFiles().size();
1347 Expected<unsigned> FileNoOrErr =
1348 Table.tryGetFile(Directory, Filename, Checksum, Source,
1349 getContext().getDwarfVersion(), FileNo);
1351 return FileNoOrErr.takeError();
1352 FileNo = FileNoOrErr.get();
1353 if (NumFiles == Table.getMCDwarfFiles().size())
1356 SmallString<128> Str;
1357 raw_svector_ostream OS1(Str);
1358 printDwarfFileDirective(FileNo, Directory, Filename, Checksum, Source,
1359 UseDwarfDirectory, OS1);
1361 if (MCTargetStreamer *TS = getTargetStreamer())
1362 TS->emitDwarfFileDirective(OS1.str());
1364 emitRawText(OS1.str());
1369 void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory,
1371 Optional<MD5::MD5Result> Checksum,
1372 Optional<StringRef> Source,
1375 // .file 0 is new for DWARF v5.
1376 if (getContext().getDwarfVersion() < 5)
1378 // Inform MCDwarf about the root file.
1379 getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
1382 SmallString<128> Str;
1383 raw_svector_ostream OS1(Str);
1384 printDwarfFileDirective(0, Directory, Filename, Checksum, Source,
1385 UseDwarfDirectory, OS1);
1387 if (MCTargetStreamer *TS = getTargetStreamer())
1388 TS->emitDwarfFileDirective(OS1.str());
1390 emitRawText(OS1.str());
1393 void MCAsmStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
1394 unsigned Column, unsigned Flags,
1395 unsigned Isa, unsigned Discriminator,
1396 StringRef FileName) {
1397 OS << "\t.loc\t" << FileNo << " " << Line << " " << Column;
1398 if (MAI->supportsExtendedDwarfLocDirective()) {
1399 if (Flags & DWARF2_FLAG_BASIC_BLOCK)
1400 OS << " basic_block";
1401 if (Flags & DWARF2_FLAG_PROLOGUE_END)
1402 OS << " prologue_end";
1403 if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
1404 OS << " epilogue_begin";
1406 unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags();
1407 if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
1410 if (Flags & DWARF2_FLAG_IS_STMT)
1417 OS << " isa " << Isa;
1419 OS << " discriminator " << Discriminator;
1423 OS.PadToColumn(MAI->getCommentColumn());
1424 OS << MAI->getCommentString() << ' ' << FileName << ':'
1425 << Line << ':' << Column;
1428 this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
1429 Discriminator, FileName);
1432 MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(unsigned CUID) {
1433 // Always use the zeroth line table, since asm syntax only supports one line
1435 return MCStreamer::getDwarfLineTableSymbol(0);
1438 bool MCAsmStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename,
1439 ArrayRef<uint8_t> Checksum,
1440 unsigned ChecksumKind) {
1441 if (!getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum,
1445 OS << "\t.cv_file\t" << FileNo << ' ';
1446 PrintQuotedString(Filename, OS);
1448 if (!ChecksumKind) {
1454 PrintQuotedString(toHex(Checksum), OS);
1455 OS << ' ' << ChecksumKind;
1461 bool MCAsmStreamer::EmitCVFuncIdDirective(unsigned FuncId) {
1462 OS << "\t.cv_func_id " << FuncId << '\n';
1463 return MCStreamer::EmitCVFuncIdDirective(FuncId);
1466 bool MCAsmStreamer::EmitCVInlineSiteIdDirective(unsigned FunctionId,
1469 unsigned IALine, unsigned IACol,
1471 OS << "\t.cv_inline_site_id " << FunctionId << " within " << IAFunc
1472 << " inlined_at " << IAFile << ' ' << IALine << ' ' << IACol << '\n';
1473 return MCStreamer::EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
1474 IALine, IACol, Loc);
1477 void MCAsmStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
1478 unsigned Line, unsigned Column,
1479 bool PrologueEnd, bool IsStmt,
1480 StringRef FileName, SMLoc Loc) {
1481 // Validate the directive.
1482 if (!checkCVLocSection(FunctionId, FileNo, Loc))
1485 OS << "\t.cv_loc\t" << FunctionId << " " << FileNo << " " << Line << " "
1488 OS << " prologue_end";
1494 OS.PadToColumn(MAI->getCommentColumn());
1495 OS << MAI->getCommentString() << ' ' << FileName << ':' << Line << ':'
1501 void MCAsmStreamer::emitCVLinetableDirective(unsigned FunctionId,
1502 const MCSymbol *FnStart,
1503 const MCSymbol *FnEnd) {
1504 OS << "\t.cv_linetable\t" << FunctionId << ", ";
1505 FnStart->print(OS, MAI);
1507 FnEnd->print(OS, MAI);
1509 this->MCStreamer::emitCVLinetableDirective(FunctionId, FnStart, FnEnd);
1512 void MCAsmStreamer::emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
1513 unsigned SourceFileId,
1514 unsigned SourceLineNum,
1515 const MCSymbol *FnStartSym,
1516 const MCSymbol *FnEndSym) {
1517 OS << "\t.cv_inline_linetable\t" << PrimaryFunctionId << ' ' << SourceFileId
1518 << ' ' << SourceLineNum << ' ';
1519 FnStartSym->print(OS, MAI);
1521 FnEndSym->print(OS, MAI);
1523 this->MCStreamer::emitCVInlineLinetableDirective(
1524 PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
1527 void MCAsmStreamer::PrintCVDefRangePrefix(
1528 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges) {
1529 OS << "\t.cv_def_range\t";
1530 for (std::pair<const MCSymbol *, const MCSymbol *> Range : Ranges) {
1532 Range.first->print(OS, MAI);
1534 Range.second->print(OS, MAI);
1538 void MCAsmStreamer::emitCVDefRangeDirective(
1539 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1540 codeview::DefRangeRegisterRelHeader DRHdr) {
1541 PrintCVDefRangePrefix(Ranges);
1542 OS << ", reg_rel, ";
1543 OS << DRHdr.Register << ", " << DRHdr.Flags << ", "
1544 << DRHdr.BasePointerOffset;
1548 void MCAsmStreamer::emitCVDefRangeDirective(
1549 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1550 codeview::DefRangeSubfieldRegisterHeader DRHdr) {
1551 PrintCVDefRangePrefix(Ranges);
1552 OS << ", subfield_reg, ";
1553 OS << DRHdr.Register << ", " << DRHdr.OffsetInParent;
1557 void MCAsmStreamer::emitCVDefRangeDirective(
1558 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1559 codeview::DefRangeRegisterHeader DRHdr) {
1560 PrintCVDefRangePrefix(Ranges);
1562 OS << DRHdr.Register;
1566 void MCAsmStreamer::emitCVDefRangeDirective(
1567 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1568 codeview::DefRangeFramePointerRelHeader DRHdr) {
1569 PrintCVDefRangePrefix(Ranges);
1570 OS << ", frame_ptr_rel, ";
1575 void MCAsmStreamer::emitCVStringTableDirective() {
1576 OS << "\t.cv_stringtable";
1580 void MCAsmStreamer::emitCVFileChecksumsDirective() {
1581 OS << "\t.cv_filechecksums";
1585 void MCAsmStreamer::emitCVFileChecksumOffsetDirective(unsigned FileNo) {
1586 OS << "\t.cv_filechecksumoffset\t" << FileNo;
1590 void MCAsmStreamer::EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) {
1591 OS << "\t.cv_fpo_data\t";
1592 ProcSym->print(OS, MAI);
1596 void MCAsmStreamer::emitIdent(StringRef IdentString) {
1597 assert(MAI->hasIdentDirective() && ".ident directive not supported");
1599 PrintQuotedString(IdentString, OS);
1603 void MCAsmStreamer::emitCFISections(bool EH, bool Debug) {
1604 MCStreamer::emitCFISections(EH, Debug);
1605 OS << "\t.cfi_sections ";
1609 OS << ", .debug_frame";
1611 OS << ".debug_frame";
1617 void MCAsmStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
1618 OS << "\t.cfi_startproc";
1624 void MCAsmStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
1625 MCStreamer::emitCFIEndProcImpl(Frame);
1626 OS << "\t.cfi_endproc";
1630 void MCAsmStreamer::EmitRegisterName(int64_t Register) {
1631 if (!MAI->useDwarfRegNumForCFI()) {
1632 // User .cfi_* directives can use arbitrary DWARF register numbers, not
1633 // just ones that map to LLVM register numbers and have known names.
1634 // Fall back to using the original number directly if no name is known.
1635 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1636 if (Optional<unsigned> LLVMRegister = MRI->getLLVMRegNum(Register, true)) {
1637 InstPrinter->printRegName(OS, *LLVMRegister);
1644 void MCAsmStreamer::emitCFIDefCfa(int64_t Register, int64_t Offset) {
1645 MCStreamer::emitCFIDefCfa(Register, Offset);
1646 OS << "\t.cfi_def_cfa ";
1647 EmitRegisterName(Register);
1648 OS << ", " << Offset;
1652 void MCAsmStreamer::emitCFIDefCfaOffset(int64_t Offset) {
1653 MCStreamer::emitCFIDefCfaOffset(Offset);
1654 OS << "\t.cfi_def_cfa_offset " << Offset;
1658 static void PrintCFIEscape(llvm::formatted_raw_ostream &OS, StringRef Values) {
1659 OS << "\t.cfi_escape ";
1660 if (!Values.empty()) {
1661 size_t e = Values.size() - 1;
1662 for (size_t i = 0; i < e; ++i)
1663 OS << format("0x%02x", uint8_t(Values[i])) << ", ";
1664 OS << format("0x%02x", uint8_t(Values[e]));
1668 void MCAsmStreamer::emitCFIEscape(StringRef Values) {
1669 MCStreamer::emitCFIEscape(Values);
1670 PrintCFIEscape(OS, Values);
1674 void MCAsmStreamer::emitCFIGnuArgsSize(int64_t Size) {
1675 MCStreamer::emitCFIGnuArgsSize(Size);
1677 uint8_t Buffer[16] = { dwarf::DW_CFA_GNU_args_size };
1678 unsigned Len = encodeULEB128(Size, Buffer + 1) + 1;
1680 PrintCFIEscape(OS, StringRef((const char *)&Buffer[0], Len));
1684 void MCAsmStreamer::emitCFIDefCfaRegister(int64_t Register) {
1685 MCStreamer::emitCFIDefCfaRegister(Register);
1686 OS << "\t.cfi_def_cfa_register ";
1687 EmitRegisterName(Register);
1691 void MCAsmStreamer::emitCFIOffset(int64_t Register, int64_t Offset) {
1692 this->MCStreamer::emitCFIOffset(Register, Offset);
1693 OS << "\t.cfi_offset ";
1694 EmitRegisterName(Register);
1695 OS << ", " << Offset;
1699 void MCAsmStreamer::emitCFIPersonality(const MCSymbol *Sym,
1700 unsigned Encoding) {
1701 MCStreamer::emitCFIPersonality(Sym, Encoding);
1702 OS << "\t.cfi_personality " << Encoding << ", ";
1703 Sym->print(OS, MAI);
1707 void MCAsmStreamer::emitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
1708 MCStreamer::emitCFILsda(Sym, Encoding);
1709 OS << "\t.cfi_lsda " << Encoding << ", ";
1710 Sym->print(OS, MAI);
1714 void MCAsmStreamer::emitCFIRememberState() {
1715 MCStreamer::emitCFIRememberState();
1716 OS << "\t.cfi_remember_state";
1720 void MCAsmStreamer::emitCFIRestoreState() {
1721 MCStreamer::emitCFIRestoreState();
1722 OS << "\t.cfi_restore_state";
1726 void MCAsmStreamer::emitCFIRestore(int64_t Register) {
1727 MCStreamer::emitCFIRestore(Register);
1728 OS << "\t.cfi_restore ";
1729 EmitRegisterName(Register);
1733 void MCAsmStreamer::emitCFISameValue(int64_t Register) {
1734 MCStreamer::emitCFISameValue(Register);
1735 OS << "\t.cfi_same_value ";
1736 EmitRegisterName(Register);
1740 void MCAsmStreamer::emitCFIRelOffset(int64_t Register, int64_t Offset) {
1741 MCStreamer::emitCFIRelOffset(Register, Offset);
1742 OS << "\t.cfi_rel_offset ";
1743 EmitRegisterName(Register);
1744 OS << ", " << Offset;
1748 void MCAsmStreamer::emitCFIAdjustCfaOffset(int64_t Adjustment) {
1749 MCStreamer::emitCFIAdjustCfaOffset(Adjustment);
1750 OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
1754 void MCAsmStreamer::emitCFISignalFrame() {
1755 MCStreamer::emitCFISignalFrame();
1756 OS << "\t.cfi_signal_frame";
1760 void MCAsmStreamer::emitCFIUndefined(int64_t Register) {
1761 MCStreamer::emitCFIUndefined(Register);
1762 OS << "\t.cfi_undefined ";
1763 EmitRegisterName(Register);
1767 void MCAsmStreamer::emitCFIRegister(int64_t Register1, int64_t Register2) {
1768 MCStreamer::emitCFIRegister(Register1, Register2);
1769 OS << "\t.cfi_register ";
1770 EmitRegisterName(Register1);
1772 EmitRegisterName(Register2);
1776 void MCAsmStreamer::emitCFIWindowSave() {
1777 MCStreamer::emitCFIWindowSave();
1778 OS << "\t.cfi_window_save";
1782 void MCAsmStreamer::emitCFINegateRAState() {
1783 MCStreamer::emitCFINegateRAState();
1784 OS << "\t.cfi_negate_ra_state";
1788 void MCAsmStreamer::emitCFIReturnColumn(int64_t Register) {
1789 MCStreamer::emitCFIReturnColumn(Register);
1790 OS << "\t.cfi_return_column ";
1791 EmitRegisterName(Register);
1795 void MCAsmStreamer::emitCFIBKeyFrame() {
1796 MCStreamer::emitCFIBKeyFrame();
1797 OS << "\t.cfi_b_key_frame";
1801 void MCAsmStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) {
1802 MCStreamer::EmitWinCFIStartProc(Symbol, Loc);
1805 Symbol->print(OS, MAI);
1809 void MCAsmStreamer::EmitWinCFIEndProc(SMLoc Loc) {
1810 MCStreamer::EmitWinCFIEndProc(Loc);
1812 OS << "\t.seh_endproc";
1817 void MCAsmStreamer::EmitWinCFIFuncletOrFuncEnd(SMLoc Loc) {
1820 void MCAsmStreamer::EmitWinCFIStartChained(SMLoc Loc) {
1821 MCStreamer::EmitWinCFIStartChained(Loc);
1823 OS << "\t.seh_startchained";
1827 void MCAsmStreamer::EmitWinCFIEndChained(SMLoc Loc) {
1828 MCStreamer::EmitWinCFIEndChained(Loc);
1830 OS << "\t.seh_endchained";
1834 void MCAsmStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
1835 bool Except, SMLoc Loc) {
1836 MCStreamer::EmitWinEHHandler(Sym, Unwind, Except, Loc);
1838 OS << "\t.seh_handler ";
1839 Sym->print(OS, MAI);
1847 void MCAsmStreamer::EmitWinEHHandlerData(SMLoc Loc) {
1848 MCStreamer::EmitWinEHHandlerData(Loc);
1850 // Switch sections. Don't call SwitchSection directly, because that will
1851 // cause the section switch to be visible in the emitted assembly.
1852 // We only do this so the section switch that terminates the handler
1853 // data block is visible.
1854 WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
1856 // Do nothing if no frame is open. MCStreamer should've already reported an
1861 MCSection *TextSec = &CurFrame->Function->getSection();
1862 MCSection *XData = getAssociatedXDataSection(TextSec);
1863 SwitchSectionNoChange(XData);
1865 OS << "\t.seh_handlerdata";
1869 void MCAsmStreamer::EmitWinCFIPushReg(MCRegister Register, SMLoc Loc) {
1870 MCStreamer::EmitWinCFIPushReg(Register, Loc);
1872 OS << "\t.seh_pushreg ";
1873 InstPrinter->printRegName(OS, Register);
1877 void MCAsmStreamer::EmitWinCFISetFrame(MCRegister Register, unsigned Offset,
1879 MCStreamer::EmitWinCFISetFrame(Register, Offset, Loc);
1881 OS << "\t.seh_setframe ";
1882 InstPrinter->printRegName(OS, Register);
1883 OS << ", " << Offset;
1887 void MCAsmStreamer::EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) {
1888 MCStreamer::EmitWinCFIAllocStack(Size, Loc);
1890 OS << "\t.seh_stackalloc " << Size;
1894 void MCAsmStreamer::EmitWinCFISaveReg(MCRegister Register, unsigned Offset,
1896 MCStreamer::EmitWinCFISaveReg(Register, Offset, Loc);
1898 OS << "\t.seh_savereg ";
1899 InstPrinter->printRegName(OS, Register);
1900 OS << ", " << Offset;
1904 void MCAsmStreamer::EmitWinCFISaveXMM(MCRegister Register, unsigned Offset,
1906 MCStreamer::EmitWinCFISaveXMM(Register, Offset, Loc);
1908 OS << "\t.seh_savexmm ";
1909 InstPrinter->printRegName(OS, Register);
1910 OS << ", " << Offset;
1914 void MCAsmStreamer::EmitWinCFIPushFrame(bool Code, SMLoc Loc) {
1915 MCStreamer::EmitWinCFIPushFrame(Code, Loc);
1917 OS << "\t.seh_pushframe";
1923 void MCAsmStreamer::EmitWinCFIEndProlog(SMLoc Loc) {
1924 MCStreamer::EmitWinCFIEndProlog(Loc);
1926 OS << "\t.seh_endprologue";
1930 void MCAsmStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
1931 const MCSymbolRefExpr *To,
1933 OS << "\t.cg_profile ";
1934 From->getSymbol().print(OS, MAI);
1936 To->getSymbol().print(OS, MAI);
1937 OS << ", " << Count;
1941 void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
1942 const MCSubtargetInfo &STI) {
1943 raw_ostream &OS = GetCommentOS();
1944 SmallString<256> Code;
1945 SmallVector<MCFixup, 4> Fixups;
1946 raw_svector_ostream VecOS(Code);
1948 // If we have no code emitter, don't emit code.
1949 if (!getAssembler().getEmitterPtr())
1952 getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
1954 // If we are showing fixups, create symbolic markers in the encoded
1955 // representation. We do this by making a per-bit map to the fixup item index,
1956 // then trying to display it as nicely as possible.
1957 SmallVector<uint8_t, 64> FixupMap;
1958 FixupMap.resize(Code.size() * 8);
1959 for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
1962 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1963 MCFixup &F = Fixups[i];
1964 const MCFixupKindInfo &Info =
1965 getAssembler().getBackend().getFixupKindInfo(F.getKind());
1966 for (unsigned j = 0; j != Info.TargetSize; ++j) {
1967 unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
1968 assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
1969 FixupMap[Index] = 1 + i;
1973 // FIXME: Note the fixup comments for Thumb2 are completely bogus since the
1974 // high order halfword of a 32-bit Thumb2 instruction is emitted first.
1975 OS << "encoding: [";
1976 for (unsigned i = 0, e = Code.size(); i != e; ++i) {
1980 // See if all bits are the same map entry.
1981 uint8_t MapEntry = FixupMap[i * 8 + 0];
1982 for (unsigned j = 1; j != 8; ++j) {
1983 if (FixupMap[i * 8 + j] == MapEntry)
1986 MapEntry = uint8_t(~0U);
1990 if (MapEntry != uint8_t(~0U)) {
1991 if (MapEntry == 0) {
1992 OS << format("0x%02x", uint8_t(Code[i]));
1995 // FIXME: Some of the 8 bits require fix up.
1996 OS << format("0x%02x", uint8_t(Code[i])) << '\''
1997 << char('A' + MapEntry - 1) << '\'';
1999 OS << char('A' + MapEntry - 1);
2002 // Otherwise, write out in binary.
2004 for (unsigned j = 8; j--;) {
2005 unsigned Bit = (Code[i] >> j) & 1;
2008 if (MAI->isLittleEndian())
2009 FixupBit = i * 8 + j;
2011 FixupBit = i * 8 + (7-j);
2013 if (uint8_t MapEntry = FixupMap[FixupBit]) {
2014 assert(Bit == 0 && "Encoder wrote into fixed up bit!");
2015 OS << char('A' + MapEntry - 1);
2023 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
2024 MCFixup &F = Fixups[i];
2025 const MCFixupKindInfo &Info =
2026 getAssembler().getBackend().getFixupKindInfo(F.getKind());
2027 OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
2028 << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
2032 void MCAsmStreamer::emitInstruction(const MCInst &Inst,
2033 const MCSubtargetInfo &STI) {
2034 assert(getCurrentSectionOnly() &&
2035 "Cannot emit contents before setting section!");
2037 // Show the encoding in a comment if we have a code emitter.
2038 AddEncodingComment(Inst, STI);
2040 // Show the MCInst if enabled.
2042 Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n ");
2043 GetCommentOS() << "\n";
2046 if(getTargetStreamer())
2047 getTargetStreamer()->prettyPrintAsm(*InstPrinter, 0, Inst, STI, OS);
2049 InstPrinter->printInst(&Inst, 0, "", STI, OS);
2051 StringRef Comments = CommentToEmit;
2052 if (Comments.size() && Comments.back() != '\n')
2053 GetCommentOS() << "\n";
2058 void MCAsmStreamer::emitBundleAlignMode(unsigned AlignPow2) {
2059 OS << "\t.bundle_align_mode " << AlignPow2;
2063 void MCAsmStreamer::emitBundleLock(bool AlignToEnd) {
2064 OS << "\t.bundle_lock";
2066 OS << " align_to_end";
2070 void MCAsmStreamer::emitBundleUnlock() {
2071 OS << "\t.bundle_unlock";
2075 Optional<std::pair<bool, std::string>>
2076 MCAsmStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
2077 const MCExpr *Expr, SMLoc,
2078 const MCSubtargetInfo &STI) {
2080 Offset.print(OS, MAI);
2084 Expr->print(OS, MAI);
2090 void MCAsmStreamer::emitAddrsig() {
2095 void MCAsmStreamer::emitAddrsigSym(const MCSymbol *Sym) {
2096 OS << "\t.addrsig_sym ";
2097 Sym->print(OS, MAI);
2101 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
2102 /// the specified string in the output .s file. This capability is
2103 /// indicated by the hasRawTextSupport() predicate.
2104 void MCAsmStreamer::emitRawTextImpl(StringRef String) {
2105 if (!String.empty() && String.back() == '\n')
2106 String = String.substr(0, String.size()-1);
2111 void MCAsmStreamer::finishImpl() {
2112 // If we are generating dwarf for assembly source files dump out the sections.
2113 if (getContext().getGenDwarfForAssembly())
2114 MCGenDwarfInfo::Emit(this);
2116 // Emit the label for the line table, if requested - since the rest of the
2117 // line table will be defined by .loc/.file directives, and not emitted
2118 // directly, the label is the only work required here.
2119 const auto &Tables = getContext().getMCDwarfLineTables();
2120 if (!Tables.empty()) {
2121 assert(Tables.size() == 1 && "asm output only supports one line table");
2122 if (auto *Label = Tables.begin()->second.getLabel()) {
2123 SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
2129 MCStreamer *llvm::createAsmStreamer(MCContext &Context,
2130 std::unique_ptr<formatted_raw_ostream> OS,
2131 bool isVerboseAsm, bool useDwarfDirectory,
2133 std::unique_ptr<MCCodeEmitter> &&CE,
2134 std::unique_ptr<MCAsmBackend> &&MAB,
2136 return new MCAsmStreamer(Context, std::move(OS), isVerboseAsm,
2137 useDwarfDirectory, IP, std::move(CE), std::move(MAB),