Create a MCSymbolELF.
[oota-llvm.git] / include / llvm / MC / MCStreamer.h
1 //===- MCStreamer.h - High-level Streaming Machine Code 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 // This file declares the MCStreamer class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCSTREAMER_H
15 #define LLVM_MC_MCSTREAMER_H
16
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCLinkerOptimizationHint.h"
22 #include "llvm/MC/MCWinEH.h"
23 #include "llvm/Support/DataTypes.h"
24 #include "llvm/Support/SMLoc.h"
25 #include <string>
26
27 namespace llvm {
28 class MCAsmBackend;
29 class MCCodeEmitter;
30 class MCContext;
31 class MCExpr;
32 class MCInst;
33 class MCInstPrinter;
34 class MCSection;
35 class MCStreamer;
36 class MCSymbol;
37 class MCSymbolELF;
38 class MCSymbolRefExpr;
39 class MCSubtargetInfo;
40 class StringRef;
41 class Twine;
42 class raw_ostream;
43 class formatted_raw_ostream;
44 class AssemblerConstantPools;
45
46 typedef std::pair<MCSection *, const MCExpr *> MCSectionSubPair;
47
48 /// Target specific streamer interface. This is used so that targets can
49 /// implement support for target specific assembly directives.
50 ///
51 /// If target foo wants to use this, it should implement 3 classes:
52 /// * FooTargetStreamer : public MCTargetStreamer
53 /// * FooTargetAsmStreamer : public FooTargetStreamer
54 /// * FooTargetELFStreamer : public FooTargetStreamer
55 ///
56 /// FooTargetStreamer should have a pure virtual method for each directive. For
57 /// example, for a ".bar symbol_name" directive, it should have
58 /// virtual emitBar(const MCSymbol &Symbol) = 0;
59 ///
60 /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
61 /// method. The assembly streamer just prints ".bar symbol_name". The object
62 /// streamer does whatever is needed to implement .bar in the object file.
63 ///
64 /// In the assembly printer and parser the target streamer can be used by
65 /// calling getTargetStreamer and casting it to FooTargetStreamer:
66 ///
67 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
68 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
69 ///
70 /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
71 /// *never* be treated differently. Callers should always talk to a
72 /// FooTargetStreamer.
73 class MCTargetStreamer {
74 protected:
75   MCStreamer &Streamer;
76
77 public:
78   MCTargetStreamer(MCStreamer &S);
79   virtual ~MCTargetStreamer();
80
81   const MCStreamer &getStreamer() { return Streamer; }
82
83   // Allow a target to add behavior to the EmitLabel of MCStreamer.
84   virtual void emitLabel(MCSymbol *Symbol);
85   // Allow a target to add behavior to the emitAssignment of MCStreamer.
86   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
87
88   virtual void finish();
89 };
90
91 // FIXME: declared here because it is used from
92 // lib/CodeGen/AsmPrinter/ARMException.cpp.
93 class ARMTargetStreamer : public MCTargetStreamer {
94 public:
95   ARMTargetStreamer(MCStreamer &S);
96   ~ARMTargetStreamer() override;
97
98   virtual void emitFnStart();
99   virtual void emitFnEnd();
100   virtual void emitCantUnwind();
101   virtual void emitPersonality(const MCSymbol *Personality);
102   virtual void emitPersonalityIndex(unsigned Index);
103   virtual void emitHandlerData();
104   virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
105                          int64_t Offset = 0);
106   virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
107   virtual void emitPad(int64_t Offset);
108   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
109                            bool isVector);
110   virtual void emitUnwindRaw(int64_t StackOffset,
111                              const SmallVectorImpl<uint8_t> &Opcodes);
112
113   virtual void switchVendor(StringRef Vendor);
114   virtual void emitAttribute(unsigned Attribute, unsigned Value);
115   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
116   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
117                                     StringRef StringValue = "");
118   virtual void emitFPU(unsigned FPU);
119   virtual void emitArch(unsigned Arch);
120   virtual void emitArchExtension(unsigned ArchExt);
121   virtual void emitObjectArch(unsigned Arch);
122   virtual void finishAttributeSection();
123   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
124
125   virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
126
127   virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
128
129   void finish() override;
130
131   /// Callback used to implement the ldr= pseudo.
132   /// Add a new entry to the constant pool for the current section and return an
133   /// MCExpr that can be used to refer to the constant pool location.
134   const MCExpr *addConstantPoolEntry(const MCExpr *);
135
136   /// Callback used to implemnt the .ltorg directive.
137   /// Emit contents of constant pool for the current section.
138   void emitCurrentConstantPool();
139
140 private:
141   std::unique_ptr<AssemblerConstantPools> ConstantPools;
142 };
143
144 /// \brief Streaming machine code generation interface.
145 ///
146 /// This interface is intended to provide a programatic interface that is very
147 /// similar to the level that an assembler .s file provides.  It has callbacks
148 /// to emit bytes, handle directives, etc.  The implementation of this interface
149 /// retains state to know what the current section is etc.
150 ///
151 /// There are multiple implementations of this interface: one for writing out
152 /// a .s file, and implementations that write out .o files of various formats.
153 ///
154 class MCStreamer {
155   MCContext &Context;
156   std::unique_ptr<MCTargetStreamer> TargetStreamer;
157
158   MCStreamer(const MCStreamer &) = delete;
159   MCStreamer &operator=(const MCStreamer &) = delete;
160
161   std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
162   MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
163   void EnsureValidDwarfFrame();
164
165   MCSymbol *EmitCFICommon();
166
167   std::vector<WinEH::FrameInfo *> WinFrameInfos;
168   WinEH::FrameInfo *CurrentWinFrameInfo;
169   void EnsureValidWinFrameInfo();
170
171   /// \brief Tracks an index to represent the order a symbol was emitted in.
172   /// Zero means we did not emit that symbol.
173   DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
174
175   /// \brief This is stack of current and previous section values saved by
176   /// PushSection.
177   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
178
179 protected:
180   MCStreamer(MCContext &Ctx);
181
182   virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
183   virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
184
185   WinEH::FrameInfo *getCurrentWinFrameInfo() {
186     return CurrentWinFrameInfo;
187   }
188
189   virtual void EmitWindowsUnwindTables();
190
191   virtual void EmitRawTextImpl(StringRef String);
192
193 public:
194   virtual ~MCStreamer();
195
196   void visitUsedExpr(const MCExpr &Expr);
197   virtual void visitUsedSymbol(const MCSymbol &Sym);
198
199   void setTargetStreamer(MCTargetStreamer *TS) {
200     TargetStreamer.reset(TS);
201   }
202
203   /// State management
204   ///
205   virtual void reset();
206
207   MCContext &getContext() const { return Context; }
208
209   MCTargetStreamer *getTargetStreamer() {
210     return TargetStreamer.get();
211   }
212
213   unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
214   ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
215     return DwarfFrameInfos;
216   }
217
218   unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
219   ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
220     return WinFrameInfos;
221   }
222
223   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
224
225   /// \name Assembly File Formatting.
226   /// @{
227
228   /// \brief Return true if this streamer supports verbose assembly and if it is
229   /// enabled.
230   virtual bool isVerboseAsm() const { return false; }
231
232   /// \brief Return true if this asm streamer supports emitting unformatted text
233   /// to the .s file with EmitRawText.
234   virtual bool hasRawTextSupport() const { return false; }
235
236   /// \brief Is the integrated assembler required for this streamer to function
237   /// correctly?
238   virtual bool isIntegratedAssemblerRequired() const { return false; }
239
240   /// \brief Add a textual command.
241   ///
242   /// Typically for comments that can be emitted to the generated .s
243   /// file if applicable as a QoI issue to make the output of the compiler
244   /// more readable.  This only affects the MCAsmStreamer, and only when
245   /// verbose assembly output is enabled.
246   ///
247   /// If the comment includes embedded \n's, they will each get the comment
248   /// prefix as appropriate.  The added comment should not end with a \n.
249   virtual void AddComment(const Twine &T) {}
250
251   /// \brief Return a raw_ostream that comments can be written to. Unlike
252   /// AddComment, you are required to terminate comments with \n if you use this
253   /// method.
254   virtual raw_ostream &GetCommentOS();
255
256   /// \brief Print T and prefix it with the comment string (normally #) and
257   /// optionally a tab. This prints the comment immediately, not at the end of
258   /// the current line. It is basically a safe version of EmitRawText: since it
259   /// only prints comments, the object streamer ignores it instead of asserting.
260   virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
261
262   /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
263   virtual void AddBlankLine() {}
264
265   /// @}
266
267   /// \name Symbol & Section Management
268   /// @{
269
270   /// \brief Return the current section that the streamer is emitting code to.
271   MCSectionSubPair getCurrentSection() const {
272     if (!SectionStack.empty())
273       return SectionStack.back().first;
274     return MCSectionSubPair();
275   }
276   MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; }
277
278   /// \brief Return the previous section that the streamer is emitting code to.
279   MCSectionSubPair getPreviousSection() const {
280     if (!SectionStack.empty())
281       return SectionStack.back().second;
282     return MCSectionSubPair();
283   }
284
285   /// \brief Returns an index to represent the order a symbol was emitted in.
286   /// (zero if we did not emit that symbol)
287   unsigned GetSymbolOrder(const MCSymbol *Sym) const {
288     return SymbolOrdering.lookup(Sym);
289   }
290
291   /// \brief Update streamer for a new active section.
292   ///
293   /// This is called by PopSection and SwitchSection, if the current
294   /// section changes.
295   virtual void ChangeSection(MCSection *, const MCExpr *);
296
297   /// \brief Save the current and previous section on the section stack.
298   void PushSection() {
299     SectionStack.push_back(
300         std::make_pair(getCurrentSection(), getPreviousSection()));
301   }
302
303   /// \brief Restore the current and previous section from the section stack.
304   /// Calls ChangeSection as needed.
305   ///
306   /// Returns false if the stack was empty.
307   bool PopSection() {
308     if (SectionStack.size() <= 1)
309       return false;
310     MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
311     MCSectionSubPair curSection = SectionStack.back().first;
312
313     if (oldSection != curSection)
314       ChangeSection(curSection.first, curSection.second);
315     return true;
316   }
317
318   bool SubSection(const MCExpr *Subsection) {
319     if (SectionStack.empty())
320       return false;
321
322     SwitchSection(SectionStack.back().first.first, Subsection);
323     return true;
324   }
325
326   /// Set the current section where code is being emitted to \p Section.  This
327   /// is required to update CurSection.
328   ///
329   /// This corresponds to assembler directives like .section, .text, etc.
330   virtual void SwitchSection(MCSection *Section,
331                              const MCExpr *Subsection = nullptr);
332
333   /// \brief Set the current section where code is being emitted to \p Section.
334   /// This is required to update CurSection. This version does not call
335   /// ChangeSection.
336   void SwitchSectionNoChange(MCSection *Section,
337                              const MCExpr *Subsection = nullptr) {
338     assert(Section && "Cannot switch to a null section!");
339     MCSectionSubPair curSection = SectionStack.back().first;
340     SectionStack.back().second = curSection;
341     if (MCSectionSubPair(Section, Subsection) != curSection)
342       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
343   }
344
345   /// \brief Create the default sections and set the initial one.
346   virtual void InitSections(bool NoExecStack);
347
348   MCSymbol *endSection(MCSection *Section);
349
350   /// \brief Sets the symbol's section.
351   ///
352   /// Each emitted symbol will be tracked in the ordering table,
353   /// so we can sort on them later.
354   void AssignSection(MCSymbol *Symbol, MCSection *Section);
355
356   /// \brief Emit a label for \p Symbol into the current section.
357   ///
358   /// This corresponds to an assembler statement such as:
359   ///   foo:
360   ///
361   /// \param Symbol - The symbol to emit. A given symbol should only be
362   /// emitted as a label once, and symbols emitted as a label should never be
363   /// used in an assignment.
364   // FIXME: These emission are non-const because we mutate the symbol to
365   // add the section we're emitting it to later.
366   virtual void EmitLabel(MCSymbol *Symbol);
367
368   virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
369
370   /// \brief Note in the output the specified \p Flag.
371   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
372
373   /// \brief Emit the given list \p Options of strings as linker
374   /// options into the output.
375   virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
376
377   /// \brief Note in the output the specified region \p Kind.
378   virtual void EmitDataRegion(MCDataRegionType Kind) {}
379
380   /// \brief Specify the MachO minimum deployment target version.
381   virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
382                               unsigned Update) {}
383
384   /// \brief Note in the output that the specified \p Func is a Thumb mode
385   /// function (ARM target only).
386   virtual void EmitThumbFunc(MCSymbol *Func);
387
388   /// \brief Emit an assignment of \p Value to \p Symbol.
389   ///
390   /// This corresponds to an assembler statement such as:
391   ///  symbol = value
392   ///
393   /// The assignment generates no code, but has the side effect of binding the
394   /// value in the current context. For the assembly streamer, this prints the
395   /// binding into the .s file.
396   ///
397   /// \param Symbol - The symbol being assigned to.
398   /// \param Value - The value for the symbol.
399   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
400
401   /// \brief Emit an weak reference from \p Alias to \p Symbol.
402   ///
403   /// This corresponds to an assembler statement such as:
404   ///  .weakref alias, symbol
405   ///
406   /// \param Alias - The alias that is being created.
407   /// \param Symbol - The symbol being aliased.
408   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
409
410   /// \brief Add the given \p Attribute to \p Symbol.
411   virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
412                                    MCSymbolAttr Attribute) = 0;
413
414   /// \brief Set the \p DescValue for the \p Symbol.
415   ///
416   /// \param Symbol - The symbol to have its n_desc field set.
417   /// \param DescValue - The value to set into the n_desc field.
418   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
419
420   /// \brief Start emitting COFF symbol definition
421   ///
422   /// \param Symbol - The symbol to have its External & Type fields set.
423   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
424
425   /// \brief Emit the storage class of the symbol.
426   ///
427   /// \param StorageClass - The storage class the symbol should have.
428   virtual void EmitCOFFSymbolStorageClass(int StorageClass);
429
430   /// \brief Emit the type of the symbol.
431   ///
432   /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
433   virtual void EmitCOFFSymbolType(int Type);
434
435   /// \brief Marks the end of the symbol definition.
436   virtual void EndCOFFSymbolDef();
437
438   virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol);
439
440   /// \brief Emits a COFF section index.
441   ///
442   /// \param Symbol - Symbol the section number relocation should point to.
443   virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
444
445   /// \brief Emits a COFF section relative relocation.
446   ///
447   /// \param Symbol - Symbol the section relative relocation should point to.
448   virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
449
450   /// \brief Emit an ELF .size directive.
451   ///
452   /// This corresponds to an assembler statement such as:
453   ///  .size symbol, expression
454   virtual void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value);
455
456   /// \brief Emit a Linker Optimization Hint (LOH) directive.
457   /// \param Args - Arguments of the LOH.
458   virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
459
460   /// \brief Emit a common symbol.
461   ///
462   /// \param Symbol - The common symbol to emit.
463   /// \param Size - The size of the common symbol.
464   /// \param ByteAlignment - The alignment of the symbol if
465   /// non-zero. This must be a power of 2.
466   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
467                                 unsigned ByteAlignment) = 0;
468
469   /// \brief Emit a local common (.lcomm) symbol.
470   ///
471   /// \param Symbol - The common symbol to emit.
472   /// \param Size - The size of the common symbol.
473   /// \param ByteAlignment - The alignment of the common symbol in bytes.
474   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
475                                      unsigned ByteAlignment);
476
477   /// \brief Emit the zerofill section and an optional symbol.
478   ///
479   /// \param Section - The zerofill section to create and or to put the symbol
480   /// \param Symbol - The zerofill symbol to emit, if non-NULL.
481   /// \param Size - The size of the zerofill symbol.
482   /// \param ByteAlignment - The alignment of the zerofill symbol if
483   /// non-zero. This must be a power of 2 on some targets.
484   virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
485                             uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
486
487   /// \brief Emit a thread local bss (.tbss) symbol.
488   ///
489   /// \param Section - The thread local common section.
490   /// \param Symbol - The thread local common symbol to emit.
491   /// \param Size - The size of the symbol.
492   /// \param ByteAlignment - The alignment of the thread local common symbol
493   /// if non-zero.  This must be a power of 2 on some targets.
494   virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
495                               uint64_t Size, unsigned ByteAlignment = 0);
496
497   /// @}
498   /// \name Generating Data
499   /// @{
500
501   /// \brief Emit the bytes in \p Data into the output.
502   ///
503   /// This is used to implement assembler directives such as .byte, .ascii,
504   /// etc.
505   virtual void EmitBytes(StringRef Data);
506
507   /// \brief Emit the expression \p Value into the output as a native
508   /// integer of the given \p Size bytes.
509   ///
510   /// This is used to implement assembler directives such as .word, .quad,
511   /// etc.
512   ///
513   /// \param Value - The value to emit.
514   /// \param Size - The size of the integer (in bytes) to emit. This must
515   /// match a native machine width.
516   /// \param Loc - The location of the expression for error reporting.
517   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
518                              const SMLoc &Loc = SMLoc());
519
520   void EmitValue(const MCExpr *Value, unsigned Size,
521                  const SMLoc &Loc = SMLoc());
522
523   /// \brief Special case of EmitValue that avoids the client having
524   /// to pass in a MCExpr for constant integers.
525   virtual void EmitIntValue(uint64_t Value, unsigned Size);
526
527   virtual void EmitULEB128Value(const MCExpr *Value);
528
529   virtual void EmitSLEB128Value(const MCExpr *Value);
530
531   /// \brief Special case of EmitULEB128Value that avoids the client having to
532   /// pass in a MCExpr for constant integers.
533   void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
534
535   /// \brief Special case of EmitSLEB128Value that avoids the client having to
536   /// pass in a MCExpr for constant integers.
537   void EmitSLEB128IntValue(int64_t Value);
538
539   /// \brief Special case of EmitValue that avoids the client having to pass in
540   /// a MCExpr for MCSymbols.
541   void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
542                        bool IsSectionRelative = false);
543
544   /// \brief Emit the expression \p Value into the output as a gprel64 (64-bit
545   /// GP relative) value.
546   ///
547   /// This is used to implement assembler directives such as .gpdword on
548   /// targets that support them.
549   virtual void EmitGPRel64Value(const MCExpr *Value);
550
551   /// \brief Emit the expression \p Value into the output as a gprel32 (32-bit
552   /// GP relative) value.
553   ///
554   /// This is used to implement assembler directives such as .gprel32 on
555   /// targets that support them.
556   virtual void EmitGPRel32Value(const MCExpr *Value);
557
558   /// \brief Emit NumBytes bytes worth of the value specified by FillValue.
559   /// This implements directives such as '.space'.
560   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
561
562   /// \brief Emit NumBytes worth of zeros.
563   /// This function properly handles data in virtual sections.
564   virtual void EmitZeros(uint64_t NumBytes);
565
566   /// \brief Emit some number of copies of \p Value until the byte alignment \p
567   /// ByteAlignment is reached.
568   ///
569   /// If the number of bytes need to emit for the alignment is not a multiple
570   /// of \p ValueSize, then the contents of the emitted fill bytes is
571   /// undefined.
572   ///
573   /// This used to implement the .align assembler directive.
574   ///
575   /// \param ByteAlignment - The alignment to reach. This must be a power of
576   /// two on some targets.
577   /// \param Value - The value to use when filling bytes.
578   /// \param ValueSize - The size of the integer (in bytes) to emit for
579   /// \p Value. This must match a native machine width.
580   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
581   /// the alignment cannot be reached in this many bytes, no bytes are
582   /// emitted.
583   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
584                                     unsigned ValueSize = 1,
585                                     unsigned MaxBytesToEmit = 0);
586
587   /// \brief Emit nops until the byte alignment \p ByteAlignment is reached.
588   ///
589   /// This used to align code where the alignment bytes may be executed.  This
590   /// can emit different bytes for different sizes to optimize execution.
591   ///
592   /// \param ByteAlignment - The alignment to reach. This must be a power of
593   /// two on some targets.
594   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
595   /// the alignment cannot be reached in this many bytes, no bytes are
596   /// emitted.
597   virtual void EmitCodeAlignment(unsigned ByteAlignment,
598                                  unsigned MaxBytesToEmit = 0);
599
600   /// \brief Emit some number of copies of \p Value until the byte offset \p
601   /// Offset is reached.
602   ///
603   /// This is used to implement assembler directives such as .org.
604   ///
605   /// \param Offset - The offset to reach. This may be an expression, but the
606   /// expression must be associated with the current section.
607   /// \param Value - The value to use when filling bytes.
608   /// \return false on success, true if the offset was invalid.
609   virtual bool EmitValueToOffset(const MCExpr *Offset,
610                                  unsigned char Value = 0);
611
612   /// @}
613
614   /// \brief Switch to a new logical file.  This is used to implement the '.file
615   /// "foo.c"' assembler directive.
616   virtual void EmitFileDirective(StringRef Filename);
617
618   /// \brief Emit the "identifiers" directive.  This implements the
619   /// '.ident "version foo"' assembler directive.
620   virtual void EmitIdent(StringRef IdentString) {}
621
622   /// \brief Associate a filename with a specified logical file number.  This
623   /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
624   virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
625                                           StringRef Filename,
626                                           unsigned CUID = 0);
627
628   /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler
629   /// directive.
630   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
631                                      unsigned Column, unsigned Flags,
632                                      unsigned Isa, unsigned Discriminator,
633                                      StringRef FileName);
634
635   /// Emit the absolute difference between two symbols if possible.
636   ///
637   /// \pre Offset of \c Hi is greater than the offset \c Lo.
638   /// \return true on success.
639   virtual bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
640                                       unsigned Size) {
641     return false;
642   }
643
644   virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
645   virtual void EmitCFISections(bool EH, bool Debug);
646   void EmitCFIStartProc(bool IsSimple);
647   void EmitCFIEndProc();
648   virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
649   virtual void EmitCFIDefCfaOffset(int64_t Offset);
650   virtual void EmitCFIDefCfaRegister(int64_t Register);
651   virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
652   virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
653   virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
654   virtual void EmitCFIRememberState();
655   virtual void EmitCFIRestoreState();
656   virtual void EmitCFISameValue(int64_t Register);
657   virtual void EmitCFIRestore(int64_t Register);
658   virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
659   virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
660   virtual void EmitCFIEscape(StringRef Values);
661   virtual void EmitCFISignalFrame();
662   virtual void EmitCFIUndefined(int64_t Register);
663   virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
664   virtual void EmitCFIWindowSave();
665
666   virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
667   virtual void EmitWinCFIEndProc();
668   virtual void EmitWinCFIStartChained();
669   virtual void EmitWinCFIEndChained();
670   virtual void EmitWinCFIPushReg(unsigned Register);
671   virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
672   virtual void EmitWinCFIAllocStack(unsigned Size);
673   virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
674   virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
675   virtual void EmitWinCFIPushFrame(bool Code);
676   virtual void EmitWinCFIEndProlog();
677
678   virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
679   virtual void EmitWinEHHandlerData();
680
681   /// \brief Emit the given \p Instruction into the current section.
682   virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
683
684   /// \brief Set the bundle alignment mode from now on in the section.
685   /// The argument is the power of 2 to which the alignment is set. The
686   /// value 0 means turn the bundle alignment off.
687   virtual void EmitBundleAlignMode(unsigned AlignPow2);
688
689   /// \brief The following instructions are a bundle-locked group.
690   ///
691   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
692   ///                     the end of a bundle.
693   virtual void EmitBundleLock(bool AlignToEnd);
694
695   /// \brief Ends a bundle-locked group.
696   virtual void EmitBundleUnlock();
697
698   /// \brief If this file is backed by a assembly streamer, this dumps the
699   /// specified string in the output .s file.  This capability is indicated by
700   /// the hasRawTextSupport() predicate.  By default this aborts.
701   void EmitRawText(const Twine &String);
702
703   /// \brief Causes any cached state to be written out.
704   virtual void Flush() {}
705
706   /// \brief Streamer specific finalization.
707   virtual void FinishImpl();
708   /// \brief Finish emission of machine code.
709   void Finish();
710
711   virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
712 };
713
714 /// Create a dummy machine code streamer, which does nothing. This is useful for
715 /// timing the assembler front end.
716 MCStreamer *createNullStreamer(MCContext &Ctx);
717
718 /// Create a machine code streamer which will print out assembly for the native
719 /// target, suitable for compiling with a native assembler.
720 ///
721 /// \param InstPrint - If given, the instruction printer to use. If not given
722 /// the MCInst representation will be printed.  This method takes ownership of
723 /// InstPrint.
724 ///
725 /// \param CE - If given, a code emitter to use to show the instruction
726 /// encoding inline with the assembly. This method takes ownership of \p CE.
727 ///
728 /// \param TAB - If given, a target asm backend to use to show the fixup
729 /// information in conjunction with encoding information. This method takes
730 /// ownership of \p TAB.
731 ///
732 /// \param ShowInst - Whether to show the MCInst representation inline with
733 /// the assembly.
734 MCStreamer *createAsmStreamer(MCContext &Ctx,
735                               std::unique_ptr<formatted_raw_ostream> OS,
736                               bool isVerboseAsm, bool useDwarfDirectory,
737                               MCInstPrinter *InstPrint, MCCodeEmitter *CE,
738                               MCAsmBackend *TAB, bool ShowInst);
739 } // end namespace llvm
740
741 #endif