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