3cd5c773c1a40f97495c442ec2664cd87d2a94f3
[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/MCWin64EH.h"
23 #include "llvm/Support/DataTypes.h"
24 #include <string>
25
26 namespace llvm {
27 class MCAsmBackend;
28 class MCCodeEmitter;
29 class MCContext;
30 class MCExpr;
31 class MCInst;
32 class MCInstPrinter;
33 class MCSection;
34 class MCSymbol;
35 class StringRef;
36 class Twine;
37 class raw_ostream;
38 class formatted_raw_ostream;
39
40 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
41
42 /// MCStreamer - Streaming machine code generation interface.  This interface
43 /// is intended to provide a programatic interface that is very similar to the
44 /// level that an assembler .s file provides.  It has callbacks to emit bytes,
45 /// handle directives, etc.  The implementation of this interface retains
46 /// state to know what the current section is etc.
47 ///
48 /// There are multiple implementations of this interface: one for writing out
49 /// a .s file, and implementations that write out .o files of various formats.
50 ///
51 class MCStreamer {
52   MCContext &Context;
53
54   MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
55   MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
56
57   bool EmitEHFrame;
58   bool EmitDebugFrame;
59
60   std::vector<MCDwarfFrameInfo> FrameInfos;
61   MCDwarfFrameInfo *getCurrentFrameInfo();
62   MCSymbol *EmitCFICommon();
63   void EnsureValidFrame();
64
65   std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
66   MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
67   void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
68   void EnsureValidW64UnwindInfo();
69
70   MCSymbol *LastSymbol;
71
72   // SymbolOrdering - Tracks an index to represent the order
73   // a symbol was emitted in. Zero means we did not emit that symbol.
74   DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
75
76   /// SectionStack - This is stack of current and previous section
77   /// values saved by PushSection.
78   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
79
80   bool AutoInitSections;
81
82 protected:
83   MCStreamer(MCContext &Ctx);
84
85   const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
86                                 const MCSymbol *B);
87
88   const MCExpr *ForceExpAbs(const MCExpr *Expr);
89
90   void RecordProcStart(MCDwarfFrameInfo &Frame);
91   virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
92   void RecordProcEnd(MCDwarfFrameInfo &Frame);
93   virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
94   void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
95
96   MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
97     return CurrentW64UnwindInfo;
98   }
99   void EmitW64Tables();
100
101 public:
102   virtual ~MCStreamer();
103
104   /// State management
105   ///
106   virtual void reset();
107
108   MCContext &getContext() const { return Context; }
109
110   unsigned getNumFrameInfos() { return FrameInfos.size(); }
111
112   const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
113
114   ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
115
116   unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
117
118   MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
119     return *W64UnwindInfos[i];
120   }
121
122   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
123
124   /// @name Assembly File Formatting.
125   /// @{
126
127   /// isVerboseAsm - Return true if this streamer supports verbose assembly
128   /// and if it is enabled.
129   virtual bool isVerboseAsm() const { return false; }
130
131   /// hasRawTextSupport - Return true if this asm streamer supports emitting
132   /// unformatted text to the .s file with EmitRawText.
133   virtual bool hasRawTextSupport() const { return false; }
134
135   /// AddComment - Add a comment that can be emitted to the generated .s
136   /// file if applicable as a QoI issue to make the output of the compiler
137   /// more readable.  This only affects the MCAsmStreamer, and only when
138   /// verbose assembly output is enabled.
139   ///
140   /// If the comment includes embedded \n's, they will each get the comment
141   /// prefix as appropriate.  The added comment should not end with a \n.
142   virtual void AddComment(const Twine &T) {}
143
144   /// GetCommentOS - Return a raw_ostream that comments can be written to.
145   /// Unlike AddComment, you are required to terminate comments with \n if you
146   /// use this method.
147   virtual raw_ostream &GetCommentOS();
148
149   /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
150   virtual void AddBlankLine() {}
151
152   /// @}
153
154   /// @name Symbol & Section Management
155   /// @{
156
157   /// getCurrentSection - Return the current section that the streamer is
158   /// emitting code to.
159   MCSectionSubPair getCurrentSection() const {
160     if (!SectionStack.empty())
161       return SectionStack.back().first;
162     return MCSectionSubPair();
163   }
164
165   /// getPreviousSection - Return the previous section that the streamer is
166   /// emitting code to.
167   MCSectionSubPair getPreviousSection() const {
168     if (!SectionStack.empty())
169       return SectionStack.back().second;
170     return MCSectionSubPair();
171   }
172
173   /// GetSymbolOrder - Returns an index to represent the order
174   /// a symbol was emitted in. (zero if we did not emit that symbol)
175   unsigned GetSymbolOrder(const MCSymbol *Sym) const {
176     return SymbolOrdering.lookup(Sym);
177   }
178
179   /// ChangeSection - Update streamer for a new active section.
180   ///
181   /// This is called by PopSection and SwitchSection, if the current
182   /// section changes.
183   virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
184
185   /// pushSection - Save the current and previous section on the
186   /// section stack.
187   void PushSection() {
188     SectionStack.push_back(
189         std::make_pair(getCurrentSection(), getPreviousSection()));
190   }
191
192   /// popSection - Restore the current and previous section from
193   /// the section stack.  Calls ChangeSection as needed.
194   ///
195   /// Returns false if the stack was empty.
196   bool PopSection() {
197     if (SectionStack.size() <= 1)
198       return false;
199     MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
200     MCSectionSubPair curSection = SectionStack.back().first;
201
202     if (oldSection != curSection)
203       ChangeSection(curSection.first, curSection.second);
204     return true;
205   }
206
207   bool SubSection(const MCExpr *Subsection) {
208     if (SectionStack.empty())
209       return false;
210
211     SwitchSection(SectionStack.back().first.first, Subsection);
212     return true;
213   }
214
215   /// SwitchSection - Set the current section where code is being emitted to
216   /// @p Section.  This is required to update CurSection.
217   ///
218   /// This corresponds to assembler directives like .section, .text, etc.
219   void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
220     assert(Section && "Cannot switch to a null section!");
221     MCSectionSubPair curSection = SectionStack.back().first;
222     SectionStack.back().second = curSection;
223     if (MCSectionSubPair(Section, Subsection) != curSection) {
224       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
225       ChangeSection(Section, Subsection);
226     }
227   }
228
229   /// SwitchSectionNoChange - Set the current section where code is being
230   /// emitted to @p Section.  This is required to update CurSection. This
231   /// version does not call ChangeSection.
232   void SwitchSectionNoChange(const MCSection *Section,
233                              const MCExpr *Subsection = 0) {
234     assert(Section && "Cannot switch to a null section!");
235     MCSectionSubPair curSection = SectionStack.back().first;
236     SectionStack.back().second = curSection;
237     if (MCSectionSubPair(Section, Subsection) != curSection)
238       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
239   }
240
241   /// Initialize the streamer.
242   void InitStreamer() {
243     if (AutoInitSections)
244       InitSections();
245   }
246
247   /// Tell this MCStreamer to call InitSections upon initialization.
248   void setAutoInitSections(bool AutoInitSections) {
249     this->AutoInitSections = AutoInitSections;
250   }
251
252   /// InitSections - Create the default sections and set the initial one.
253   virtual void InitSections() = 0;
254
255   /// InitToTextSection - Create a text section and switch the streamer to it.
256   virtual void InitToTextSection() = 0;
257
258   /// AssignSection - Sets the symbol's section.
259   ///
260   /// Each emitted symbol will be tracked in the ordering table,
261   /// so we can sort on them later.
262   void AssignSection(MCSymbol *Symbol, const MCSection *Section);
263
264   /// EmitLabel - Emit a label for @p Symbol into the current section.
265   ///
266   /// This corresponds to an assembler statement such as:
267   ///   foo:
268   ///
269   /// @param Symbol - The symbol to emit. A given symbol should only be
270   /// emitted as a label once, and symbols emitted as a label should never be
271   /// used in an assignment.
272   virtual void EmitLabel(MCSymbol *Symbol);
273
274   virtual void EmitDebugLabel(MCSymbol *Symbol);
275
276   virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
277
278   /// EmitAssemblerFlag - Note in the output the specified @p Flag.
279   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
280
281   /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
282   /// options into the output.
283   virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
284
285   /// EmitDataRegion - Note in the output the specified region @p Kind.
286   virtual void EmitDataRegion(MCDataRegionType Kind) {}
287
288   /// EmitThumbFunc - Note in the output that the specified @p Func is
289   /// a Thumb mode function (ARM target only).
290   virtual void EmitThumbFunc(MCSymbol *Func) = 0;
291
292   /// getOrCreateSymbolData - Get symbol data for given symbol.
293   virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
294
295   /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
296   ///
297   /// This corresponds to an assembler statement such as:
298   ///  symbol = value
299   ///
300   /// The assignment generates no code, but has the side effect of binding the
301   /// value in the current context. For the assembly streamer, this prints the
302   /// binding into the .s file.
303   ///
304   /// @param Symbol - The symbol being assigned to.
305   /// @param Value - The value for the symbol.
306   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
307
308   /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
309   ///
310   /// This corresponds to an assembler statement such as:
311   ///  .weakref alias, symbol
312   ///
313   /// @param Alias - The alias that is being created.
314   /// @param Symbol - The symbol being aliased.
315   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
316
317   /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
318   virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
319                                    MCSymbolAttr Attribute) = 0;
320
321   /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
322   ///
323   /// @param Symbol - The symbol to have its n_desc field set.
324   /// @param DescValue - The value to set into the n_desc field.
325   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
326
327   /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
328   ///
329   /// @param Symbol - The symbol to have its External & Type fields set.
330   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
331
332   /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
333   ///
334   /// @param StorageClass - The storage class the symbol should have.
335   virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
336
337   /// EmitCOFFSymbolType - Emit the type of the symbol.
338   ///
339   /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
340   virtual void EmitCOFFSymbolType(int Type) = 0;
341
342   /// EndCOFFSymbolDef - Marks the end of the symbol definition.
343   virtual void EndCOFFSymbolDef() = 0;
344
345   /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
346   ///
347   /// @param Symbol - Symbol the section relative realocation should point to.
348   virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
349
350   /// EmitELFSize - Emit an ELF .size directive.
351   ///
352   /// This corresponds to an assembler statement such as:
353   ///  .size symbol, expression
354   ///
355   virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
356
357   /// EmitCommonSymbol - Emit a common symbol.
358   ///
359   /// @param Symbol - The common symbol to emit.
360   /// @param Size - The size of the common symbol.
361   /// @param ByteAlignment - The alignment of the symbol if
362   /// non-zero. This must be a power of 2.
363   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
364                                 unsigned ByteAlignment) = 0;
365
366   /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
367   ///
368   /// @param Symbol - The common symbol to emit.
369   /// @param Size - The size of the common symbol.
370   /// @param ByteAlignment - The alignment of the common symbol in bytes.
371   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
372                                      unsigned ByteAlignment) = 0;
373
374   /// EmitZerofill - Emit the zerofill section and an optional symbol.
375   ///
376   /// @param Section - The zerofill section to create and or to put the symbol
377   /// @param Symbol - The zerofill symbol to emit, if non-NULL.
378   /// @param Size - The size of the zerofill symbol.
379   /// @param ByteAlignment - The alignment of the zerofill symbol if
380   /// non-zero. This must be a power of 2 on some targets.
381   virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
382                             uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
383
384   /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
385   ///
386   /// @param Section - The thread local common section.
387   /// @param Symbol - The thread local common symbol to emit.
388   /// @param Size - The size of the symbol.
389   /// @param ByteAlignment - The alignment of the thread local common symbol
390   /// if non-zero.  This must be a power of 2 on some targets.
391   virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
392                               uint64_t Size, unsigned ByteAlignment = 0) = 0;
393
394   /// @}
395   /// @name Generating Data
396   /// @{
397
398   /// EmitBytes - Emit the bytes in \p Data into the output.
399   ///
400   /// This is used to implement assembler directives such as .byte, .ascii,
401   /// etc.
402   virtual void EmitBytes(StringRef Data) = 0;
403
404   /// EmitValue - Emit the expression @p Value into the output as a native
405   /// integer of the given @p Size bytes.
406   ///
407   /// This is used to implement assembler directives such as .word, .quad,
408   /// etc.
409   ///
410   /// @param Value - The value to emit.
411   /// @param Size - The size of the integer (in bytes) to emit. This must
412   /// match a native machine width.
413   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
414
415   void EmitValue(const MCExpr *Value, unsigned Size);
416
417   /// EmitIntValue - Special case of EmitValue that avoids the client having
418   /// to pass in a MCExpr for constant integers.
419   virtual void EmitIntValue(uint64_t Value, unsigned Size);
420
421   /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
422   /// this is done by producing
423   /// foo = value
424   /// .long foo
425   void EmitAbsValue(const MCExpr *Value, unsigned Size);
426
427   virtual void EmitULEB128Value(const MCExpr *Value) = 0;
428
429   virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
430
431   /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
432   /// client having to pass in a MCExpr for constant integers.
433   void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
434
435   /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
436   /// client having to pass in a MCExpr for constant integers.
437   void EmitSLEB128IntValue(int64_t Value);
438
439   /// EmitSymbolValue - Special case of EmitValue that avoids the client
440   /// having to pass in a MCExpr for MCSymbols.
441   void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
442
443   /// EmitGPRel64Value - Emit the expression @p Value into the output as a
444   /// gprel64 (64-bit GP relative) value.
445   ///
446   /// This is used to implement assembler directives such as .gpdword on
447   /// targets that support them.
448   virtual void EmitGPRel64Value(const MCExpr *Value);
449
450   /// EmitGPRel32Value - Emit the expression @p Value into the output as a
451   /// gprel32 (32-bit GP relative) value.
452   ///
453   /// This is used to implement assembler directives such as .gprel32 on
454   /// targets that support them.
455   virtual void EmitGPRel32Value(const MCExpr *Value);
456
457   /// EmitFill - Emit NumBytes bytes worth of the value specified by
458   /// FillValue.  This implements directives such as '.space'.
459   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
460
461   /// \brief Emit NumBytes worth of zeros.
462   /// This function properly handles data in virtual sections.
463   virtual void EmitZeros(uint64_t NumBytes);
464
465   /// EmitValueToAlignment - Emit some number of copies of @p Value until
466   /// the byte alignment @p ByteAlignment is reached.
467   ///
468   /// If the number of bytes need to emit for the alignment is not a multiple
469   /// of @p ValueSize, then the contents of the emitted fill bytes is
470   /// undefined.
471   ///
472   /// This used to implement the .align assembler directive.
473   ///
474   /// @param ByteAlignment - The alignment to reach. This must be a power of
475   /// two on some targets.
476   /// @param Value - The value to use when filling bytes.
477   /// @param ValueSize - The size of the integer (in bytes) to emit for
478   /// @p Value. This must match a native machine width.
479   /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
480   /// the alignment cannot be reached in this many bytes, no bytes are
481   /// emitted.
482   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
483                                     unsigned ValueSize = 1,
484                                     unsigned MaxBytesToEmit = 0) = 0;
485
486   /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
487   /// is reached.
488   ///
489   /// This used to align code where the alignment bytes may be executed.  This
490   /// can emit different bytes for different sizes to optimize execution.
491   ///
492   /// @param ByteAlignment - The alignment to reach. This must be a power of
493   /// two on some targets.
494   /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
495   /// the alignment cannot be reached in this many bytes, no bytes are
496   /// emitted.
497   virtual void EmitCodeAlignment(unsigned ByteAlignment,
498                                  unsigned MaxBytesToEmit = 0) = 0;
499
500   /// EmitValueToOffset - Emit some number of copies of @p Value until the
501   /// byte offset @p Offset is reached.
502   ///
503   /// This is used to implement assembler directives such as .org.
504   ///
505   /// @param Offset - The offset to reach. This may be an expression, but the
506   /// expression must be associated with the current section.
507   /// @param Value - The value to use when filling bytes.
508   /// @return false on success, true if the offset was invalid.
509   virtual bool EmitValueToOffset(const MCExpr *Offset,
510                                  unsigned char Value = 0) = 0;
511
512   /// @}
513
514   /// EmitFileDirective - Switch to a new logical file.  This is used to
515   /// implement the '.file "foo.c"' assembler directive.
516   virtual void EmitFileDirective(StringRef Filename) = 0;
517
518   /// EmitDwarfFileDirective - Associate a filename with a specified logical
519   /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
520   /// directive.
521   virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
522                                       StringRef Filename, unsigned CUID = 0);
523
524   /// EmitDwarfLocDirective - This implements the DWARF2
525   // '.loc fileno lineno ...' assembler directive.
526   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
527                                      unsigned Column, unsigned Flags,
528                                      unsigned Isa, unsigned Discriminator,
529                                      StringRef FileName);
530
531   virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
532                                         const MCSymbol *LastLabel,
533                                         const MCSymbol *Label,
534                                         unsigned PointerSize) = 0;
535
536   virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
537                                          const MCSymbol *Label) {}
538
539   void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
540                             int PointerSize);
541
542   virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
543   virtual void EmitCFISections(bool EH, bool Debug);
544   void EmitCFIStartProc();
545   void EmitCFIEndProc();
546   virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
547   virtual void EmitCFIDefCfaOffset(int64_t Offset);
548   virtual void EmitCFIDefCfaRegister(int64_t Register);
549   virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
550   virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
551   virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
552   virtual void EmitCFIRememberState();
553   virtual void EmitCFIRestoreState();
554   virtual void EmitCFISameValue(int64_t Register);
555   virtual void EmitCFIRestore(int64_t Register);
556   virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
557   virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
558   virtual void EmitCFIEscape(StringRef Values);
559   virtual void EmitCFISignalFrame();
560   virtual void EmitCFIUndefined(int64_t Register);
561   virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
562   virtual void EmitCFIWindowSave();
563
564   virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
565   virtual void EmitWin64EHEndProc();
566   virtual void EmitWin64EHStartChained();
567   virtual void EmitWin64EHEndChained();
568   virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
569                                   bool Except);
570   virtual void EmitWin64EHHandlerData();
571   virtual void EmitWin64EHPushReg(unsigned Register);
572   virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
573   virtual void EmitWin64EHAllocStack(unsigned Size);
574   virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
575   virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
576   virtual void EmitWin64EHPushFrame(bool Code);
577   virtual void EmitWin64EHEndProlog();
578
579   /// EmitInstruction - Emit the given @p Instruction into the current
580   /// section.
581   virtual void EmitInstruction(const MCInst &Inst) = 0;
582
583   /// \brief Set the bundle alignment mode from now on in the section.
584   /// The argument is the power of 2 to which the alignment is set. The
585   /// value 0 means turn the bundle alignment off.
586   virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
587
588   /// \brief The following instructions are a bundle-locked group.
589   ///
590   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
591   ///                     the end of a bundle.
592   virtual void EmitBundleLock(bool AlignToEnd) = 0;
593
594   /// \brief Ends a bundle-locked group.
595   virtual void EmitBundleUnlock() = 0;
596
597   /// EmitRawText - If this file is backed by a assembly streamer, this dumps
598   /// the specified string in the output .s file.  This capability is
599   /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
600   virtual void EmitRawText(StringRef String);
601   void EmitRawText(const Twine &String);
602
603   /// ARM-related methods.
604   /// FIXME: Eventually we should have some "target MC streamer" and move
605   /// these methods there.
606   virtual void EmitFnStart();
607   virtual void EmitFnEnd();
608   virtual void EmitCantUnwind();
609   virtual void EmitPersonality(const MCSymbol *Personality);
610   virtual void EmitHandlerData();
611   virtual void EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
612   virtual void EmitPad(int64_t Offset);
613   virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList,
614                            bool isVector);
615
616   /// Mips-related methods.
617   virtual void emitMipsHackELFFlags(unsigned Flags);
618   virtual void emitMipsHackSTOCG(MCSymbol *Sym, unsigned Val);
619
620   /// PPC-related methods.
621   /// FIXME: Eventually replace it with some "target MC streamer" and move
622   /// these methods there.
623   virtual void EmitTCEntry(const MCSymbol &S);
624
625   /// Flush - Causes any cached state to be written out.
626   virtual void Flush() {}
627
628   /// FinishImpl - Streamer specific finalization.
629   virtual void FinishImpl() = 0;
630   /// Finish - Finish emission of machine code.
631   void Finish();
632 };
633
634 /// createNullStreamer - Create a dummy machine code streamer, which does
635 /// nothing. This is useful for timing the assembler front end.
636 MCStreamer *createNullStreamer(MCContext &Ctx);
637
638 /// createAsmStreamer - Create a machine code streamer which will print out
639 /// assembly for the native target, suitable for compiling with a native
640 /// assembler.
641 ///
642 /// \param InstPrint - If given, the instruction printer to use. If not given
643 /// the MCInst representation will be printed.  This method takes ownership of
644 /// InstPrint.
645 ///
646 /// \param CE - If given, a code emitter to use to show the instruction
647 /// encoding inline with the assembly. This method takes ownership of \p CE.
648 ///
649 /// \param TAB - If given, a target asm backend to use to show the fixup
650 /// information in conjunction with encoding information. This method takes
651 /// ownership of \p TAB.
652 ///
653 /// \param ShowInst - Whether to show the MCInst representation inline with
654 /// the assembly.
655 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
656                               bool isVerboseAsm, bool useLoc, bool useCFI,
657                               bool useDwarfDirectory,
658                               MCInstPrinter *InstPrint = 0,
659                               MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
660                               bool ShowInst = false);
661
662 /// createMachOStreamer - Create a machine code streamer which will generate
663 /// Mach-O format object files.
664 ///
665 /// Takes ownership of \p TAB and \p CE.
666 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
667                                 raw_ostream &OS, MCCodeEmitter *CE,
668                                 bool RelaxAll = false);
669
670 /// createWinCOFFStreamer - Create a machine code streamer which will
671 /// generate Microsoft COFF format object files.
672 ///
673 /// Takes ownership of \p TAB and \p CE.
674 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
675                                   MCCodeEmitter &CE, raw_ostream &OS,
676                                   bool RelaxAll = false);
677
678 /// createELFStreamer - Create a machine code streamer which will generate
679 /// ELF format object files.
680 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
681                               raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
682                               bool NoExecStack);
683
684 /// createPureStreamer - Create a machine code streamer which will generate
685 /// "pure" MC object files, for use with MC-JIT and testing tools.
686 ///
687 /// Takes ownership of \p TAB and \p CE.
688 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
689                                raw_ostream &OS, MCCodeEmitter *CE);
690
691 } // end namespace llvm
692
693 #endif