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