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  MD5::MD5Result *Checksum = 0,
228  unsigned CUID = 0) override;
229  void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
230  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  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  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, FileNo);
1194  if (!FileNoOrErr)
1195  return FileNoOrErr.takeError();
1196  FileNo = FileNoOrErr.get();
1197  if (NumFiles == Table.getMCDwarfFiles().size())
1198  return FileNo;
1199 
1200  SmallString<128> Str;
1201  raw_svector_ostream OS1(Str);
1202  printDwarfFileDirective(FileNo, Directory, Filename, Checksum, Source,
1203  UseDwarfDirectory, OS1);
1204 
1205  if (MCTargetStreamer *TS = getTargetStreamer())
1206  TS->emitDwarfFileDirective(OS1.str());
1207  else
1208  EmitRawText(OS1.str());
1209 
1210  return FileNo;
1211 }
1212 
1213 void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory,
1214  StringRef Filename,
1215  MD5::MD5Result *Checksum,
1216  Optional<StringRef> Source,
1217  unsigned CUID) {
1218  assert(CUID == 0);
1219  // .file 0 is new for DWARF v5.
1220  if (getContext().getDwarfVersion() < 5)
1221  return;
1222  // Inform MCDwarf about the root file.
1223  getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
1224  Source);
1225 
1226  SmallString<128> Str;
1227  raw_svector_ostream OS1(Str);
1228  printDwarfFileDirective(0, Directory, Filename, Checksum, Source,
1229  UseDwarfDirectory, OS1);
1230 
1231  if (MCTargetStreamer *TS = getTargetStreamer())
1232  TS->emitDwarfFileDirective(OS1.str());
1233  else
1234  EmitRawText(OS1.str());
1235 }
1236 
1237 void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
1238  unsigned Column, unsigned Flags,
1239  unsigned Isa,
1240  unsigned Discriminator,
1241  StringRef FileName) {
1242  OS << "\t.loc\t" << FileNo << " " << Line << " " << Column;
1243  if (MAI->supportsExtendedDwarfLocDirective()) {
1244  if (Flags & DWARF2_FLAG_BASIC_BLOCK)
1245  OS << " basic_block";
1246  if (Flags & DWARF2_FLAG_PROLOGUE_END)
1247  OS << " prologue_end";
1248  if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
1249  OS << " epilogue_begin";
1250 
1251  unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags();
1252  if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
1253  OS << " is_stmt ";
1254 
1255  if (Flags & DWARF2_FLAG_IS_STMT)
1256  OS << "1";
1257  else
1258  OS << "0";
1259  }
1260 
1261  if (Isa)
1262  OS << " isa " << Isa;
1263  if (Discriminator)
1264  OS << " discriminator " << Discriminator;
1265  }
1266 
1267  if (IsVerboseAsm) {
1268  OS.PadToColumn(MAI->getCommentColumn());
1269  OS << MAI->getCommentString() << ' ' << FileName << ':'
1270  << Line << ':' << Column;
1271  }
1272  EmitEOL();
1273  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
1274  Isa, Discriminator, FileName);
1275 }
1276 
1277 MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(unsigned CUID) {
1278  // Always use the zeroth line table, since asm syntax only supports one line
1279  // table for now.
1281 }
1282 
1283 bool MCAsmStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename,
1284  ArrayRef<uint8_t> Checksum,
1285  unsigned ChecksumKind) {
1286  if (!getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum,
1287  ChecksumKind))
1288  return false;
1289 
1290  OS << "\t.cv_file\t" << FileNo << ' ';
1291  PrintQuotedString(Filename, OS);
1292 
1293  if (!ChecksumKind) {
1294  EmitEOL();
1295  return true;
1296  }
1297 
1298  OS << ' ';
1299  PrintQuotedString(toHex(Checksum), OS);
1300  OS << ' ' << ChecksumKind;
1301 
1302  EmitEOL();
1303  return true;
1304 }
1305 
1306 bool MCAsmStreamer::EmitCVFuncIdDirective(unsigned FuncId) {
1307  OS << "\t.cv_func_id " << FuncId << '\n';
1308  return MCStreamer::EmitCVFuncIdDirective(FuncId);
1309 }
1310 
1311 bool MCAsmStreamer::EmitCVInlineSiteIdDirective(unsigned FunctionId,
1312  unsigned IAFunc,
1313  unsigned IAFile,
1314  unsigned IALine, unsigned IACol,
1315  SMLoc Loc) {
1316  OS << "\t.cv_inline_site_id " << FunctionId << " within " << IAFunc
1317  << " inlined_at " << IAFile << ' ' << IALine << ' ' << IACol << '\n';
1318  return MCStreamer::EmitCVInlineSiteIdDirective(FunctionId, IAFunc, IAFile,
1319  IALine, IACol, Loc);
1320 }
1321 
1322 void MCAsmStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
1323  unsigned Line, unsigned Column,
1324  bool PrologueEnd, bool IsStmt,
1325  StringRef FileName, SMLoc Loc) {
1326  // Validate the directive.
1327  if (!checkCVLocSection(FunctionId, FileNo, Loc))
1328  return;
1329 
1330  OS << "\t.cv_loc\t" << FunctionId << " " << FileNo << " " << Line << " "
1331  << Column;
1332  if (PrologueEnd)
1333  OS << " prologue_end";
1334 
1335  if (IsStmt)
1336  OS << " is_stmt 1";
1337 
1338  if (IsVerboseAsm) {
1339  OS.PadToColumn(MAI->getCommentColumn());
1340  OS << MAI->getCommentString() << ' ' << FileName << ':' << Line << ':'
1341  << Column;
1342  }
1343  EmitEOL();
1344 }
1345 
1346 void MCAsmStreamer::EmitCVLinetableDirective(unsigned FunctionId,
1347  const MCSymbol *FnStart,
1348  const MCSymbol *FnEnd) {
1349  OS << "\t.cv_linetable\t" << FunctionId << ", ";
1350  FnStart->print(OS, MAI);
1351  OS << ", ";
1352  FnEnd->print(OS, MAI);
1353  EmitEOL();
1354  this->MCStreamer::EmitCVLinetableDirective(FunctionId, FnStart, FnEnd);
1355 }
1356 
1357 void MCAsmStreamer::EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
1358  unsigned SourceFileId,
1359  unsigned SourceLineNum,
1360  const MCSymbol *FnStartSym,
1361  const MCSymbol *FnEndSym) {
1362  OS << "\t.cv_inline_linetable\t" << PrimaryFunctionId << ' ' << SourceFileId
1363  << ' ' << SourceLineNum << ' ';
1364  FnStartSym->print(OS, MAI);
1365  OS << ' ';
1366  FnEndSym->print(OS, MAI);
1367  EmitEOL();
1369  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
1370 }
1371 
1372 void MCAsmStreamer::EmitCVDefRangeDirective(
1373  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1374  StringRef FixedSizePortion) {
1375  OS << "\t.cv_def_range\t";
1376  for (std::pair<const MCSymbol *, const MCSymbol *> Range : Ranges) {
1377  OS << ' ';
1378  Range.first->print(OS, MAI);
1379  OS << ' ';
1380  Range.second->print(OS, MAI);
1381  }
1382  OS << ", ";
1383  PrintQuotedString(FixedSizePortion, OS);
1384  EmitEOL();
1385  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
1386 }
1387 
1388 void MCAsmStreamer::EmitCVStringTableDirective() {
1389  OS << "\t.cv_stringtable";
1390  EmitEOL();
1391 }
1392 
1393 void MCAsmStreamer::EmitCVFileChecksumsDirective() {
1394  OS << "\t.cv_filechecksums";
1395  EmitEOL();
1396 }
1397 
1398 void MCAsmStreamer::EmitCVFileChecksumOffsetDirective(unsigned FileNo) {
1399  OS << "\t.cv_filechecksumoffset\t" << FileNo;
1400  EmitEOL();
1401 }
1402 
1403 void MCAsmStreamer::EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) {
1404  OS << "\t.cv_fpo_data\t";
1405  ProcSym->print(OS, MAI);
1406  EmitEOL();
1407 }
1408 
1409 void MCAsmStreamer::EmitIdent(StringRef IdentString) {
1410  assert(MAI->hasIdentDirective() && ".ident directive not supported");
1411  OS << "\t.ident\t";
1412  PrintQuotedString(IdentString, OS);
1413  EmitEOL();
1414 }
1415 
1416 void MCAsmStreamer::EmitCFISections(bool EH, bool Debug) {
1417  MCStreamer::EmitCFISections(EH, Debug);
1418  OS << "\t.cfi_sections ";
1419  if (EH) {
1420  OS << ".eh_frame";
1421  if (Debug)
1422  OS << ", .debug_frame";
1423  } else if (Debug) {
1424  OS << ".debug_frame";
1425  }
1426 
1427  EmitEOL();
1428 }
1429 
1430 void MCAsmStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
1431  OS << "\t.cfi_startproc";
1432  if (Frame.IsSimple)
1433  OS << " simple";
1434  EmitEOL();
1435 }
1436 
1437 void MCAsmStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
1439  OS << "\t.cfi_endproc";
1440  EmitEOL();
1441 }
1442 
1443 void MCAsmStreamer::EmitRegisterName(int64_t Register) {
1444  if (!MAI->useDwarfRegNumForCFI()) {
1445  // User .cfi_* directives can use arbitrary DWARF register numbers, not
1446  // just ones that map to LLVM register numbers and have known names.
1447  // Fall back to using the original number directly if no name is known.
1448  const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1449  int LLVMRegister = MRI->getLLVMRegNumFromEH(Register);
1450  if (LLVMRegister != -1) {
1451  InstPrinter->printRegName(OS, LLVMRegister);
1452  return;
1453  }
1454  }
1455  OS << Register;
1456 }
1457 
1458 void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
1459  MCStreamer::EmitCFIDefCfa(Register, Offset);
1460  OS << "\t.cfi_def_cfa ";
1461  EmitRegisterName(Register);
1462  OS << ", " << Offset;
1463  EmitEOL();
1464 }
1465 
1466 void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
1468  OS << "\t.cfi_def_cfa_offset " << Offset;
1469  EmitEOL();
1470 }
1471 
1473  OS << "\t.cfi_escape ";
1474  if (!Values.empty()) {
1475  size_t e = Values.size() - 1;
1476  for (size_t i = 0; i < e; ++i)
1477  OS << format("0x%02x", uint8_t(Values[i])) << ", ";
1478  OS << format("0x%02x", uint8_t(Values[e]));
1479  }
1480 }
1481 
1482 void MCAsmStreamer::EmitCFIEscape(StringRef Values) {
1483  MCStreamer::EmitCFIEscape(Values);
1484  PrintCFIEscape(OS, Values);
1485  EmitEOL();
1486 }
1487 
1488 void MCAsmStreamer::EmitCFIGnuArgsSize(int64_t Size) {
1490 
1491  uint8_t Buffer[16] = { dwarf::DW_CFA_GNU_args_size };
1492  unsigned Len = encodeULEB128(Size, Buffer + 1) + 1;
1493 
1494  PrintCFIEscape(OS, StringRef((const char *)&Buffer[0], Len));
1495  EmitEOL();
1496 }
1497 
1498 void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
1500  OS << "\t.cfi_def_cfa_register ";
1501  EmitRegisterName(Register);
1502  EmitEOL();
1503 }
1504 
1505 void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
1506  this->MCStreamer::EmitCFIOffset(Register, Offset);
1507  OS << "\t.cfi_offset ";
1508  EmitRegisterName(Register);
1509  OS << ", " << Offset;
1510  EmitEOL();
1511 }
1512 
1513 void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
1514  unsigned Encoding) {
1515  MCStreamer::EmitCFIPersonality(Sym, Encoding);
1516  OS << "\t.cfi_personality " << Encoding << ", ";
1517  Sym->print(OS, MAI);
1518  EmitEOL();
1519 }
1520 
1521 void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
1522  MCStreamer::EmitCFILsda(Sym, Encoding);
1523  OS << "\t.cfi_lsda " << Encoding << ", ";
1524  Sym->print(OS, MAI);
1525  EmitEOL();
1526 }
1527 
1528 void MCAsmStreamer::EmitCFIRememberState() {
1530  OS << "\t.cfi_remember_state";
1531  EmitEOL();
1532 }
1533 
1534 void MCAsmStreamer::EmitCFIRestoreState() {
1536  OS << "\t.cfi_restore_state";
1537  EmitEOL();
1538 }
1539 
1540 void MCAsmStreamer::EmitCFIRestore(int64_t Register) {
1541  MCStreamer::EmitCFIRestore(Register);
1542  OS << "\t.cfi_restore ";
1543  EmitRegisterName(Register);
1544  EmitEOL();
1545 }
1546 
1547 void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
1548  MCStreamer::EmitCFISameValue(Register);
1549  OS << "\t.cfi_same_value ";
1550  EmitRegisterName(Register);
1551  EmitEOL();
1552 }
1553 
1554 void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
1555  MCStreamer::EmitCFIRelOffset(Register, Offset);
1556  OS << "\t.cfi_rel_offset ";
1557  EmitRegisterName(Register);
1558  OS << ", " << Offset;
1559  EmitEOL();
1560 }
1561 
1562 void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
1564  OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
1565  EmitEOL();
1566 }
1567 
1568 void MCAsmStreamer::EmitCFISignalFrame() {
1570  OS << "\t.cfi_signal_frame";
1571  EmitEOL();
1572 }
1573 
1574 void MCAsmStreamer::EmitCFIUndefined(int64_t Register) {
1575  MCStreamer::EmitCFIUndefined(Register);
1576  OS << "\t.cfi_undefined " << Register;
1577  EmitEOL();
1578 }
1579 
1580 void MCAsmStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
1581  MCStreamer::EmitCFIRegister(Register1, Register2);
1582  OS << "\t.cfi_register " << Register1 << ", " << Register2;
1583  EmitEOL();
1584 }
1585 
1586 void MCAsmStreamer::EmitCFIWindowSave() {
1588  OS << "\t.cfi_window_save";
1589  EmitEOL();
1590 }
1591 
1592 void MCAsmStreamer::EmitCFINegateRAState() {
1594  OS << "\t.cfi_negate_ra_state";
1595  EmitEOL();
1596 }
1597 
1598 void MCAsmStreamer::EmitCFIReturnColumn(int64_t Register) {
1600  OS << "\t.cfi_return_column " << Register;
1601  EmitEOL();
1602 }
1603 
1604 void MCAsmStreamer::EmitCFIBKeyFrame() {
1606  OS << "\t.cfi_b_key_frame";
1607  EmitEOL();
1608 }
1609 
1610 void MCAsmStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) {
1611  MCStreamer::EmitWinCFIStartProc(Symbol, Loc);
1612 
1613  OS << ".seh_proc ";
1614  Symbol->print(OS, MAI);
1615  EmitEOL();
1616 }
1617 
1618 void MCAsmStreamer::EmitWinCFIEndProc(SMLoc Loc) {
1620 
1621  OS << "\t.seh_endproc";
1622  EmitEOL();
1623 }
1624 
1625 // TODO: Implement
1626 void MCAsmStreamer::EmitWinCFIFuncletOrFuncEnd(SMLoc Loc) {
1627 }
1628 
1629 void MCAsmStreamer::EmitWinCFIStartChained(SMLoc Loc) {
1631 
1632  OS << "\t.seh_startchained";
1633  EmitEOL();
1634 }
1635 
1636 void MCAsmStreamer::EmitWinCFIEndChained(SMLoc Loc) {
1638 
1639  OS << "\t.seh_endchained";
1640  EmitEOL();
1641 }
1642 
1643 void MCAsmStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
1644  bool Except, SMLoc Loc) {
1645  MCStreamer::EmitWinEHHandler(Sym, Unwind, Except, Loc);
1646 
1647  OS << "\t.seh_handler ";
1648  Sym->print(OS, MAI);
1649  if (Unwind)
1650  OS << ", @unwind";
1651  if (Except)
1652  OS << ", @except";
1653  EmitEOL();
1654 }
1655 
1656 void MCAsmStreamer::EmitWinEHHandlerData(SMLoc Loc) {
1658 
1659  // Switch sections. Don't call SwitchSection directly, because that will
1660  // cause the section switch to be visible in the emitted assembly.
1661  // We only do this so the section switch that terminates the handler
1662  // data block is visible.
1663  WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
1664  MCSection *TextSec = &CurFrame->Function->getSection();
1665  MCSection *XData = getAssociatedXDataSection(TextSec);
1666  SwitchSectionNoChange(XData);
1667 
1668  OS << "\t.seh_handlerdata";
1669  EmitEOL();
1670 }
1671 
1672 void MCAsmStreamer::EmitWinCFIPushReg(unsigned Register, SMLoc Loc) {
1673  MCStreamer::EmitWinCFIPushReg(Register, Loc);
1674 
1675  OS << "\t.seh_pushreg " << Register;
1676  EmitEOL();
1677 }
1678 
1679 void MCAsmStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset,
1680  SMLoc Loc) {
1681  MCStreamer::EmitWinCFISetFrame(Register, Offset, Loc);
1682 
1683  OS << "\t.seh_setframe " << Register << ", " << Offset;
1684  EmitEOL();
1685 }
1686 
1687 void MCAsmStreamer::EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) {
1689 
1690  OS << "\t.seh_stackalloc " << Size;
1691  EmitEOL();
1692 }
1693 
1694 void MCAsmStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset,
1695  SMLoc Loc) {
1696  MCStreamer::EmitWinCFISaveReg(Register, Offset, Loc);
1697 
1698  OS << "\t.seh_savereg " << Register << ", " << Offset;
1699  EmitEOL();
1700 }
1701 
1702 void MCAsmStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset,
1703  SMLoc Loc) {
1704  MCStreamer::EmitWinCFISaveXMM(Register, Offset, Loc);
1705 
1706  OS << "\t.seh_savexmm " << Register << ", " << Offset;
1707  EmitEOL();
1708 }
1709 
1710 void MCAsmStreamer::EmitWinCFIPushFrame(bool Code, SMLoc Loc) {
1712 
1713  OS << "\t.seh_pushframe";
1714  if (Code)
1715  OS << " @code";
1716  EmitEOL();
1717 }
1718 
1719 void MCAsmStreamer::EmitWinCFIEndProlog(SMLoc Loc) {
1721 
1722  OS << "\t.seh_endprologue";
1723  EmitEOL();
1724 }
1725 
1726 void MCAsmStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
1727  const MCSymbolRefExpr *To,
1728  uint64_t Count) {
1729  OS << "\t.cg_profile ";
1730  From->getSymbol().print(OS, MAI);
1731  OS << ", ";
1732  To->getSymbol().print(OS, MAI);
1733  OS << ", " << Count;
1734  EmitEOL();
1735 }
1736 
1737 void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
1738  const MCSubtargetInfo &STI) {
1739  raw_ostream &OS = GetCommentOS();
1740  SmallString<256> Code;
1742  raw_svector_ostream VecOS(Code);
1743 
1744  // If we have no code emitter, don't emit code.
1745  if (!getAssembler().getEmitterPtr())
1746  return;
1747 
1748  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
1749 
1750  // If we are showing fixups, create symbolic markers in the encoded
1751  // representation. We do this by making a per-bit map to the fixup item index,
1752  // then trying to display it as nicely as possible.
1753  SmallVector<uint8_t, 64> FixupMap;
1754  FixupMap.resize(Code.size() * 8);
1755  for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
1756  FixupMap[i] = 0;
1757 
1758  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1759  MCFixup &F = Fixups[i];
1760  const MCFixupKindInfo &Info =
1761  getAssembler().getBackend().getFixupKindInfo(F.getKind());
1762  for (unsigned j = 0; j != Info.TargetSize; ++j) {
1763  unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
1764  assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
1765  FixupMap[Index] = 1 + i;
1766  }
1767  }
1768 
1769  // FIXME: Note the fixup comments for Thumb2 are completely bogus since the
1770  // high order halfword of a 32-bit Thumb2 instruction is emitted first.
1771  OS << "encoding: [";
1772  for (unsigned i = 0, e = Code.size(); i != e; ++i) {
1773  if (i)
1774  OS << ',';
1775 
1776  // See if all bits are the same map entry.
1777  uint8_t MapEntry = FixupMap[i * 8 + 0];
1778  for (unsigned j = 1; j != 8; ++j) {
1779  if (FixupMap[i * 8 + j] == MapEntry)
1780  continue;
1781 
1782  MapEntry = uint8_t(~0U);
1783  break;
1784  }
1785 
1786  if (MapEntry != uint8_t(~0U)) {
1787  if (MapEntry == 0) {
1788  OS << format("0x%02x", uint8_t(Code[i]));
1789  } else {
1790  if (Code[i]) {
1791  // FIXME: Some of the 8 bits require fix up.
1792  OS << format("0x%02x", uint8_t(Code[i])) << '\''
1793  << char('A' + MapEntry - 1) << '\'';
1794  } else
1795  OS << char('A' + MapEntry - 1);
1796  }
1797  } else {
1798  // Otherwise, write out in binary.
1799  OS << "0b";
1800  for (unsigned j = 8; j--;) {
1801  unsigned Bit = (Code[i] >> j) & 1;
1802 
1803  unsigned FixupBit;
1804  if (MAI->isLittleEndian())
1805  FixupBit = i * 8 + j;
1806  else
1807  FixupBit = i * 8 + (7-j);
1808 
1809  if (uint8_t MapEntry = FixupMap[FixupBit]) {
1810  assert(Bit == 0 && "Encoder wrote into fixed up bit!");
1811  OS << char('A' + MapEntry - 1);
1812  } else
1813  OS << Bit;
1814  }
1815  }
1816  }
1817  OS << "]\n";
1818 
1819  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
1820  MCFixup &F = Fixups[i];
1821  const MCFixupKindInfo &Info =
1822  getAssembler().getBackend().getFixupKindInfo(F.getKind());
1823  OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
1824  << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
1825  }
1826 }
1827 
1828 void MCAsmStreamer::EmitInstruction(const MCInst &Inst,
1829  const MCSubtargetInfo &STI) {
1830  assert(getCurrentSectionOnly() &&
1831  "Cannot emit contents before setting section!");
1832 
1833  // Show the encoding in a comment if we have a code emitter.
1834  AddEncodingComment(Inst, STI);
1835 
1836  // Show the MCInst if enabled.
1837  if (ShowInst) {
1838  Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n ");
1839  GetCommentOS() << "\n";
1840  }
1841 
1842  if(getTargetStreamer())
1843  getTargetStreamer()->prettyPrintAsm(*InstPrinter, OS, Inst, STI);
1844  else
1845  InstPrinter->printInst(&Inst, OS, "", STI);
1846 
1847  StringRef Comments = CommentToEmit;
1848  if (Comments.size() && Comments.back() != '\n')
1849  GetCommentOS() << "\n";
1850 
1851  EmitEOL();
1852 }
1853 
1854 void MCAsmStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
1855  OS << "\t.bundle_align_mode " << AlignPow2;
1856  EmitEOL();
1857 }
1858 
1859 void MCAsmStreamer::EmitBundleLock(bool AlignToEnd) {
1860  OS << "\t.bundle_lock";
1861  if (AlignToEnd)
1862  OS << " align_to_end";
1863  EmitEOL();
1864 }
1865 
1866 void MCAsmStreamer::EmitBundleUnlock() {
1867  OS << "\t.bundle_unlock";
1868  EmitEOL();
1869 }
1870 
1871 bool MCAsmStreamer::EmitRelocDirective(const MCExpr &Offset, StringRef Name,
1872  const MCExpr *Expr, SMLoc,
1873  const MCSubtargetInfo &STI) {
1874  OS << "\t.reloc ";
1875  Offset.print(OS, MAI);
1876  OS << ", " << Name;
1877  if (Expr) {
1878  OS << ", ";
1879  Expr->print(OS, MAI);
1880  }
1881  EmitEOL();
1882  return false;
1883 }
1884 
1885 void MCAsmStreamer::EmitAddrsig() {
1886  OS << "\t.addrsig";
1887  EmitEOL();
1888 }
1889 
1890 void MCAsmStreamer::EmitAddrsigSym(const MCSymbol *Sym) {
1891  OS << "\t.addrsig_sym ";
1892  Sym->print(OS, MAI);
1893  EmitEOL();
1894 }
1895 
1896 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
1897 /// the specified string in the output .s file. This capability is
1898 /// indicated by the hasRawTextSupport() predicate.
1899 void MCAsmStreamer::EmitRawTextImpl(StringRef String) {
1900  if (!String.empty() && String.back() == '\n')
1901  String = String.substr(0, String.size()-1);
1902  OS << String;
1903  EmitEOL();
1904 }
1905 
1906 void MCAsmStreamer::FinishImpl() {
1907  // If we are generating dwarf for assembly source files dump out the sections.
1908  if (getContext().getGenDwarfForAssembly())
1909  MCGenDwarfInfo::Emit(this);
1910 
1911  // Emit the label for the line table, if requested - since the rest of the
1912  // line table will be defined by .loc/.file directives, and not emitted
1913  // directly, the label is the only work required here.
1914  auto &Tables = getContext().getMCDwarfLineTables();
1915  if (!Tables.empty()) {
1916  assert(Tables.size() == 1 && "asm output only supports one line table");
1917  if (auto *Label = Tables.begin()->second.getLabel()) {
1918  SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
1919  EmitLabel(Label);
1920  }
1921  }
1922 }
1923 
1925  std::unique_ptr<formatted_raw_ostream> OS,
1926  bool isVerboseAsm, bool useDwarfDirectory,
1927  MCInstPrinter *IP,
1928  std::unique_ptr<MCCodeEmitter> &&CE,
1929  std::unique_ptr<MCAsmBackend> &&MAB,
1930  bool ShowInst) {
1931  return new MCAsmStreamer(Context, std::move(OS), isVerboseAsm,
1932  useDwarfDirectory, IP, std::move(CE), std::move(MAB),
1933  ShowInst);
1934 }
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: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:617
bool hasSingleParameterDotFile() const
Definition: MCAsmInfo.h:539
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: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: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: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: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:1348
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:423
.type _foo, STT_NOTYPE # aka
Definition: MCDirectives.h:28
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
Definition: MCStreamer.cpp:239
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:356
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
.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:454
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:483
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:79
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:662
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: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: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: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:51
#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: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:500
const char * getTPRel32Directive() const
Definition: MCAsmInfo.h:422
bool hasNoDeadStrip() const
Definition: MCAsmInfo.h:541
.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: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:31
.data_region jt32
Definition: MCDirectives.h:60
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:344
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: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:67
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
.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: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: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: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:332
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:537
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:857
.indirect_symbol (MachO)
Definition: MCDirectives.h:32
virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:794
.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: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: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:1130
.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:811
.type _foo,
Definition: MCDirectives.h:30
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: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: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:43
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 char * getGPRel32Directive() const
Definition: MCAsmInfo.h:418
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
.private_extern (MachO)
Definition: MCDirectives.h:39
unsigned getTextAlignFillValue() const
Definition: MCAsmInfo.h:520
.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: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: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: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:61
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:344