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