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