LLVM API Documentation

MCStreamer.h
Go to the documentation of this file.
00001 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the MCStreamer class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_MC_MCSTREAMER_H
00015 #define LLVM_MC_MCSTREAMER_H
00016 
00017 #include "llvm/ADT/ArrayRef.h"
00018 #include "llvm/ADT/SmallVector.h"
00019 #include "llvm/MC/MCAssembler.h"
00020 #include "llvm/MC/MCDirectives.h"
00021 #include "llvm/MC/MCDwarf.h"
00022 #include "llvm/MC/MCWin64EH.h"
00023 #include "llvm/Support/DataTypes.h"
00024 #include <string>
00025 
00026 namespace llvm {
00027   class MCAsmBackend;
00028   class MCCodeEmitter;
00029   class MCContext;
00030   class MCExpr;
00031   class MCInst;
00032   class MCInstPrinter;
00033   class MCSection;
00034   class MCSymbol;
00035   class StringRef;
00036   class Twine;
00037   class raw_ostream;
00038   class formatted_raw_ostream;
00039 
00040   typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
00041 
00042   /// MCStreamer - Streaming machine code generation interface.  This interface
00043   /// is intended to provide a programatic interface that is very similar to the
00044   /// level that an assembler .s file provides.  It has callbacks to emit bytes,
00045   /// handle directives, etc.  The implementation of this interface retains
00046   /// state to know what the current section is etc.
00047   ///
00048   /// There are multiple implementations of this interface: one for writing out
00049   /// a .s file, and implementations that write out .o files of various formats.
00050   ///
00051   class MCStreamer {
00052   public:
00053     enum StreamerKind {
00054       SK_AsmStreamer,
00055       SK_NullStreamer,
00056       SK_RecordStreamer,
00057 
00058       // MCObjectStreamer subclasses.
00059       SK_ELFStreamer,
00060       SK_ARMELFStreamer,
00061       SK_MachOStreamer,
00062       SK_PureStreamer,
00063       SK_MipsELFStreamer,
00064       SK_WinCOFFStreamer
00065     };
00066 
00067   private:
00068     const StreamerKind Kind;
00069     MCContext &Context;
00070 
00071     MCStreamer(const MCStreamer&) LLVM_DELETED_FUNCTION;
00072     MCStreamer &operator=(const MCStreamer&) LLVM_DELETED_FUNCTION;
00073 
00074     bool EmitEHFrame;
00075     bool EmitDebugFrame;
00076 
00077     std::vector<MCDwarfFrameInfo> FrameInfos;
00078     MCDwarfFrameInfo *getCurrentFrameInfo();
00079     MCSymbol *EmitCFICommon();
00080     void EnsureValidFrame();
00081 
00082     std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
00083     MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
00084     void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
00085     void EnsureValidW64UnwindInfo();
00086 
00087     MCSymbol* LastSymbol;
00088 
00089     /// SectionStack - This is stack of current and previous section
00090     /// values saved by PushSection.
00091     SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
00092 
00093     bool AutoInitSections;
00094 
00095   protected:
00096     MCStreamer(StreamerKind Kind, MCContext &Ctx);
00097 
00098     const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
00099                                   const MCSymbol *B);
00100 
00101     const MCExpr *ForceExpAbs(const MCExpr* Expr);
00102 
00103     void RecordProcStart(MCDwarfFrameInfo &Frame);
00104     virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
00105     void RecordProcEnd(MCDwarfFrameInfo &Frame);
00106     virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
00107     void EmitFrames(bool usingCFI);
00108 
00109     MCWin64EHUnwindInfo *getCurrentW64UnwindInfo(){return CurrentW64UnwindInfo;}
00110     void EmitW64Tables();
00111 
00112   public:
00113     virtual ~MCStreamer();
00114 
00115     StreamerKind getKind() const { return Kind; }
00116 
00117     /// State management
00118     ///
00119     virtual void reset();
00120 
00121     MCContext &getContext() const { return Context; }
00122 
00123     unsigned getNumFrameInfos() {
00124       return FrameInfos.size();
00125     }
00126 
00127     const MCDwarfFrameInfo &getFrameInfo(unsigned i) {
00128       return FrameInfos[i];
00129     }
00130 
00131     ArrayRef<MCDwarfFrameInfo> getFrameInfos() {
00132       return FrameInfos;
00133     }
00134 
00135     unsigned getNumW64UnwindInfos() {
00136       return W64UnwindInfos.size();
00137     }
00138 
00139     MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
00140       return *W64UnwindInfos[i];
00141     }
00142 
00143     /// @name Assembly File Formatting.
00144     /// @{
00145 
00146     /// isVerboseAsm - Return true if this streamer supports verbose assembly
00147     /// and if it is enabled.
00148     virtual bool isVerboseAsm() const { return false; }
00149 
00150     /// hasRawTextSupport - Return true if this asm streamer supports emitting
00151     /// unformatted text to the .s file with EmitRawText.
00152     virtual bool hasRawTextSupport() const { return false; }
00153 
00154     /// AddComment - Add a comment that can be emitted to the generated .s
00155     /// file if applicable as a QoI issue to make the output of the compiler
00156     /// more readable.  This only affects the MCAsmStreamer, and only when
00157     /// verbose assembly output is enabled.
00158     ///
00159     /// If the comment includes embedded \n's, they will each get the comment
00160     /// prefix as appropriate.  The added comment should not end with a \n.
00161     virtual void AddComment(const Twine &T) {}
00162 
00163     /// GetCommentOS - Return a raw_ostream that comments can be written to.
00164     /// Unlike AddComment, you are required to terminate comments with \n if you
00165     /// use this method.
00166     virtual raw_ostream &GetCommentOS();
00167 
00168     /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
00169     virtual void AddBlankLine() {}
00170 
00171     /// @}
00172 
00173     /// @name Symbol & Section Management
00174     /// @{
00175 
00176     /// getCurrentSection - Return the current section that the streamer is
00177     /// emitting code to.
00178     MCSectionSubPair getCurrentSection() const {
00179       if (!SectionStack.empty())
00180         return SectionStack.back().first;
00181       return MCSectionSubPair();
00182     }
00183 
00184     /// getPreviousSection - Return the previous section that the streamer is
00185     /// emitting code to.
00186     MCSectionSubPair getPreviousSection() const {
00187       if (!SectionStack.empty())
00188         return SectionStack.back().second;
00189       return MCSectionSubPair();
00190     }
00191 
00192     /// ChangeSection - Update streamer for a new active section.
00193     ///
00194     /// This is called by PopSection and SwitchSection, if the current
00195     /// section changes.
00196     virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
00197 
00198     /// pushSection - Save the current and previous section on the
00199     /// section stack.
00200     void PushSection() {
00201       SectionStack.push_back(std::make_pair(getCurrentSection(),
00202                                             getPreviousSection()));
00203     }
00204 
00205     /// popSection - Restore the current and previous section from
00206     /// the section stack.  Calls ChangeSection as needed.
00207     ///
00208     /// Returns false if the stack was empty.
00209     bool PopSection() {
00210       if (SectionStack.size() <= 1)
00211         return false;
00212       MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
00213       MCSectionSubPair curSection = SectionStack.back().first;
00214 
00215       if (oldSection != curSection)
00216         ChangeSection(curSection.first, curSection.second);
00217       return true;
00218     }
00219 
00220     bool SubSection(const MCExpr *Subsection) {
00221       if (SectionStack.empty())
00222         return false;
00223 
00224       SwitchSection(SectionStack.back().first.first, Subsection);
00225       return true;
00226     }
00227 
00228     /// SwitchSection - Set the current section where code is being emitted to
00229     /// @p Section.  This is required to update CurSection.
00230     ///
00231     /// This corresponds to assembler directives like .section, .text, etc.
00232     void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
00233       assert(Section && "Cannot switch to a null section!");
00234       MCSectionSubPair curSection = SectionStack.back().first;
00235       SectionStack.back().second = curSection;
00236       if (MCSectionSubPair(Section, Subsection) != curSection) {
00237         SectionStack.back().first = MCSectionSubPair(Section, Subsection);
00238         ChangeSection(Section, Subsection);
00239       }
00240     }
00241 
00242     /// SwitchSectionNoChange - Set the current section where code is being
00243     /// emitted to @p Section.  This is required to update CurSection. This
00244     /// version does not call ChangeSection.
00245     void SwitchSectionNoChange(const MCSection *Section,
00246                                const MCExpr *Subsection = 0) {
00247       assert(Section && "Cannot switch to a null section!");
00248       MCSectionSubPair curSection = SectionStack.back().first;
00249       SectionStack.back().second = curSection;
00250       if (MCSectionSubPair(Section, Subsection) != curSection)
00251         SectionStack.back().first = MCSectionSubPair(Section, Subsection);
00252     }
00253 
00254     /// Initialize the streamer.
00255     void InitStreamer() {
00256       if (AutoInitSections)
00257         InitSections();
00258     }
00259 
00260     /// Tell this MCStreamer to call InitSections upon initialization.
00261     void setAutoInitSections(bool AutoInitSections) {
00262       this->AutoInitSections = AutoInitSections;
00263     }
00264 
00265     /// InitSections - Create the default sections and set the initial one.
00266     virtual void InitSections() = 0;
00267 
00268     /// InitToTextSection - Create a text section and switch the streamer to it.
00269     virtual void InitToTextSection() = 0;
00270 
00271     /// EmitLabel - Emit a label for @p Symbol into the current section.
00272     ///
00273     /// This corresponds to an assembler statement such as:
00274     ///   foo:
00275     ///
00276     /// @param Symbol - The symbol to emit. A given symbol should only be
00277     /// emitted as a label once, and symbols emitted as a label should never be
00278     /// used in an assignment.
00279     virtual void EmitLabel(MCSymbol *Symbol);
00280 
00281     virtual void EmitDebugLabel(MCSymbol *Symbol);
00282 
00283     virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
00284                                      MCSymbol *EHSymbol);
00285 
00286     /// EmitAssemblerFlag - Note in the output the specified @p Flag.
00287     virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
00288 
00289     /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
00290     /// options into the output.
00291     virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
00292 
00293     /// EmitDataRegion - Note in the output the specified region @p Kind.
00294     virtual void EmitDataRegion(MCDataRegionType Kind) {}
00295 
00296     /// EmitThumbFunc - Note in the output that the specified @p Func is
00297     /// a Thumb mode function (ARM target only).
00298     virtual void EmitThumbFunc(MCSymbol *Func) = 0;
00299 
00300     /// getOrCreateSymbolData - Get symbol data for given symbol.
00301     virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
00302 
00303     /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
00304     ///
00305     /// This corresponds to an assembler statement such as:
00306     ///  symbol = value
00307     ///
00308     /// The assignment generates no code, but has the side effect of binding the
00309     /// value in the current context. For the assembly streamer, this prints the
00310     /// binding into the .s file.
00311     ///
00312     /// @param Symbol - The symbol being assigned to.
00313     /// @param Value - The value for the symbol.
00314     virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
00315 
00316     /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
00317     ///
00318     /// This corresponds to an assembler statement such as:
00319     ///  .weakref alias, symbol
00320     ///
00321     /// @param Alias - The alias that is being created.
00322     /// @param Symbol - The symbol being aliased.
00323     virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
00324 
00325     /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
00326     virtual void EmitSymbolAttribute(MCSymbol *Symbol,
00327                                      MCSymbolAttr Attribute) = 0;
00328 
00329     /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
00330     ///
00331     /// @param Symbol - The symbol to have its n_desc field set.
00332     /// @param DescValue - The value to set into the n_desc field.
00333     virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
00334 
00335     /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
00336     ///
00337     /// @param Symbol - The symbol to have its External & Type fields set.
00338     virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
00339 
00340     /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
00341     ///
00342     /// @param StorageClass - The storage class the symbol should have.
00343     virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
00344 
00345     /// EmitCOFFSymbolType - Emit the type of the symbol.
00346     ///
00347     /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
00348     virtual void EmitCOFFSymbolType(int Type) = 0;
00349 
00350     /// EndCOFFSymbolDef - Marks the end of the symbol definition.
00351     virtual void EndCOFFSymbolDef() = 0;
00352 
00353     /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
00354     ///
00355     /// @param Symbol - Symbol the section relative realocation should point to.
00356     virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
00357 
00358     /// EmitELFSize - Emit an ELF .size directive.
00359     ///
00360     /// This corresponds to an assembler statement such as:
00361     ///  .size symbol, expression
00362     ///
00363     virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
00364 
00365     /// EmitCommonSymbol - Emit a common symbol.
00366     ///
00367     /// @param Symbol - The common symbol to emit.
00368     /// @param Size - The size of the common symbol.
00369     /// @param ByteAlignment - The alignment of the symbol if
00370     /// non-zero. This must be a power of 2.
00371     virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
00372                                   unsigned ByteAlignment) = 0;
00373 
00374     /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
00375     ///
00376     /// @param Symbol - The common symbol to emit.
00377     /// @param Size - The size of the common symbol.
00378     /// @param ByteAlignment - The alignment of the common symbol in bytes.
00379     virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
00380                                        unsigned ByteAlignment) = 0;
00381 
00382     /// EmitZerofill - Emit the zerofill section and an optional symbol.
00383     ///
00384     /// @param Section - The zerofill section to create and or to put the symbol
00385     /// @param Symbol - The zerofill symbol to emit, if non-NULL.
00386     /// @param Size - The size of the zerofill symbol.
00387     /// @param ByteAlignment - The alignment of the zerofill symbol if
00388     /// non-zero. This must be a power of 2 on some targets.
00389     virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
00390                               uint64_t Size = 0,unsigned ByteAlignment = 0) = 0;
00391 
00392     /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
00393     ///
00394     /// @param Section - The thread local common section.
00395     /// @param Symbol - The thread local common symbol to emit.
00396     /// @param Size - The size of the symbol.
00397     /// @param ByteAlignment - The alignment of the thread local common symbol
00398     /// if non-zero.  This must be a power of 2 on some targets.
00399     virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
00400                                 uint64_t Size, unsigned ByteAlignment = 0) = 0;
00401 
00402     /// @}
00403     /// @name Generating Data
00404     /// @{
00405 
00406     /// EmitBytes - Emit the bytes in \p Data into the output.
00407     ///
00408     /// This is used to implement assembler directives such as .byte, .ascii,
00409     /// etc.
00410     virtual void EmitBytes(StringRef Data, unsigned AddrSpace = 0) = 0;
00411 
00412     /// EmitValue - Emit the expression @p Value into the output as a native
00413     /// integer of the given @p Size bytes.
00414     ///
00415     /// This is used to implement assembler directives such as .word, .quad,
00416     /// etc.
00417     ///
00418     /// @param Value - The value to emit.
00419     /// @param Size - The size of the integer (in bytes) to emit. This must
00420     /// match a native machine width.
00421     virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
00422                                unsigned AddrSpace) = 0;
00423 
00424     void EmitValue(const MCExpr *Value, unsigned Size, unsigned AddrSpace = 0);
00425 
00426     /// EmitIntValue - Special case of EmitValue that avoids the client having
00427     /// to pass in a MCExpr for constant integers.
00428     virtual void EmitIntValue(uint64_t Value, unsigned Size,
00429                               unsigned AddrSpace = 0);
00430 
00431     /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
00432     /// this is done by producing
00433     /// foo = value
00434     /// .long foo
00435     void EmitAbsValue(const MCExpr *Value, unsigned Size,
00436                       unsigned AddrSpace = 0);
00437 
00438     virtual void EmitULEB128Value(const MCExpr *Value) = 0;
00439 
00440     virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
00441 
00442     /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
00443     /// client having to pass in a MCExpr for constant integers.
00444     void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0,
00445                              unsigned AddrSpace = 0);
00446 
00447     /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
00448     /// client having to pass in a MCExpr for constant integers.
00449     void EmitSLEB128IntValue(int64_t Value, unsigned AddrSpace = 0);
00450 
00451     /// EmitSymbolValue - Special case of EmitValue that avoids the client
00452     /// having to pass in a MCExpr for MCSymbols.
00453     void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
00454                          unsigned AddrSpace = 0);
00455 
00456     /// EmitGPRel64Value - Emit the expression @p Value into the output as a
00457     /// gprel64 (64-bit GP relative) value.
00458     ///
00459     /// This is used to implement assembler directives such as .gpdword on
00460     /// targets that support them.
00461     virtual void EmitGPRel64Value(const MCExpr *Value);
00462 
00463     /// EmitGPRel32Value - Emit the expression @p Value into the output as a
00464     /// gprel32 (32-bit GP relative) value.
00465     ///
00466     /// This is used to implement assembler directives such as .gprel32 on
00467     /// targets that support them.
00468     virtual void EmitGPRel32Value(const MCExpr *Value);
00469 
00470     /// EmitFill - Emit NumBytes bytes worth of the value specified by
00471     /// FillValue.  This implements directives such as '.space'.
00472     virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
00473                           unsigned AddrSpace = 0);
00474 
00475     /// EmitZeros - Emit NumBytes worth of zeros.  This is a convenience
00476     /// function that just wraps EmitFill.
00477     void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0) {
00478       EmitFill(NumBytes, 0, AddrSpace);
00479     }
00480 
00481     /// EmitValueToAlignment - Emit some number of copies of @p Value until
00482     /// the byte alignment @p ByteAlignment is reached.
00483     ///
00484     /// If the number of bytes need to emit for the alignment is not a multiple
00485     /// of @p ValueSize, then the contents of the emitted fill bytes is
00486     /// undefined.
00487     ///
00488     /// This used to implement the .align assembler directive.
00489     ///
00490     /// @param ByteAlignment - The alignment to reach. This must be a power of
00491     /// two on some targets.
00492     /// @param Value - The value to use when filling bytes.
00493     /// @param ValueSize - The size of the integer (in bytes) to emit for
00494     /// @p Value. This must match a native machine width.
00495     /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
00496     /// the alignment cannot be reached in this many bytes, no bytes are
00497     /// emitted.
00498     virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
00499                                       unsigned ValueSize = 1,
00500                                       unsigned MaxBytesToEmit = 0) = 0;
00501 
00502     /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
00503     /// is reached.
00504     ///
00505     /// This used to align code where the alignment bytes may be executed.  This
00506     /// can emit different bytes for different sizes to optimize execution.
00507     ///
00508     /// @param ByteAlignment - The alignment to reach. This must be a power of
00509     /// two on some targets.
00510     /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
00511     /// the alignment cannot be reached in this many bytes, no bytes are
00512     /// emitted.
00513     virtual void EmitCodeAlignment(unsigned ByteAlignment,
00514                                    unsigned MaxBytesToEmit = 0) = 0;
00515 
00516     /// EmitValueToOffset - Emit some number of copies of @p Value until the
00517     /// byte offset @p Offset is reached.
00518     ///
00519     /// This is used to implement assembler directives such as .org.
00520     ///
00521     /// @param Offset - The offset to reach. This may be an expression, but the
00522     /// expression must be associated with the current section.
00523     /// @param Value - The value to use when filling bytes.
00524     /// @return false on success, true if the offset was invalid.
00525     virtual bool EmitValueToOffset(const MCExpr *Offset,
00526                                    unsigned char Value = 0) = 0;
00527 
00528     /// @}
00529 
00530     /// EmitFileDirective - Switch to a new logical file.  This is used to
00531     /// implement the '.file "foo.c"' assembler directive.
00532     virtual void EmitFileDirective(StringRef Filename) = 0;
00533 
00534     /// EmitDwarfFileDirective - Associate a filename with a specified logical
00535     /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
00536     /// directive.
00537     virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
00538                                         StringRef Filename, unsigned CUID = 0);
00539 
00540     /// EmitDwarfLocDirective - This implements the DWARF2
00541     // '.loc fileno lineno ...' assembler directive.
00542     virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
00543                                        unsigned Column, unsigned Flags,
00544                                        unsigned Isa,
00545                                        unsigned Discriminator,
00546                                        StringRef FileName);
00547 
00548     virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
00549                                           const MCSymbol *LastLabel,
00550                                           const MCSymbol *Label,
00551                                           unsigned PointerSize) = 0;
00552 
00553     virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
00554                                            const MCSymbol *Label) {
00555     }
00556 
00557     void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
00558                               int PointerSize);
00559 
00560     virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
00561     virtual void EmitCFISections(bool EH, bool Debug);
00562     void EmitCFIStartProc();
00563     void EmitCFIEndProc();
00564     virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
00565     virtual void EmitCFIDefCfaOffset(int64_t Offset);
00566     virtual void EmitCFIDefCfaRegister(int64_t Register);
00567     virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
00568     virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
00569     virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
00570     virtual void EmitCFIRememberState();
00571     virtual void EmitCFIRestoreState();
00572     virtual void EmitCFISameValue(int64_t Register);
00573     virtual void EmitCFIRestore(int64_t Register);
00574     virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
00575     virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
00576     virtual void EmitCFIEscape(StringRef Values);
00577     virtual void EmitCFISignalFrame();
00578     virtual void EmitCFIUndefined(int64_t Register);
00579     virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
00580 
00581     virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
00582     virtual void EmitWin64EHEndProc();
00583     virtual void EmitWin64EHStartChained();
00584     virtual void EmitWin64EHEndChained();
00585     virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
00586                                     bool Except);
00587     virtual void EmitWin64EHHandlerData();
00588     virtual void EmitWin64EHPushReg(unsigned Register);
00589     virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
00590     virtual void EmitWin64EHAllocStack(unsigned Size);
00591     virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
00592     virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
00593     virtual void EmitWin64EHPushFrame(bool Code);
00594     virtual void EmitWin64EHEndProlog();
00595 
00596     /// EmitInstruction - Emit the given @p Instruction into the current
00597     /// section.
00598     virtual void EmitInstruction(const MCInst &Inst) = 0;
00599 
00600     /// \brief Set the bundle alignment mode from now on in the section.
00601     /// The argument is the power of 2 to which the alignment is set. The
00602     /// value 0 means turn the bundle alignment off.
00603     virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
00604 
00605     /// \brief The following instructions are a bundle-locked group.
00606     ///
00607     /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
00608     ///                     the end of a bundle.
00609     virtual void EmitBundleLock(bool AlignToEnd) = 0;
00610 
00611     /// \brief Ends a bundle-locked group.
00612     virtual void EmitBundleUnlock() = 0;
00613 
00614     /// EmitRawText - If this file is backed by a assembly streamer, this dumps
00615     /// the specified string in the output .s file.  This capability is
00616     /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
00617     virtual void EmitRawText(StringRef String);
00618     void EmitRawText(const Twine &String);
00619 
00620     /// ARM-related methods.
00621     /// FIXME: Eventually we should have some "target MC streamer" and move
00622     /// these methods there.
00623     virtual void EmitFnStart();
00624     virtual void EmitFnEnd();
00625     virtual void EmitCantUnwind();
00626     virtual void EmitPersonality(const MCSymbol *Personality);
00627     virtual void EmitHandlerData();
00628     virtual void EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
00629     virtual void EmitPad(int64_t Offset);
00630     virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList,
00631                              bool isVector);
00632 
00633     /// PPC-related methods.
00634     /// FIXME: Eventually replace it with some "target MC streamer" and move
00635     /// these methods there.
00636     virtual void EmitTCEntry(const MCSymbol &S);
00637 
00638     /// FinishImpl - Streamer specific finalization.
00639     virtual void FinishImpl() = 0;
00640     /// Finish - Finish emission of machine code.
00641     void Finish();
00642   };
00643 
00644   /// createNullStreamer - Create a dummy machine code streamer, which does
00645   /// nothing. This is useful for timing the assembler front end.
00646   MCStreamer *createNullStreamer(MCContext &Ctx);
00647 
00648   /// createAsmStreamer - Create a machine code streamer which will print out
00649   /// assembly for the native target, suitable for compiling with a native
00650   /// assembler.
00651   ///
00652   /// \param InstPrint - If given, the instruction printer to use. If not given
00653   /// the MCInst representation will be printed.  This method takes ownership of
00654   /// InstPrint.
00655   ///
00656   /// \param CE - If given, a code emitter to use to show the instruction
00657   /// encoding inline with the assembly. This method takes ownership of \p CE.
00658   ///
00659   /// \param TAB - If given, a target asm backend to use to show the fixup
00660   /// information in conjunction with encoding information. This method takes
00661   /// ownership of \p TAB.
00662   ///
00663   /// \param ShowInst - Whether to show the MCInst representation inline with
00664   /// the assembly.
00665   MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
00666                                 bool isVerboseAsm,
00667                                 bool useLoc,
00668                                 bool useCFI,
00669                                 bool useDwarfDirectory,
00670                                 MCInstPrinter *InstPrint = 0,
00671                                 MCCodeEmitter *CE = 0,
00672                                 MCAsmBackend *TAB = 0,
00673                                 bool ShowInst = false);
00674 
00675   /// createMachOStreamer - Create a machine code streamer which will generate
00676   /// Mach-O format object files.
00677   ///
00678   /// Takes ownership of \p TAB and \p CE.
00679   MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
00680                                   raw_ostream &OS, MCCodeEmitter *CE,
00681                                   bool RelaxAll = false);
00682 
00683   /// createWinCOFFStreamer - Create a machine code streamer which will
00684   /// generate Microsoft COFF format object files.
00685   ///
00686   /// Takes ownership of \p TAB and \p CE.
00687   MCStreamer *createWinCOFFStreamer(MCContext &Ctx,
00688                                     MCAsmBackend &TAB,
00689                                     MCCodeEmitter &CE, raw_ostream &OS,
00690                                     bool RelaxAll = false);
00691 
00692   /// createELFStreamer - Create a machine code streamer which will generate
00693   /// ELF format object files.
00694   MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
00695                                 raw_ostream &OS, MCCodeEmitter *CE,
00696                                 bool RelaxAll, bool NoExecStack);
00697 
00698   /// createPureStreamer - Create a machine code streamer which will generate
00699   /// "pure" MC object files, for use with MC-JIT and testing tools.
00700   ///
00701   /// Takes ownership of \p TAB and \p CE.
00702   MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
00703                                  raw_ostream &OS, MCCodeEmitter *CE);
00704 
00705 } // end namespace llvm
00706 
00707 #endif