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