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