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