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  void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &);
111 
112  /// Return a raw_ostream that comments can be written to.
113  /// Unlike AddComment, you are required to terminate comments with \n if you
114  /// use this method.
115  raw_ostream &GetCommentOS() override {
116  if (!IsVerboseAsm)
117  return nulls(); // Discard comments unless in verbose asm mode.
118  return CommentStream;
119  }
120 
121  void emitRawComment(const Twine &T, bool TabPrefix = true) override;
122 
123  void addExplicitComment(const Twine &T) override;
124  void emitExplicitComments() override;
125 
126  /// Emit a blank line to a .s file to pretty it up.
127  void AddBlankLine() override {
128  EmitEOL();
129  }
130 
131  /// @name MCStreamer Interface
132  /// @{
133 
134  void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
135 
136  void emitELFSymverDirective(StringRef AliasName,
137  const MCSymbol *Aliasee) override;
138 
139  void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
140  void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
141 
142  void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
143  void EmitLinkerOptions(ArrayRef<std::string> Options) override;
144  void EmitDataRegion(MCDataRegionType Kind) override;
145  void EmitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
146  unsigned Update, VersionTuple SDKVersion) override;
147  void EmitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
148  unsigned Update, VersionTuple SDKVersion) override;
149  void EmitThumbFunc(MCSymbol *Func) override;
150 
151  void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
152  void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
153  bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
154 
155  void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
156  void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
157  void EmitCOFFSymbolStorageClass(int StorageClass) override;
158  void EmitCOFFSymbolType(int Type) override;
159  void EndCOFFSymbolDef() override;
160  void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
161  void EmitCOFFSymbolIndex(MCSymbol const *Symbol) override;
162  void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
163  void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override;
164  void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) override;
165  void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
166  void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
167  unsigned ByteAlignment) override;
168 
169  /// Emit a local common (.lcomm) symbol.
170  ///
171  /// @param Symbol - The common symbol to emit.
172  /// @param Size - The size of the common symbol.
173  /// @param ByteAlignment - The alignment of the common symbol in bytes.
174  void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
175  unsigned ByteAlignment) override;
176 
177  void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
178  uint64_t Size = 0, unsigned ByteAlignment = 0,
179  SMLoc Loc = SMLoc()) override;
180 
181  void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
182  unsigned ByteAlignment = 0) override;
183 
184  void EmitBinaryData(StringRef Data) override;
185 
186  void EmitBytes(StringRef Data) override;
187 
188  void EmitValueImpl(const MCExpr *Value, unsigned Size,
189  SMLoc Loc = SMLoc()) override;
190  void EmitIntValue(uint64_t Value, unsigned Size) override;
191 
192  void EmitULEB128Value(const MCExpr *Value) override;
193 
194  void EmitSLEB128Value(const MCExpr *Value) override;
195 
196  void EmitDTPRel32Value(const MCExpr *Value) override;
197  void EmitDTPRel64Value(const MCExpr *Value) override;
198  void EmitTPRel32Value(const MCExpr *Value) override;
199  void EmitTPRel64Value(const MCExpr *Value) override;
200 
201  void EmitGPRel64Value(const MCExpr *Value) override;
202 
203  void EmitGPRel32Value(const MCExpr *Value) override;
204 
205  void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
206  SMLoc Loc = SMLoc()) override;
207 
208  void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
209  SMLoc Loc = SMLoc()) override;
210 
211  void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
212  unsigned ValueSize = 1,
213  unsigned MaxBytesToEmit = 0) override;
214 
215  void EmitCodeAlignment(unsigned ByteAlignment,
216  unsigned MaxBytesToEmit = 0) override;
217 
218  void emitValueToOffset(const MCExpr *Offset,
219  unsigned char Value,
220  SMLoc Loc) override;
221 
222  void EmitFileDirective(StringRef Filename) override;
223  Expected<unsigned> tryEmitDwarfFileDirective(unsigned FileNo,
224  StringRef Directory,
225  StringRef Filename,
226  Optional<MD5::MD5Result> Checksum = None,
228  unsigned CUID = 0) override;
229  void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
230  Optional<MD5::MD5Result> Checksum,
232  unsigned CUID = 0) override;
233  void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
234  unsigned Column, unsigned Flags,
235  unsigned Isa, unsigned Discriminator,
236  StringRef FileName) override;
237  MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
238 
239  bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
240  ArrayRef<uint8_t> Checksum,
241  unsigned ChecksumKind) override;
242  bool EmitCVFuncIdDirective(unsigned FuncId) override;
243  bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
244  unsigned IAFile, unsigned IALine,
245  unsigned IACol, SMLoc Loc) override;
246  void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
247  unsigned Column, bool PrologueEnd, bool IsStmt,
248  StringRef FileName, SMLoc Loc) override;
249  void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart,
250  const MCSymbol *FnEnd) override;
251  void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
252  unsigned SourceFileId,
253  unsigned SourceLineNum,
254  const MCSymbol *FnStartSym,
255  const MCSymbol *FnEndSym) override;
256  void EmitCVDefRangeDirective(
257  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
258  StringRef FixedSizePortion) override;
259  void EmitCVStringTableDirective() override;
260  void EmitCVFileChecksumsDirective() override;
261  void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override;
262  void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) override;
263 
264  void EmitIdent(StringRef IdentString) override;
265  void EmitCFIBKeyFrame() override;
266  void EmitCFISections(bool EH, bool Debug) override;
267  void EmitCFIDefCfa(int64_t Register, int64_t Offset) override;
268  void EmitCFIDefCfaOffset(int64_t Offset) override;
269  void EmitCFIDefCfaRegister(int64_t Register) override;
270  void EmitCFIOffset(int64_t Register, int64_t Offset) override;
271  void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) override;
272  void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) override;
273  void EmitCFIRememberState() override;
274  void EmitCFIRestoreState() override;
275  void EmitCFIRestore(int64_t Register) override;
276  void EmitCFISameValue(int64_t Register) override;
277  void EmitCFIRelOffset(int64_t Register, int64_t Offset) override;
278  void EmitCFIAdjustCfaOffset(int64_t Adjustment) override;
279  void EmitCFIEscape(StringRef Values) override;
280  void EmitCFIGnuArgsSize(int64_t Size) override;
281  void EmitCFISignalFrame() override;
282  void EmitCFIUndefined(int64_t Register) override;
283  void EmitCFIRegister(int64_t Register1, int64_t Register2) override;
284  void EmitCFIWindowSave() override;
285  void EmitCFINegateRAState() override;
286  void EmitCFIReturnColumn(int64_t Register) override;
287 
288  void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) override;
289  void EmitWinCFIEndProc(SMLoc Loc) override;
290  void EmitWinCFIFuncletOrFuncEnd(SMLoc Loc) override;
291  void EmitWinCFIStartChained(SMLoc Loc) override;
292  void EmitWinCFIEndChained(SMLoc Loc) override;
293  void EmitWinCFIPushReg(unsigned Register, SMLoc Loc) override;
294  void EmitWinCFISetFrame(unsigned Register, unsigned Offset,
295  SMLoc Loc) override;
296  void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) override;
297  void EmitWinCFISaveReg(unsigned Register, unsigned Offset,
298  SMLoc Loc) override;
299  void EmitWinCFISaveXMM(unsigned Register, unsigned Offset,
300  SMLoc Loc) override;
301  void EmitWinCFIPushFrame(bool Code, SMLoc Loc) override;
302  void EmitWinCFIEndProlog(SMLoc Loc) override;
303 
304  void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
305  SMLoc Loc) override;
306  void EmitWinEHHandlerData(SMLoc Loc) override;
307 
308  void emitCGProfileEntry(const MCSymbolRefExpr *From,
309  const MCSymbolRefExpr *To, uint64_t Count) override;
310 
311  void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
312 
313  void EmitBundleAlignMode(unsigned AlignPow2) override;
314  void EmitBundleLock(bool AlignToEnd) override;
315  void EmitBundleUnlock() override;
316 
317  bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
318  const MCExpr *Expr, SMLoc Loc,
319  const MCSubtargetInfo &STI) override;
320 
321  void EmitAddrsig() override;
322  void EmitAddrsigSym(const MCSymbol *Sym) override;
323 
324  /// If this file is backed by an assembly streamer, this dumps the specified
325  /// string in the output .s file. This capability is indicated by the
326  /// hasRawTextSupport() predicate.
327  void EmitRawTextImpl(StringRef String) override;
328 
329  void FinishImpl() override;
330 };
331 
332 } // end anonymous namespace.
333 
334 void MCAsmStreamer::AddComment(const Twine &T, bool EOL) {
335  if (!IsVerboseAsm) return;
336 
337  T.toVector(CommentToEmit);
338 
339  if (EOL)
340  CommentToEmit.push_back('\n'); // Place comment in a new line.
341 }
342 
343 void MCAsmStreamer::EmitCommentsAndEOL() {
344  if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
345  OS << '\n';
346  return;
347  }
348 
349  StringRef Comments = CommentToEmit;
350 
351  assert(Comments.back() == '\n' &&
352  "Comment array not newline terminated");
353  do {
354  // Emit a line of comments.
355  OS.PadToColumn(MAI->getCommentColumn());
356  size_t Position = Comments.find('\n');
357  OS << MAI->getCommentString() << ' ' << Comments.substr(0, Position) <<'\n';
358 
359  Comments = Comments.substr(Position+1);
360  } while (!Comments.empty());
361 
362  CommentToEmit.clear();
363 }
364 
365 static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
366  assert(Bytes > 0 && Bytes <= 8 && "Invalid size!");
367  return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
368 }
369 
370 void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) {
371  if (TabPrefix)
372  OS << '\t';
373  OS << MAI->getCommentString() << T;
374  EmitEOL();
375 }
376 
377 void MCAsmStreamer::addExplicitComment(const Twine &T) {
379  if (c.equals(StringRef(MAI->getSeparatorString())))
380  return;
381  if (c.startswith(StringRef("//"))) {
382  ExplicitCommentToEmit.append("\t");
383  ExplicitCommentToEmit.append(MAI->getCommentString());
384  // drop //
385  ExplicitCommentToEmit.append(c.slice(2, c.size()).str());
386  } else if (c.startswith(StringRef("/*"))) {
387  size_t p = 2, len = c.size() - 2;
388  // emit each line in comment as separate newline.
389  do {
390  size_t newp = std::min(len, c.find_first_of("\r\n", p));
391  ExplicitCommentToEmit.append("\t");
392  ExplicitCommentToEmit.append(MAI->getCommentString());
393  ExplicitCommentToEmit.append(c.slice(p, newp).str());
394  // If we have another line in this comment add line
395  if (newp < len)
396  ExplicitCommentToEmit.append("\n");
397  p = newp + 1;
398  } while (p < len);
399  } else if (c.startswith(StringRef(MAI->getCommentString()))) {
400  ExplicitCommentToEmit.append("\t");
401  ExplicitCommentToEmit.append(c.str());
402  } else if (c.front() == '#') {
403 
404  ExplicitCommentToEmit.append("\t");
405  ExplicitCommentToEmit.append(MAI->getCommentString());
406  ExplicitCommentToEmit.append(c.slice(1, c.size()).str());
407  } else
408  assert(false && "Unexpected Assembly Comment");
409  // full line comments immediately output
410  if (c.back() == '\n')
411  emitExplicitComments();
412 }
413 
414 void MCAsmStreamer::emitExplicitComments() {
415  StringRef Comments = ExplicitCommentToEmit;
416  if (!Comments.empty())
417  OS << Comments;
418  ExplicitCommentToEmit.clear();
419 }
420 
421 void MCAsmStreamer::ChangeSection(MCSection *Section,
422  const MCExpr *Subsection) {
423  assert(Section && "Cannot switch to a null section!");
424  if (MCTargetStreamer *TS = getTargetStreamer()) {
425  TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);
426  } else {
427  Section->PrintSwitchToSection(
428  *MAI, getContext().getObjectFileInfo()->getTargetTriple(), OS,
429  Subsection);
430  }
431 }
432 
433 void MCAsmStreamer::emitELFSymverDirective(StringRef AliasName,
434  const MCSymbol *Aliasee) {
435  OS << ".symver ";
436  Aliasee->print(OS, MAI);
437  OS << ", " << AliasName;
438  EmitEOL();
439 }
440 
441 void MCAsmStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
442  MCStreamer::EmitLabel(Symbol, Loc);
443 
444  Symbol->print(OS, MAI);
445  OS << MAI->getLabelSuffix();
446 
447  EmitEOL();
448 }
449 
450 void MCAsmStreamer::EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {
451  StringRef str = MCLOHIdToName(Kind);
452 
453 #ifndef NDEBUG
454  int NbArgs = MCLOHIdToNbArgs(Kind);
455  assert(NbArgs != -1 && ((size_t)NbArgs) == Args.size() && "Malformed LOH!");
456  assert(str != "" && "Invalid LOH name");
457 #endif
458 
459  OS << "\t" << MCLOHDirectiveName() << " " << str << "\t";
460  bool IsFirst = true;
461  for (const MCSymbol *Arg : Args) {
462  if (!IsFirst)
463  OS << ", ";
464  IsFirst = false;
465  Arg->print(OS, MAI);
466  }
467  EmitEOL();
468 }
469 
470 void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
471  switch (Flag) {
472  case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
473  case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
474  case MCAF_Code16: OS << '\t'<< MAI->getCode16Directive();break;
475  case MCAF_Code32: OS << '\t'<< MAI->getCode32Directive();break;
476  case MCAF_Code64: OS << '\t'<< MAI->getCode64Directive();break;
477  }
478  EmitEOL();
479 }
480 
481 void MCAsmStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
482  assert(!Options.empty() && "At least one option is required!");
483  OS << "\t.linker_option \"" << Options[0] << '"';
484  for (ArrayRef<std::string>::iterator it = Options.begin() + 1,
485  ie = Options.end(); it != ie; ++it) {
486  OS << ", " << '"' << *it << '"';
487  }
488  EmitEOL();
489 }
490 
491 void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
493  return;
494  switch (Kind) {
495  case MCDR_DataRegion: OS << "\t.data_region"; break;
496  case MCDR_DataRegionJT8: OS << "\t.data_region jt8"; break;
497  case MCDR_DataRegionJT16: OS << "\t.data_region jt16"; break;
498  case MCDR_DataRegionJT32: OS << "\t.data_region jt32"; break;
499  case MCDR_DataRegionEnd: OS << "\t.end_data_region"; break;
500  }
501  EmitEOL();
502 }
503 
505  switch (Type) {
506  case MCVM_WatchOSVersionMin: return ".watchos_version_min";
507  case MCVM_TvOSVersionMin: return ".tvos_version_min";
508  case MCVM_IOSVersionMin: return ".ios_version_min";
509  case MCVM_OSXVersionMin: return ".macosx_version_min";
510  }
511  llvm_unreachable("Invalid MC version min type");
512 }
513 
515  const VersionTuple &SDKVersion) {
516  if (SDKVersion.empty())
517  return;
518  OS << '\t' << "sdk_version " << SDKVersion.getMajor();
519  if (auto Minor = SDKVersion.getMinor()) {
520  OS << ", " << *Minor;
521  if (auto Subminor = SDKVersion.getSubminor()) {
522  OS << ", " << *Subminor;
523  }
524  }
525 }
526 
527 void MCAsmStreamer::EmitVersionMin(MCVersionMinType Type, unsigned Major,
528  unsigned Minor, unsigned Update,
529  VersionTuple SDKVersion) {
530  OS << '\t' << getVersionMinDirective(Type) << ' ' << Major << ", " << Minor;
531  if (Update)
532  OS << ", " << Update;
533  EmitSDKVersionSuffix(OS, SDKVersion);
534  EmitEOL();
535 }
536 
537 static const char *getPlatformName(MachO::PlatformType Type) {
538  switch (Type) {
539  case MachO::PLATFORM_MACOS: return "macos";
540  case MachO::PLATFORM_IOS: return "ios";
541  case MachO::PLATFORM_TVOS: return "tvos";
542  case MachO::PLATFORM_WATCHOS: return "watchos";
543  case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
544  case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
545  case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
546  case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
547  }
548  llvm_unreachable("Invalid Mach-O platform type");
549 }
550 
551 void MCAsmStreamer::EmitBuildVersion(unsigned Platform, unsigned Major,
552  unsigned Minor, unsigned Update,
553  VersionTuple SDKVersion) {
554  const char *PlatformName = getPlatformName((MachO::PlatformType)Platform);
555  OS << "\t.build_version " << PlatformName << ", " << Major << ", " << Minor;
556  if (Update)
557  OS << ", " << Update;
558  EmitSDKVersionSuffix(OS, SDKVersion);
559  EmitEOL();
560 }
561 
562 void MCAsmStreamer::EmitThumbFunc(MCSymbol *Func) {
563  // This needs to emit to a temporary string to get properly quoted
564  // MCSymbols when they have spaces in them.
565  OS << "\t.thumb_func";
566  // Only Mach-O hasSubsectionsViaSymbols()
567  if (MAI->hasSubsectionsViaSymbols()) {
568  OS << '\t';
569  Func->print(OS, MAI);
570  }
571  EmitEOL();
572 }
573 
574 void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
575  // Do not emit a .set on inlined target assignments.
576  bool EmitSet = true;
577  if (auto *E = dyn_cast<MCTargetExpr>(Value))
578  if (E->inlineAssignedExpr())
579  EmitSet = false;
580  if (EmitSet) {
581  OS << ".set ";
582  Symbol->print(OS, MAI);
583  OS << ", ";
584  Value->print(OS, MAI);
585 
586  EmitEOL();
587  }
588 
589  MCStreamer::EmitAssignment(Symbol, Value);
590 }
591 
592 void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
593  OS << ".weakref ";
594  Alias->print(OS, MAI);
595  OS << ", ";
596  Symbol->print(OS, MAI);
597  EmitEOL();
598 }
599 
600 bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
602  switch (Attribute) {
603  case MCSA_Invalid: llvm_unreachable("Invalid symbol attribute");
604  case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function
605  case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
606  case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object
607  case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object
608  case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
609  case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
610  case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
611  if (!MAI->hasDotTypeDotSizeDirective())
612  return false; // Symbol attribute not supported
613  OS << "\t.type\t";
614  Symbol->print(OS, MAI);
615  OS << ',' << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
616  switch (Attribute) {
617  default: return false;
618  case MCSA_ELF_TypeFunction: OS << "function"; break;
619  case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
620  case MCSA_ELF_TypeObject: OS << "object"; break;
621  case MCSA_ELF_TypeTLS: OS << "tls_object"; break;
622  case MCSA_ELF_TypeCommon: OS << "common"; break;
623  case MCSA_ELF_TypeNoType: OS << "notype"; break;
624  case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
625  }
626  EmitEOL();
627  return true;
628  case MCSA_Global: // .globl/.global
629  OS << MAI->getGlobalDirective();
630  break;
631  case MCSA_Hidden: OS << "\t.hidden\t"; break;
632  case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
633  case MCSA_Internal: OS << "\t.internal\t"; break;
634  case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break;
635  case MCSA_Local: OS << "\t.local\t"; break;
636  case MCSA_NoDeadStrip:
637  if (!MAI->hasNoDeadStrip())
638  return false;
639  OS << "\t.no_dead_strip\t";
640  break;
641  case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break;
642  case MCSA_AltEntry: OS << "\t.alt_entry\t"; break;
643  case MCSA_PrivateExtern:
644  OS << "\t.private_extern\t";
645  break;
646  case MCSA_Protected: OS << "\t.protected\t"; break;
647  case MCSA_Reference: OS << "\t.reference\t"; break;
648  case MCSA_Weak: OS << MAI->getWeakDirective(); break;
649  case MCSA_WeakDefinition:
650  OS << "\t.weak_definition\t";
651  break;
652  // .weak_reference
653  case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break;
654  case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
655  case MCSA_Cold:
656  // Assemblers currently do not support a .cold directive.
657  return false;
658  }
659 
660  Symbol->print(OS, MAI);
661  EmitEOL();
662 
663  return true;
664 }
665 
666 void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
667  OS << ".desc" << ' ';
668  Symbol->print(OS, MAI);
669  OS << ',' << DescValue;
670  EmitEOL();
671 }
672 
673 void MCAsmStreamer::EmitSyntaxDirective() {
674  if (MAI->getAssemblerDialect() == 1) {
675  OS << "\t.intel_syntax noprefix";
676  EmitEOL();
677  }
678  // FIXME: Currently emit unprefix'ed registers.
679  // The intel_syntax directive has one optional argument
680  // with may have a value of prefix or noprefix.
681 }
682 
683 void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
684  OS << "\t.def\t ";
685  Symbol->print(OS, MAI);
686  OS << ';';
687  EmitEOL();
688 }
689 
690 void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
691  OS << "\t.scl\t" << StorageClass << ';';
692  EmitEOL();
693 }
694 
695 void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
696  OS << "\t.type\t" << Type << ';';
697  EmitEOL();
698 }
699 
700 void MCAsmStreamer::EndCOFFSymbolDef() {
701  OS << "\t.endef";
702  EmitEOL();
703 }
704 
705 void MCAsmStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
706  OS << "\t.safeseh\t";
707  Symbol->print(OS, MAI);
708  EmitEOL();
709 }
710 
711 void MCAsmStreamer::EmitCOFFSymbolIndex(MCSymbol const *Symbol) {
712  OS << "\t.symidx\t";
713  Symbol->print(OS, MAI);
714  EmitEOL();
715 }
716 
717 void MCAsmStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
718  OS << "\t.secidx\t";
719  Symbol->print(OS, MAI);
720  EmitEOL();
721 }
722 
723 void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) {
724  OS << "\t.secrel32\t";
725  Symbol->print(OS, MAI);
726  if (Offset != 0)
727  OS << '+' << Offset;
728  EmitEOL();
729 }
730 
731 void MCAsmStreamer::EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) {
732  OS << "\t.rva\t";
733  Symbol->print(OS, MAI);
734  if (Offset > 0)
735  OS << '+' << Offset;
736  else if (Offset < 0)
737  OS << '-' << -Offset;
738  EmitEOL();
739 }
740 
741 void MCAsmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
743  OS << "\t.size\t";
744  Symbol->print(OS, MAI);
745  OS << ", ";
746  Value->print(OS, MAI);
747  EmitEOL();
748 }
749 
750 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
751  unsigned ByteAlignment) {
752  OS << "\t.comm\t";
753  Symbol->print(OS, MAI);
754  OS << ',' << Size;
755 
756  if (ByteAlignment != 0) {
758  OS << ',' << ByteAlignment;
759  else
760  OS << ',' << Log2_32(ByteAlignment);
761  }
762  EmitEOL();
763 }
764 
765 void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
766  unsigned ByteAlign) {
767  OS << "\t.lcomm\t";
768  Symbol->print(OS, MAI);
769  OS << ',' << Size;
770 
771  if (ByteAlign > 1) {
772  switch (MAI->getLCOMMDirectiveAlignmentType()) {
773  case LCOMM::NoAlignment:
774  llvm_unreachable("alignment not supported on .lcomm!");
776  OS << ',' << ByteAlign;
777  break;
779  assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2");
780  OS << ',' << Log2_32(ByteAlign);
781  break;
782  }
783  }
784  EmitEOL();
785 }
786 
787 void MCAsmStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
788  uint64_t Size, unsigned ByteAlignment,
789  SMLoc Loc) {
790  if (Symbol)
791  AssignFragment(Symbol, &Section->getDummyFragment());
792 
793  // Note: a .zerofill directive does not switch sections.
794  OS << ".zerofill ";
795 
796  assert(Section->getVariant() == MCSection::SV_MachO &&
797  ".zerofill is a Mach-O specific directive");
798  // This is a mach-o specific directive.
799 
800  const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
801  OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
802 
803  if (Symbol) {
804  OS << ',';
805  Symbol->print(OS, MAI);
806  OS << ',' << Size;
807  if (ByteAlignment != 0)
808  OS << ',' << Log2_32(ByteAlignment);
809  }
810  EmitEOL();
811 }
812 
813 // .tbss sym, size, align
814 // This depends that the symbol has already been mangled from the original,
815 // e.g. _a.
816 void MCAsmStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
817  uint64_t Size, unsigned ByteAlignment) {
818  AssignFragment(Symbol, &Section->getDummyFragment());
819 
820  assert(Symbol && "Symbol shouldn't be NULL!");
821  // Instead of using the Section we'll just use the shortcut.
822 
823  assert(Section->getVariant() == MCSection::SV_MachO &&
824  ".zerofill is a Mach-O specific directive");
825  // This is a mach-o specific directive and section.
826 
827  OS << ".tbss ";
828  Symbol->print(OS, MAI);
829  OS << ", " << Size;
830 
831  // Output align if we have it. We default to 1 so don't bother printing
832  // that.
833  if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
834 
835  EmitEOL();
836 }
837 
838 static inline char toOctal(int X) { return (X&7)+'0'; }
839 
840 static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
841  OS << '"';
842 
843  for (unsigned i = 0, e = Data.size(); i != e; ++i) {
844  unsigned char C = Data[i];
845  if (C == '"' || C == '\\') {
846  OS << '\\' << (char)C;
847  continue;
848  }
849 
850  if (isPrint((unsigned char)C)) {
851  OS << (char)C;
852  continue;
853  }
854 
855  switch (C) {
856  case '\b': OS << "\\b"; break;
857  case '\f': OS << "\\f"; break;
858  case '\n': OS << "\\n"; break;
859  case '\r': OS << "\\r"; break;
860  case '\t': OS << "\\t"; break;
861  default:
862  OS << '\\';
863  OS << toOctal(C >> 6);
864  OS << toOctal(C >> 3);
865  OS << toOctal(C >> 0);
866  break;
867  }
868  }
869 
870  OS << '"';
871 }
872 
873 void MCAsmStreamer::EmitBytes(StringRef Data) {
874  assert(getCurrentSectionOnly() &&
875  "Cannot emit contents before setting section!");
876  if (Data.empty()) return;
877 
878  // If only single byte is provided or no ascii or asciz directives is
879  // supported, emit as vector of 8bits data.
880  if (Data.size() == 1 ||
881  !(MAI->getAscizDirective() || MAI->getAsciiDirective())) {
882  if (MCTargetStreamer *TS = getTargetStreamer()) {
883  TS->emitRawBytes(Data);
884  } else {
885  const char *Directive = MAI->getData8bitsDirective();
886  for (const unsigned char C : Data.bytes()) {
887  OS << Directive << (unsigned)C;
888  EmitEOL();
889  }
890  }
891  return;
892  }
893 
894  // If the data ends with 0 and the target supports .asciz, use it, otherwise
895  // use .ascii
896  if (MAI->getAscizDirective() && Data.back() == 0) {
897  OS << MAI->getAscizDirective();
898  Data = Data.substr(0, Data.size()-1);
899  } else {
900  OS << MAI->getAsciiDirective();
901  }
902 
903  PrintQuotedString(Data, OS);
904  EmitEOL();
905 }
906 
907 void MCAsmStreamer::EmitBinaryData(StringRef Data) {
908  // This is binary data. Print it in a grid of hex bytes for readability.
909  const size_t Cols = 4;
910  for (size_t I = 0, EI = alignTo(Data.size(), Cols); I < EI; I += Cols) {
911  size_t J = I, EJ = std::min(I + Cols, Data.size());
912  assert(EJ > 0);
913  OS << MAI->getData8bitsDirective();
914  for (; J < EJ - 1; ++J)
915  OS << format("0x%02x", uint8_t(Data[J])) << ", ";
916  OS << format("0x%02x", uint8_t(Data[J]));
917  EmitEOL();
918  }
919 }
920 
921 void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
922  EmitValue(MCConstantExpr::create(Value, getContext()), Size);
923 }
924 
925 void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
926  SMLoc Loc) {
927  assert(Size <= 8 && "Invalid size");
928  assert(getCurrentSectionOnly() &&
929  "Cannot emit contents before setting section!");
930  const char *Directive = nullptr;
931  switch (Size) {
932  default: break;
933  case 1: Directive = MAI->getData8bitsDirective(); break;
934  case 2: Directive = MAI->getData16bitsDirective(); break;
935  case 4: Directive = MAI->getData32bitsDirective(); break;
936  case 8: Directive = MAI->getData64bitsDirective(); break;
937  }
938 
939  if (!Directive) {
940  int64_t IntValue;
941  if (!Value->evaluateAsAbsolute(IntValue))
942  report_fatal_error("Don't know how to emit this value.");
943 
944  // We couldn't handle the requested integer size so we fallback by breaking
945  // the request down into several, smaller, integers.
946  // Since sizes greater or equal to "Size" are invalid, we use the greatest
947  // power of 2 that is less than "Size" as our largest piece of granularity.
948  bool IsLittleEndian = MAI->isLittleEndian();
949  for (unsigned Emitted = 0; Emitted != Size;) {
950  unsigned Remaining = Size - Emitted;
951  // The size of our partial emission must be a power of two less than
952  // Size.
953  unsigned EmissionSize = PowerOf2Floor(std::min(Remaining, Size - 1));
954  // Calculate the byte offset of our partial emission taking into account
955  // the endianness of the target.
956  unsigned ByteOffset =
957  IsLittleEndian ? Emitted : (Remaining - EmissionSize);
958  uint64_t ValueToEmit = IntValue >> (ByteOffset * 8);
959  // We truncate our partial emission to fit within the bounds of the
960  // emission domain. This produces nicer output and silences potential
961  // truncation warnings when round tripping through another assembler.
962  uint64_t Shift = 64 - EmissionSize * 8;
963  assert(Shift < static_cast<uint64_t>(
964  std::numeric_limits<unsigned long long>::digits) &&
965  "undefined behavior");
966  ValueToEmit &= ~0ULL >> Shift;
967  EmitIntValue(ValueToEmit, EmissionSize);
968  Emitted += EmissionSize;
969  }
970  return;
971  }
972 
973  assert(Directive && "Invalid size for machine code value!");
974  OS << Directive;
975  if (MCTargetStreamer *TS = getTargetStreamer()) {
976  TS->emitValue(Value);
977  } else {
978  Value->print(OS, MAI);
979  EmitEOL();
980  }
981 }
982 
983 void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
984  int64_t IntValue;
985  if (Value->evaluateAsAbsolute(IntValue)) {
986  EmitULEB128IntValue(IntValue);
987  return;
988  }
989  OS << "\t.uleb128 ";
990  Value->print(OS, MAI);
991  EmitEOL();
992 }
993 
994 void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
995  int64_t IntValue;
996  if (Value->evaluateAsAbsolute(IntValue)) {
997  EmitSLEB128IntValue(IntValue);
998  return;
999  }
1000  OS << "\t.sleb128 ";
1001  Value->print(OS, MAI);
1002  EmitEOL();
1003 }
1004 
1005 void MCAsmStreamer::EmitDTPRel64Value(const MCExpr *Value) {
1006  assert(MAI->getDTPRel64Directive() != nullptr);
1007  OS << MAI->getDTPRel64Directive();
1008  Value->print(OS, MAI);
1009  EmitEOL();
1010 }
1011 
1012 void MCAsmStreamer::EmitDTPRel32Value(const MCExpr *Value) {
1013  assert(MAI->getDTPRel32Directive() != nullptr);
1014  OS << MAI->getDTPRel32Directive();
1015  Value->print(OS, MAI);
1016  EmitEOL();
1017 }
1018 
1019 void MCAsmStreamer::EmitTPRel64Value(const MCExpr *Value) {
1020  assert(MAI->getTPRel64Directive() != nullptr);
1021  OS << MAI->getTPRel64Directive();
1022  Value->print(OS, MAI);
1023  EmitEOL();
1024 }
1025 
1026 void MCAsmStreamer::EmitTPRel32Value(const MCExpr *Value) {
1027  assert(MAI->getTPRel32Directive() != nullptr);
1028  OS << MAI->getTPRel32Directive();
1029  Value->print(OS, MAI);
1030  EmitEOL();
1031 }
1032 
1033 void MCAsmStreamer::EmitGPRel64Value(const MCExpr *Value) {
1034  assert(MAI->getGPRel64Directive() != nullptr);
1035  OS << MAI->getGPRel64Directive();
1036  Value->print(OS, MAI);
1037  EmitEOL();
1038 }
1039 
1040 void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
1041  assert(MAI->getGPRel32Directive() != nullptr);
1042  OS << MAI->getGPRel32Directive();
1043  Value->print(OS, MAI);
1044  EmitEOL();
1045 }
1046 
1047 void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
1048  SMLoc Loc) {
1049  int64_t IntNumBytes;
1050  if (NumBytes.evaluateAsAbsolute(IntNumBytes) && IntNumBytes == 0)
1051  return;
1052 
1053  if (const char *ZeroDirective = MAI->getZeroDirective()) {
1054  // FIXME: Emit location directives
1055  OS << ZeroDirective;
1056  NumBytes.print(OS, MAI);
1057  if (FillValue != 0)
1058  OS << ',' << (int)FillValue;
1059  EmitEOL();
1060  return;
1061  }
1062 
1063  MCStreamer::emitFill(NumBytes, FillValue);
1064 }
1065 
1066 void MCAsmStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
1067  int64_t Expr, SMLoc Loc) {
1068  // FIXME: Emit location directives
1069  OS << "\t.fill\t";
1070  NumValues.print(OS, MAI);
1071  OS << ", " << Size << ", 0x";
1072  OS.write_hex(truncateToSize(Expr, 4));
1073  EmitEOL();
1074 }
1075 
1076 void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
1077  unsigned ValueSize,
1078  unsigned MaxBytesToEmit) {
1079  // Some assemblers don't support non-power of two alignments, so we always
1080  // emit alignments as a power of two if possible.
1081  if (isPowerOf2_32(ByteAlignment)) {
1082  switch (ValueSize) {
1083  default:
1084  llvm_unreachable("Invalid size for machine code value!");
1085  case 1:
1086  OS << "\t.p2align\t";
1087  break;
1088  case 2:
1089  OS << ".p2alignw ";
1090  break;
1091  case 4:
1092  OS << ".p2alignl ";
1093  break;
1094  case 8:
1095  llvm_unreachable("Unsupported alignment size!");
1096  }
1097 
1098  OS << Log2_32(ByteAlignment);
1099 
1100  if (Value || MaxBytesToEmit) {
1101  OS << ", 0x";
1102  OS.write_hex(truncateToSize(Value, ValueSize));
1103 
1104  if (MaxBytesToEmit)
1105  OS << ", " << MaxBytesToEmit;
1106  }
1107  EmitEOL();
1108  return;
1109  }
1110 
1111  // Non-power of two alignment. This is not widely supported by assemblers.
1112  // FIXME: Parameterize this based on MAI.
1113  switch (ValueSize) {
1114  default: llvm_unreachable("Invalid size for machine code value!");
1115  case 1: OS << ".balign"; break;
1116  case 2: OS << ".balignw"; break;
1117  case 4: OS << ".balignl"; break;
1118  case 8: llvm_unreachable("Unsupported alignment size!");
1119  }
1120 
1121  OS << ' ' << ByteAlignment;
1122  OS << ", " << truncateToSize(Value, ValueSize);
1123  if (MaxBytesToEmit)
1124  OS << ", " << MaxBytesToEmit;
1125  EmitEOL();
1126 }
1127 
1128 void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
1129  unsigned MaxBytesToEmit) {
1130  // Emit with a text fill value.
1131  EmitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(),
1132  1, MaxBytesToEmit);
1133 }
1134 
1135 void MCAsmStreamer::emitValueToOffset(const MCExpr *Offset,
1136  unsigned char Value,
1137  SMLoc Loc) {
1138  // FIXME: Verify that Offset is associated with the current section.
1139  OS << ".org ";
1140  Offset->print(OS, MAI);
1141  OS << ", " << (unsigned)Value;
1142  EmitEOL();
1143 }
1144 
1145 void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
1147  OS << "\t.file\t";
1148  PrintQuotedString(Filename, OS);
1149  EmitEOL();
1150 }
1151 
1152 static void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
1153  StringRef Filename,
1154  Optional<MD5::MD5Result> Checksum,
1156  bool UseDwarfDirectory,
1157  raw_svector_ostream &OS) {
1158  SmallString<128> FullPathName;
1159 
1160  if (!UseDwarfDirectory && !Directory.empty()) {
1161  if (sys::path::is_absolute(Filename))
1162  Directory = "";
1163  else {
1164  FullPathName = Directory;
1165  sys::path::append(FullPathName, Filename);
1166  Directory = "";
1167  Filename = FullPathName;
1168  }
1169  }
1170 
1171  OS << "\t.file\t" << FileNo << ' ';
1172  if (!Directory.empty()) {
1173  PrintQuotedString(Directory, OS);
1174  OS << ' ';
1175  }
1176  PrintQuotedString(Filename, OS);
1177  if (Checksum)
1178  OS << " md5 0x" << Checksum->digest();
1179  if (Source) {
1180  OS << " source ";
1181  PrintQuotedString(*Source, OS);
1182  }
1183 }
1184 
1185 Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
1186  unsigned FileNo, StringRef Directory, StringRef Filename,
1187  Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source, unsigned CUID) {
1188  assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer");
1189 
1190  MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
1191  unsigned NumFiles = Table.getMCDwarfFiles().size();
1192  Expected<unsigned> FileNoOrErr =
1193  Table.tryGetFile(Directory, Filename, Checksum, Source,
1194  getContext().getDwarfVersion(), 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  Optional<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  raw_ostream &OS = GetCommentOS();
1741  SmallString<256> Code;
1743  raw_svector_ostream VecOS(Code);
1744 
1745  // If we have no code emitter, don't emit code.
1746  if (!getAssembler().getEmitterPtr())
1747  return;
1748 
1749  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
1750 
1751  // If we are showing fixups, create symbolic markers in the encoded
1752  // representation. We do this by making a per-bit map to the fixup item index,
1753  // then trying to display it as nicely as possible.
1754  SmallVector<uint8_t, 64> FixupMap;
1755  FixupMap.resize(Code.size() * 8);
1756  for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
1757  FixupMap[i] = 0;
1758 
1759  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1760  MCFixup &F = Fixups[i];
1761  const MCFixupKindInfo &Info =
1762  getAssembler().getBackend().getFixupKindInfo(F.getKind());
1763  for (unsigned j = 0; j != Info.TargetSize; ++j) {
1764  unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
1765  assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
1766  FixupMap[Index] = 1 + i;
1767  }
1768  }
1769 
1770  // FIXME: Note the fixup comments for Thumb2 are completely bogus since the
1771  // high order halfword of a 32-bit Thumb2 instruction is emitted first.
1772  OS << "encoding: [";
1773  for (unsigned i = 0, e = Code.size(); i != e; ++i) {
1774  if (i)
1775  OS << ',';
1776 
1777  // See if all bits are the same map entry.
1778  uint8_t MapEntry = FixupMap[i * 8 + 0];
1779  for (unsigned j = 1; j != 8; ++j) {
1780  if (FixupMap[i * 8 + j] == MapEntry)
1781  continue;
1782 
1783  MapEntry = uint8_t(~0U);
1784  break;
1785  }
1786 
1787  if (MapEntry != uint8_t(~0U)) {
1788  if (MapEntry == 0) {
1789  OS << format("0x%02x", uint8_t(Code[i]));
1790  } else {
1791  if (Code[i]) {
1792  // FIXME: Some of the 8 bits require fix up.
1793  OS << format("0x%02x", uint8_t(Code[i])) << '\''
1794  << char('A' + MapEntry - 1) << '\'';
1795  } else
1796  OS << char('A' + MapEntry - 1);
1797  }
1798  } else {
1799  // Otherwise, write out in binary.
1800  OS << "0b";
1801  for (unsigned j = 8; j--;) {
1802  unsigned Bit = (Code[i] >> j) & 1;
1803 
1804  unsigned FixupBit;
1805  if (MAI->isLittleEndian())
1806  FixupBit = i * 8 + j;
1807  else
1808  FixupBit = i * 8 + (7-j);
1809 
1810  if (uint8_t MapEntry = FixupMap[FixupBit]) {
1811  assert(Bit == 0 && "Encoder wrote into fixed up bit!");
1812  OS << char('A' + MapEntry - 1);
1813  } else
1814  OS << Bit;
1815  }
1816  }
1817  }
1818  OS << "]\n";
1819 
1820  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1821  MCFixup &F = Fixups[i];
1822  const MCFixupKindInfo &Info =
1823  getAssembler().getBackend().getFixupKindInfo(F.getKind());
1824  OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
1825  << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
1826  }
1827 }
1828 
1829 void MCAsmStreamer::EmitInstruction(const MCInst &Inst,
1830  const MCSubtargetInfo &STI) {
1831  assert(getCurrentSectionOnly() &&
1832  "Cannot emit contents before setting section!");
1833 
1834  // Show the encoding in a comment if we have a code emitter.
1835  AddEncodingComment(Inst, STI);
1836 
1837  // Show the MCInst if enabled.
1838  if (ShowInst) {
1839  Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n ");
1840  GetCommentOS() << "\n";
1841  }
1842 
1843  if(getTargetStreamer())
1844  getTargetStreamer()->prettyPrintAsm(*InstPrinter, OS, Inst, STI);
1845  else
1846  InstPrinter->printInst(&Inst, OS, "", STI);
1847 
1848  StringRef Comments = CommentToEmit;
1849  if (Comments.size() && Comments.back() != '\n')
1850  GetCommentOS() << "\n";
1851 
1852  EmitEOL();
1853 }
1854 
1855 void MCAsmStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
1856  OS << "\t.bundle_align_mode " << AlignPow2;
1857  EmitEOL();
1858 }
1859 
1860 void MCAsmStreamer::EmitBundleLock(bool AlignToEnd) {
1861  OS << "\t.bundle_lock";
1862  if (AlignToEnd)
1863  OS << " align_to_end";
1864  EmitEOL();
1865 }
1866 
1867 void MCAsmStreamer::EmitBundleUnlock() {
1868  OS << "\t.bundle_unlock";
1869  EmitEOL();
1870 }
1871 
1872 bool MCAsmStreamer::EmitRelocDirective(const MCExpr &Offset, StringRef Name,
1873  const MCExpr *Expr, SMLoc,
1874  const MCSubtargetInfo &STI) {
1875  OS << "\t.reloc ";
1876  Offset.print(OS, MAI);
1877  OS << ", " << Name;
1878  if (Expr) {
1879  OS << ", ";
1880  Expr->print(OS, MAI);
1881  }
1882  EmitEOL();
1883  return false;
1884 }
1885 
1886 void MCAsmStreamer::EmitAddrsig() {
1887  OS << "\t.addrsig";
1888  EmitEOL();
1889 }
1890 
1891 void MCAsmStreamer::EmitAddrsigSym(const MCSymbol *Sym) {
1892  OS << "\t.addrsig_sym ";
1893  Sym->print(OS, MAI);
1894  EmitEOL();
1895 }
1896 
1897 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
1898 /// the specified string in the output .s file. This capability is
1899 /// indicated by the hasRawTextSupport() predicate.
1900 void MCAsmStreamer::EmitRawTextImpl(StringRef String) {
1901  if (!String.empty() && String.back() == '\n')
1902  String = String.substr(0, String.size()-1);
1903  OS << String;
1904  EmitEOL();
1905 }
1906 
1907 void MCAsmStreamer::FinishImpl() {
1908  // If we are generating dwarf for assembly source files dump out the sections.
1909  if (getContext().getGenDwarfForAssembly())
1910  MCGenDwarfInfo::Emit(this);
1911 
1912  // Emit the label for the line table, if requested - since the rest of the
1913  // line table will be defined by .loc/.file directives, and not emitted
1914  // directly, the label is the only work required here.
1915  const auto &Tables = getContext().getMCDwarfLineTables();
1916  if (!Tables.empty()) {
1917  assert(Tables.size() == 1 && "asm output only supports one line table");
1918  if (auto *Label = Tables.begin()->second.getLabel()) {
1919  SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
1920  EmitLabel(Label);
1921  }
1922  }
1923 }
1924 
1926  std::unique_ptr<formatted_raw_ostream> OS,
1927  bool isVerboseAsm, bool useDwarfDirectory,
1928  MCInstPrinter *IP,
1929  std::unique_ptr<MCCodeEmitter> &&CE,
1930  std::unique_ptr<MCAsmBackend> &&MAB,
1931  bool ShowInst) {
1932  return new MCAsmStreamer(Context, std::move(OS), isVerboseAsm,
1933  useDwarfDirectory, IP, std::move(CE), std::move(MAB),
1934  ShowInst);
1935 }
bool doesSupportDataRegionDirectives() const
Definition: MCAsmInfo.h:519
bool getCOMMDirectiveAlignmentIsInBytes() const
Definition: MCAsmInfo.h:536
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:235
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:515
const char * getLabelSuffix() const
Definition: MCAsmInfo.h:493
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:330
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:479
virtual void EmitWinCFIPushReg(unsigned Register, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:766
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:544
LLVMContext & Context
bool isPrint(char C)
Checks whether character C is printable.
Definition: StringExtras.h:105
#define DWARF2_FLAG_PROLOGUE_END
Definition: MCDwarf.h:84
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:528
.type _foo, STT_OBJECT # aka
Definition: MCDirectives.h:25
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:622
bool hasSingleParameterDotFile() const
Definition: MCAsmInfo.h:546
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
.watchos_version_min
Definition: MCDirectives.h:68
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:833
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:65
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:512
bool hasDotTypeDotSizeDirective() const
Definition: MCAsmInfo.h:545
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:417
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
Definition: MCStreamer.cpp:571
F(f)
const char * getTPRel64Directive() const
Definition: MCAsmInfo.h:422
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:66
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:1403
MCDataRegionType
Definition: MCDirectives.h:56
Error takeError()
Take ownership of the stored error.
Definition: Error.h:552
virtual void EmitCFIDefCfaOffset(int64_t Offset)
Definition: MCStreamer.cpp:428
.type _foo, STT_NOTYPE # aka
Definition: MCDirectives.h:28
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
Definition: MCStreamer.cpp:244
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:356
bool hasIdentDirective() const
Definition: MCAsmInfo.h:547
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:74
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:369
const char * getDTPRel64Directive() const
Definition: MCAsmInfo.h:420
static int64_t truncateToSize(int64_t Value, unsigned Bytes)
virtual void EmitCFIRememberState()
Definition: MCStreamer.cpp:496
.cold (MachO)
Definition: MCDirectives.h:22
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:455
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:488
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:82
Definition: BitVector.h:937
const char * getAscizDirective() const
Definition: MCAsmInfo.h:525
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:639
virtual void EmitCFIEscape(StringRef Values)
Definition: MCStreamer.cpp:535
const char * getZeroDirective() const
Definition: MCAsmInfo.h:523
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:688
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition: Path.cpp:663
const char * Name
A target specific name for the fixup kind.
.data_region jt16
Definition: MCDirectives.h:59
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:35
const char * getGPRel64Directive() const
Definition: MCAsmInfo.h:418
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:551
.no_dead_strip (MachO)
Definition: MCDirectives.h:36
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:484
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:916
virtual void EmitWinCFIStartChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:661
Context object for machine code objects.
Definition: MCContext.h:62
const char * getWeakDirective() const
Definition: MCAsmInfo.h:550
formatted_raw_ostream & PadToColumn(unsigned NewCol)
PadToColumn - Align the output to some column number.
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:51
#define T
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame)
Definition: MCStreamer.cpp:405
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:24
.alt_entry (MachO)
Definition: MCDirectives.h:38
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:40
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
.lazy_reference (MachO)
Definition: MCDirectives.h:34
virtual void EmitCFIRestoreState()
Definition: MCStreamer.cpp:505
const char * getTPRel32Directive() const
Definition: MCAsmInfo.h:423
bool hasNoDeadStrip() const
Definition: MCAsmInfo.h:548
.reference (MachO)
Definition: MCDirectives.h:41
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:603
virtual void EmitCFIRestore(int64_t Register)
Definition: MCStreamer.cpp:525
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:414
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:56
void append(in_iter S, in_iter E)
Append from an iterator pair.
Definition: SmallString.h:74
.hidden (ELF)
Definition: MCDirectives.h:31
.data_region jt32
Definition: MCDirectives.h:60
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:359
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:45
bool useDwarfRegNumForCFI() const
Definition: MCAsmInfo.h:601
const char * getData16bitsDirective() const
Definition: MCAsmInfo.h:415
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:320
.tvos_version_min
Definition: MCDirectives.h:67
static char toOctal(int X)
unsigned getAssemblerDialect() const
Definition: MCAsmInfo.h:515
#define DWARF2_FLAG_EPILOGUE_BEGIN
Definition: MCDwarf.h:85
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const char * getSeparatorString() const
Definition: MCAsmInfo.h:486
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:448
MCLOHType
Linker Optimization Hint Type.
StringRef getCommentString() const
Definition: MCAsmInfo.h:492
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:50
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
Definition: MCAsmInfo.h:540
#define DWARF2_FLAG_BASIC_BLOCK
Definition: MCDwarf.h:83
virtual void EmitWinEHHandlerData(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:705
static const char * getVersionMinDirective(MCVersionMinType Type)
uint32_t getOffset() const
Definition: MCFixup.h:125
SectionVariant getVariant() const
Definition: MCSection.h:107
virtual void EmitCFIUndefined(int64_t Register)
Definition: MCStreamer.cpp:561
virtual void EmitCFINegateRAState()
Definition: MCStreamer.cpp:591
bool hasSubsectionsViaSymbols() const
Definition: MCAsmInfo.h:410
.weak_reference (MachO)
Definition: MCDirectives.h:44
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:416
virtual void EmitWinCFIEndChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:674
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:777
#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:848
static void PrintCFIEscape(llvm::formatted_raw_ostream &OS, StringRef Values)
const MCDummyFragment & getDummyFragment() const
Definition: MCSection.h:159
virtual void EmitCFIReturnColumn(int64_t Register)
Definition: MCStreamer.cpp:600
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:334
virtual void EmitCFIOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:459
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
virtual void EmitWinCFIEndProlog(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:862
.indirect_symbol (MachO)
Definition: MCDirectives.h:32
virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:799
.type _foo, STT_TLS # aka
Definition: MCDirectives.h:26
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:324
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:49
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:33
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1136
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:52
.type _foo, STT_COMMON # aka
Definition: MCDirectives.h:27
.code64 (X86)
Definition: MCDirectives.h:53
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:37
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:816
.type _foo,
Definition: MCDirectives.h:30
virtual void EmitCFISignalFrame()
Definition: MCStreamer.cpp:554
virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:469
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
MCAssemblerFlag
Definition: MCDirectives.h:48
.type _foo, STT_FUNC # aka
Definition: MCDirectives.h:23
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:421
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:405
.weak_definition (MachO)
Definition: MCDirectives.h:43
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
Definition: MCStreamer.cpp:200
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:417
Target independent information on a fixup kind.
const char * getAsciiDirective() const
Definition: MCAsmInfo.h:524
static void printDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source, bool UseDwarfDirectory, raw_svector_ostream &OS)
const char * getGPRel32Directive() const
Definition: MCAsmInfo.h:419
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
.private_extern (MachO)
Definition: MCDirectives.h:39
unsigned getTextAlignFillValue() const
Definition: MCAsmInfo.h:527
.data_region jt8
Definition: MCDirectives.h:58
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:490
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:279
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:64
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:275
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
virtual void EmitCFIBKeyFrame()
Definition: MCStreamer.cpp:228
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:351
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:128
const char * getCode64Directive() const
Definition: MCAsmInfo.h:514
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
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Definition: MCDwarf.cpp:537
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:438
.end_data_region
Definition: MCDirectives.h:61
MCFixupKind getKind() const
Definition: MCFixup.h:123
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143
const char * getCode32Directive() const
Definition: MCAsmInfo.h:513
virtual void EmitCFIWindowSave()
Definition: MCStreamer.cpp:581
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:344