MCStreamer.h revision df39be6cb4eb44011db3d3e86f8fe463f81ce127
125e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar//===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
225e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar//
325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar//                     The LLVM Compiler Infrastructure
425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar//
525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar// This file is distributed under the University of Illinois Open Source
625e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar// License. See LICENSE.TXT for details.
725e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar//
825e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar//===----------------------------------------------------------------------===//
9e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner//
10e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner// This file declares the MCStreamer class.
11e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner//
12e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner//===----------------------------------------------------------------------===//
1325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
1425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar#ifndef LLVM_MC_MCSTREAMER_H
1525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar#define LLVM_MC_MCSTREAMER_H
1625e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
17255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/ADT/ArrayRef.h"
18255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/ADT/SmallVector.h"
1977afbdce53aa740777486b0cc4e9df151ae65468Jack Carter#include "llvm/MC/MCAssembler.h"
20a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner#include "llvm/MC/MCDirectives.h"
2189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola#include "llvm/MC/MCDwarf.h"
220855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis#include "llvm/MC/MCWin64EH.h"
23255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/Support/DataTypes.h"
24cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar#include <string>
2584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
2625e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbarnamespace llvm {
2778c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Cheng  class MCAsmBackend;
284a0abd80f18f9c2a10bf5b14cd6731d51972a426Daniel Dunbar  class MCCodeEmitter;
2925e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCContext;
30821e3334ed3390d931f497300e6a5f1dc21bcfb3Daniel Dunbar  class MCExpr;
3125e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCInst;
3290edac0e8b35f766599362b6301863229f0ddcdbChris Lattner  class MCInstPrinter;
3325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCSection;
3425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCSymbol;
359a7e2ccf574368b60455f8c8975030475a1f3ce0Daniel Dunbar  class StringRef;
3686e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner  class Twine;
3725e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class raw_ostream;
3886e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner  class formatted_raw_ostream;
3925e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
40df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne  typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
41df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne
42e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// MCStreamer - Streaming machine code generation interface.  This interface
43e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// is intended to provide a programatic interface that is very similar to the
44e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// level that an assembler .s file provides.  It has callbacks to emit bytes,
457092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar  /// handle directives, etc.  The implementation of this interface retains
46e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// state to know what the current section is etc.
47e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  ///
48e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// There are multiple implementations of this interface: one for writing out
49e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// a .s file, and implementations that write out .o files of various formats.
50e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  ///
5125e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCStreamer {
525da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth  public:
535da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth    enum StreamerKind {
545da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_AsmStreamer,
555da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_NullStreamer,
565da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_RecordStreamer,
575da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth
585da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      // MCObjectStreamer subclasses.
595da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_ELFStreamer,
605da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_ARMELFStreamer,
615da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_MachOStreamer,
625da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_PureStreamer,
639c5b94b6be08afe22b576d007353a0002603cef1Jack Carter      SK_MipsELFStreamer,
645da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth      SK_WinCOFFStreamer
655da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth    };
665da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth
675da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth  private:
685da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth    const StreamerKind Kind;
6925e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    MCContext &Context;
7025e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
711f7210e808373fa92be3a2d4fa653a6f79d5088bCraig Topper    MCStreamer(const MCStreamer&) LLVM_DELETED_FUNCTION;
721f7210e808373fa92be3a2d4fa653a6f79d5088bCraig Topper    MCStreamer &operator=(const MCStreamer&) LLVM_DELETED_FUNCTION;
7325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
74f9efd83166401bca542c6702ea329f9901c4e04bRafael Espindola    bool EmitEHFrame;
75f9efd83166401bca542c6702ea329f9901c4e04bRafael Espindola    bool EmitDebugFrame;
76f9efd83166401bca542c6702ea329f9901c4e04bRafael Espindola
77d7c8ccae8e48dce3ab7c3e9b4d8a309998c47961Rafael Espindola    std::vector<MCDwarfFrameInfo> FrameInfos;
78d7c8ccae8e48dce3ab7c3e9b4d8a309998c47961Rafael Espindola    MCDwarfFrameInfo *getCurrentFrameInfo();
79529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola    MCSymbol *EmitCFICommon();
80d7c8ccae8e48dce3ab7c3e9b4d8a309998c47961Rafael Espindola    void EnsureValidFrame();
81d7c8ccae8e48dce3ab7c3e9b4d8a309998c47961Rafael Espindola
82ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis    std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
8391d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis    MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
8491d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis    void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
850855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis    void EnsureValidW64UnwindInfo();
860855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis
8749cb9b88867426d1a430f248550d3cc785a68fe4Rafael Espindola    MCSymbol* LastSymbol;
88ed708f9c1facb9928ef2f79503e7030c8f25b00dRafael Espindola
897d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger    /// SectionStack - This is stack of current and previous section
907d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger    /// values saved by PushSection.
91df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
927092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar
9307f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames    bool AutoInitSections;
9407f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames
957768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola  protected:
965da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth    MCStreamer(StreamerKind Kind, MCContext &Ctx);
97a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola
98a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola    const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
99a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola                                  const MCSymbol *B);
100a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola
101a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindola    const MCExpr *ForceExpAbs(const MCExpr* Expr);
1021674b0b0e4972b844833f253286cbf99a6e99d6eBenjamin Kramer
103547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola    void RecordProcStart(MCDwarfFrameInfo &Frame);
104547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola    virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
1051fe9737eb49ecb80fbb547f0e16e10a726cd53cfRafael Espindola    void RecordProcEnd(MCDwarfFrameInfo &Frame);
1061fe9737eb49ecb80fbb547f0e16e10a726cd53cfRafael Espindola    virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
107c25dad8750083829d9a8935ce40d0734e5488f8eRafael Espindola    void EmitFrames(bool usingCFI);
108c25dad8750083829d9a8935ce40d0734e5488f8eRafael Espindola
1093185f5c35322cbd10040ab20f265042d477efe62Charles Davis    MCWin64EHUnwindInfo *getCurrentW64UnwindInfo(){return CurrentW64UnwindInfo;}
11038ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis    void EmitW64Tables();
1113185f5c35322cbd10040ab20f265042d477efe62Charles Davis
112381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  public:
11325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    virtual ~MCStreamer();
11425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
1155da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth    StreamerKind getKind() const { return Kind; }
1165da3665cc501ed8928e63678254357214ec0b9ebChandler Carruth
1175399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas    /// State management
1185399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas    ///
1195399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas    virtual void reset();
1205399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas
12125e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    MCContext &getContext() const { return Context; }
12225e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
12389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    unsigned getNumFrameInfos() {
12489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola      return FrameInfos.size();
12589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    }
12689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
12789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    const MCDwarfFrameInfo &getFrameInfo(unsigned i) {
12889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola      return FrameInfos[i];
12989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    }
13089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
131dda1bdc962a314bf4fca86f4cd4802ff6c55b172Bill Wendling    ArrayRef<MCDwarfFrameInfo> getFrameInfos() {
132dda1bdc962a314bf4fca86f4cd4802ff6c55b172Bill Wendling      return FrameInfos;
133dda1bdc962a314bf4fca86f4cd4802ff6c55b172Bill Wendling    }
134dda1bdc962a314bf4fca86f4cd4802ff6c55b172Bill Wendling
13538ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis    unsigned getNumW64UnwindInfos() {
13638ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis      return W64UnwindInfos.size();
13738ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis    }
13838ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis
13938ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis    MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
140ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis      return *W64UnwindInfos[i];
14138ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis    }
14238ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis
1430fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// @name Assembly File Formatting.
1440fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// @{
1450dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
14691bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// isVerboseAsm - Return true if this streamer supports verbose assembly
14791bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// and if it is enabled.
14856591ab218639d8a6e4c756ca37adaf20215c3b6Chris Lattner    virtual bool isVerboseAsm() const { return false; }
1490dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
15091bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// hasRawTextSupport - Return true if this asm streamer supports emitting
15191bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// unformatted text to the .s file with EmitRawText.
15291bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    virtual bool hasRawTextSupport() const { return false; }
1530fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner
154d32c7cfa248f685e6e3064c0958dc2f0c31a4df6Chris Lattner    /// AddComment - Add a comment that can be emitted to the generated .s
15586e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// file if applicable as a QoI issue to make the output of the compiler
15686e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// more readable.  This only affects the MCAsmStreamer, and only when
15786e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// verbose assembly output is enabled.
15886e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    ///
15986e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// If the comment includes embedded \n's, they will each get the comment
16086e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// prefix as appropriate.  The added comment should not end with a \n.
161d32c7cfa248f685e6e3064c0958dc2f0c31a4df6Chris Lattner    virtual void AddComment(const Twine &T) {}
1620dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
163d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// GetCommentOS - Return a raw_ostream that comments can be written to.
164d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// Unlike AddComment, you are required to terminate comments with \n if you
165d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// use this method.
166d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    virtual raw_ostream &GetCommentOS();
1670dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
1680fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
1690fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    virtual void AddBlankLine() {}
1700dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
1710fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// @}
1720dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
17384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @name Symbol & Section Management
17484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @{
1750dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
1766a4824c466bbfbcbe7dc4d95ec1e23a14ec73d87Dan Gohman    /// getCurrentSection - Return the current section that the streamer is
1777092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// emitting code to.
178df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    MCSectionSubPair getCurrentSection() const {
1797d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger      if (!SectionStack.empty())
1807d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger        return SectionStack.back().first;
181df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      return MCSectionSubPair();
1827768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    }
18384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
1841674b0b0e4972b844833f253286cbf99a6e99d6eBenjamin Kramer    /// getPreviousSection - Return the previous section that the streamer is
1851674b0b0e4972b844833f253286cbf99a6e99d6eBenjamin Kramer    /// emitting code to.
186df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    MCSectionSubPair getPreviousSection() const {
1877d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger      if (!SectionStack.empty())
1887d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger        return SectionStack.back().second;
189df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      return MCSectionSubPair();
1907768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    }
1917768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola
1927768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// ChangeSection - Update streamer for a new active section.
1937768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    ///
1947768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// This is called by PopSection and SwitchSection, if the current
1957768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// section changes.
196df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
1977768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola
1987768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// pushSection - Save the current and previous section on the
1997768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// section stack.
2007768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    void PushSection() {
2017d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger      SectionStack.push_back(std::make_pair(getCurrentSection(),
2027d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger                                            getPreviousSection()));
2037768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    }
2047768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola
2057768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// popSection - Restore the current and previous section from
2067768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// the section stack.  Calls ChangeSection as needed.
2077768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    ///
2087768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    /// Returns false if the stack was empty.
2097768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    bool PopSection() {
2107d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger      if (SectionStack.size() <= 1)
2117768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola        return false;
212df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
213df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      MCSectionSubPair curSection = SectionStack.back().first;
2147768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola
2157768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola      if (oldSection != curSection)
216df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne        ChangeSection(curSection.first, curSection.second);
217df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      return true;
218df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    }
219df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne
220df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    bool SubSection(const MCExpr *Subsection) {
221df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      if (SectionStack.empty())
222df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne        return false;
223df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne
224df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      SwitchSection(SectionStack.back().first.first, Subsection);
2257768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola      return true;
2267768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    }
2271674b0b0e4972b844833f253286cbf99a6e99d6eBenjamin Kramer
228381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// SwitchSection - Set the current section where code is being emitted to
229fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @p Section.  This is required to update CurSection.
230381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
231381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to assembler directives like .section, .text, etc.
232df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
2337768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola      assert(Section && "Cannot switch to a null section!");
234df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      MCSectionSubPair curSection = SectionStack.back().first;
2357d0805dcb82e9ba1d90ce8d702169683b9caded7Joerg Sonnenberger      SectionStack.back().second = curSection;
236df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      if (MCSectionSubPair(Section, Subsection) != curSection) {
237df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne        SectionStack.back().first = MCSectionSubPair(Section, Subsection);
238df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne        ChangeSection(Section, Subsection);
2397768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola      }
2407768a9dce14431018133cd586f5c8ce3e057f069Rafael Espindola    }
2410dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
242410ef2b263e92d3de1b2acff7437059400daed7dCharles Davis    /// SwitchSectionNoChange - Set the current section where code is being
243410ef2b263e92d3de1b2acff7437059400daed7dCharles Davis    /// emitted to @p Section.  This is required to update CurSection. This
244410ef2b263e92d3de1b2acff7437059400daed7dCharles Davis    /// version does not call ChangeSection.
245df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne    void SwitchSectionNoChange(const MCSection *Section,
246df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne                               const MCExpr *Subsection = 0) {
247410ef2b263e92d3de1b2acff7437059400daed7dCharles Davis      assert(Section && "Cannot switch to a null section!");
248df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      MCSectionSubPair curSection = SectionStack.back().first;
249410ef2b263e92d3de1b2acff7437059400daed7dCharles Davis      SectionStack.back().second = curSection;
250df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne      if (MCSectionSubPair(Section, Subsection) != curSection)
251df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne        SectionStack.back().first = MCSectionSubPair(Section, Subsection);
252410ef2b263e92d3de1b2acff7437059400daed7dCharles Davis    }
253410ef2b263e92d3de1b2acff7437059400daed7dCharles Davis
25407f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames    /// Initialize the streamer.
25507f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames    void InitStreamer() {
25607f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames      if (AutoInitSections)
25707f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames        InitSections();
25807f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames    }
25907f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames
26007f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames    /// Tell this MCStreamer to call InitSections upon initialization.
26107f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames    void setAutoInitSections(bool AutoInitSections) {
26207f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames      this->AutoInitSections = AutoInitSections;
26307f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames    }
26407f6a4fde0a1b081fbefd986345c9b2f4f85e88aLang Hames
265d80781b98b771d370730ab7c630018f23e202b57Rafael Espindola    /// InitSections - Create the default sections and set the initial one.
266d80781b98b771d370730ab7c630018f23e202b57Rafael Espindola    virtual void InitSections() = 0;
267030f63a397edc20f8f661bac62f7b90cb5cf57bcEli Bendersky
268030f63a397edc20f8f661bac62f7b90cb5cf57bcEli Bendersky    /// InitToTextSection - Create a text section and switch the streamer to it.
269030f63a397edc20f8f661bac62f7b90cb5cf57bcEli Bendersky    virtual void InitToTextSection() = 0;
270d80781b98b771d370730ab7c630018f23e202b57Rafael Espindola
271fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitLabel - Emit a label for @p Symbol into the current section.
272381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
273381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to an assembler statement such as:
274381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///   foo:
275381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
276381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Symbol - The symbol to emit. A given symbol should only be
277381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// emitted as a label once, and symbols emitted as a label should never be
278381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// used in an assignment.
279ed708f9c1facb9928ef2f79503e7030c8f25b00dRafael Espindola    virtual void EmitLabel(MCSymbol *Symbol);
280381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
2812c3a4641a7785da78839caf574277df9cd93b52cReed Kotler    virtual void EmitDebugLabel(MCSymbol *Symbol);
2822c3a4641a7785da78839caf574277df9cd93b52cReed Kotler
2838bca4106dfc2945723251db10e340183f3e372ddRafael Espindola    virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
2848bca4106dfc2945723251db10e340183f3e372ddRafael Espindola                                     MCSymbol *EHSymbol);
2858bca4106dfc2945723251db10e340183f3e372ddRafael Espindola
2863e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach    /// EmitAssemblerFlag - Note in the output the specified @p Flag.
287a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner    virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
288a5c783280f83df5c60a8ed9e32c61b05a11048e3Kevin Enderby
289cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar    /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
290cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar    /// options into the output.
291cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar    virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
292cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar
2933e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach    /// EmitDataRegion - Note in the output the specified region @p Kind.
2943e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach    virtual void EmitDataRegion(MCDataRegionType Kind) {}
2953e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach
296ce79299f78bb04e76e1860ab119b85d69f3a19c7Jim Grosbach    /// EmitThumbFunc - Note in the output that the specified @p Func is
297ce79299f78bb04e76e1860ab119b85d69f3a19c7Jim Grosbach    /// a Thumb mode function (ARM target only).
298ce79299f78bb04e76e1860ab119b85d69f3a19c7Jim Grosbach    virtual void EmitThumbFunc(MCSymbol *Func) = 0;
299ce79299f78bb04e76e1860ab119b85d69f3a19c7Jim Grosbach
30077afbdce53aa740777486b0cc4e9df151ae65468Jack Carter    /// getOrCreateSymbolData - Get symbol data for given symbol.
30177afbdce53aa740777486b0cc4e9df151ae65468Jack Carter    virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
30277afbdce53aa740777486b0cc4e9df151ae65468Jack Carter
303fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
304381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
305381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to an assembler statement such as:
306381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///  symbol = value
307381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
308381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// The assignment generates no code, but has the side effect of binding the
309381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// value in the current context. For the assembly streamer, this prints the
310381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// binding into the .s file.
311381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
312381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Symbol - The symbol being assigned to.
313381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Value - The value for the symbol.
314821e3334ed3390d931f497300e6a5f1dc21bcfb3Daniel Dunbar    virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
31525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
316484291c27319668ad99cb87def000254357736fbRafael Espindola    /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
317484291c27319668ad99cb87def000254357736fbRafael Espindola    ///
318484291c27319668ad99cb87def000254357736fbRafael Espindola    /// This corresponds to an assembler statement such as:
319484291c27319668ad99cb87def000254357736fbRafael Espindola    ///  .weakref alias, symbol
320484291c27319668ad99cb87def000254357736fbRafael Espindola    ///
321484291c27319668ad99cb87def000254357736fbRafael Espindola    /// @param Alias - The alias that is being created.
322484291c27319668ad99cb87def000254357736fbRafael Espindola    /// @param Symbol - The symbol being aliased.
323484291c27319668ad99cb87def000254357736fbRafael Espindola    virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
324484291c27319668ad99cb87def000254357736fbRafael Espindola
325fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
326a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar    virtual void EmitSymbolAttribute(MCSymbol *Symbol,
327a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner                                     MCSymbolAttr Attribute) = 0;
32825e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
329fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
33095cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    ///
33195cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    /// @param Symbol - The symbol to have its n_desc field set.
33295cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    /// @param DescValue - The value to set into the n_desc field.
33395cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
33495cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby
335b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
336b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    ///
337b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// @param Symbol - The symbol to have its External & Type fields set.
338b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
339b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
340b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
341b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    ///
342b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// @param StorageClass - The storage class the symbol should have.
343b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
344b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
345b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// EmitCOFFSymbolType - Emit the type of the symbol.
346b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    ///
347b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
348b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void EmitCOFFSymbolType(int Type) = 0;
349b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
350b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// EndCOFFSymbolDef - Marks the end of the symbol definition.
351b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void EndCOFFSymbolDef() = 0;
352b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
3538f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindola    /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
3548f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindola    ///
3558f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindola    /// @param Symbol - Symbol the section relative realocation should point to.
3568f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindola    virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
3578f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindola
35899328add833807f12a4950c7de29fb2a5df04703Chris Lattner    /// EmitELFSize - Emit an ELF .size directive.
35999328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///
36099328add833807f12a4950c7de29fb2a5df04703Chris Lattner    /// This corresponds to an assembler statement such as:
36199328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///  .size symbol, expression
36299328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///
36399328add833807f12a4950c7de29fb2a5df04703Chris Lattner    virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
3640dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
3659eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// EmitCommonSymbol - Emit a common symbol.
3664e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    ///
3674e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    /// @param Symbol - The common symbol to emit.
3684e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    /// @param Size - The size of the common symbol.
3697092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// @param ByteAlignment - The alignment of the symbol if
3709eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// non-zero. This must be a power of 2.
3719eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
3727092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar                                  unsigned ByteAlignment) = 0;
3734e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner
3749eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
3759eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    ///
3769eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// @param Symbol - The common symbol to emit.
3779eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// @param Size - The size of the common symbol.
37836a16015ac108e2f0dd2d6d96a6d364bc74c50d7Benjamin Kramer    /// @param ByteAlignment - The alignment of the common symbol in bytes.
37936a16015ac108e2f0dd2d6d96a6d364bc74c50d7Benjamin Kramer    virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
38036a16015ac108e2f0dd2d6d96a6d364bc74c50d7Benjamin Kramer                                       unsigned ByteAlignment) = 0;
3810dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
3820df4a80e2063424929bbfaa61dd7973062218ad4Eric Christopher    /// EmitZerofill - Emit the zerofill section and an optional symbol.
3839be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    ///
3849be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Section - The zerofill section to create and or to put the symbol
3859be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Symbol - The zerofill symbol to emit, if non-NULL.
3869be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Size - The size of the zerofill symbol.
3877092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// @param ByteAlignment - The alignment of the zerofill symbol if
3887092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// non-zero. This must be a power of 2 on some targets.
3898751b94ffbd9c49df8949a37f78d6bd0be87b256Daniel Dunbar    virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
390c90a1fcf9f44858b20e0f5f7e0b98049aec7a1e0Evan Cheng                              uint64_t Size = 0,unsigned ByteAlignment = 0) = 0;
3919be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner
392482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
393482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    ///
3944d01cbe93b0e1a349b5c2881f1b319963f9e0504Eric Christopher    /// @param Section - The thread local common section.
395482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// @param Symbol - The thread local common symbol to emit.
396482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// @param Size - The size of the symbol.
397482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// @param ByteAlignment - The alignment of the thread local common symbol
398482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// if non-zero.  This must be a power of 2 on some targets.
3994d01cbe93b0e1a349b5c2881f1b319963f9e0504Eric Christopher    virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
4000dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach                                uint64_t Size, unsigned ByteAlignment = 0) = 0;
401ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
40284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @}
40384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @name Generating Data
40484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @{
40584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
406c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko    /// EmitBytes - Emit the bytes in \p Data into the output.
407381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
408381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This is used to implement assembler directives such as .byte, .ascii,
409381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// etc.
410ca1dd05c3c12e857614ae6837f90894396225dd6Eric Christopher    virtual void EmitBytes(StringRef Data, unsigned AddrSpace = 0) = 0;
411381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
412fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValue - Emit the expression @p Value into the output as a native
413fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// integer of the given @p Size bytes.
414381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
415381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This is used to implement assembler directives such as .word, .quad,
416381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// etc.
417381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
418381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Value - The value to emit.
419381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Size - The size of the integer (in bytes) to emit. This must
420381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// match a native machine width.
42189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
422debd7e4e8bc5cfe61bfb71835ce2b1a3fbccc2beRafael Espindola                               unsigned AddrSpace) = 0;
42389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
42489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    void EmitValue(const MCExpr *Value, unsigned Size, unsigned AddrSpace = 0);
42589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
42632ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner    /// EmitIntValue - Special case of EmitValue that avoids the client having
42732ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner    /// to pass in a MCExpr for constant integers.
4282df042cb32ecb8d2e1d499dfa27d5074c8b40e13Rafael Espindola    virtual void EmitIntValue(uint64_t Value, unsigned Size,
4292df042cb32ecb8d2e1d499dfa27d5074c8b40e13Rafael Espindola                              unsigned AddrSpace = 0);
4300dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
4310bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola    /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
4320bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola    /// this is done by producing
4330bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola    /// foo = value
4340bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola    /// .long foo
4350bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola    void EmitAbsValue(const MCExpr *Value, unsigned Size,
4360bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola                      unsigned AddrSpace = 0);
4373bb435301a2b5c901a993b0e151d05b596697038Kevin Enderby
438e8cfbd843d737e1f95c3032c7670c2be3838a6f6Rafael Espindola    virtual void EmitULEB128Value(const MCExpr *Value) = 0;
4393ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola
440e8cfbd843d737e1f95c3032c7670c2be3838a6f6Rafael Espindola    virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
4413ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola
4423ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola    /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
4433ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola    /// client having to pass in a MCExpr for constant integers.
4441ced208be9cab0f994c5df9000da36bc313b2507Eric Christopher    void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0,
445dc08bfbd565ba6540be698bba551b2039661299dJack Carter                             unsigned AddrSpace = 0);
4463ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola
4473ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola    /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
4483ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola    /// client having to pass in a MCExpr for constant integers.
44971e7f9210d87fa29202d851c43b5e91bbbd2fa51Rafael Espindola    void EmitSLEB128IntValue(int64_t Value, unsigned AddrSpace = 0);
4503bb435301a2b5c901a993b0e151d05b596697038Kevin Enderby
4516cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    /// EmitSymbolValue - Special case of EmitValue that avoids the client
4526cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    /// having to pass in a MCExpr for MCSymbols.
453175ccab75f3a355285cf4533c201cbcecfd5928dRafael Espindola    void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
454175ccab75f3a355285cf4533c201cbcecfd5928dRafael Espindola                         unsigned AddrSpace = 0);
4550dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
4566c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka    /// EmitGPRel64Value - Emit the expression @p Value into the output as a
4576c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka    /// gprel64 (64-bit GP relative) value.
4586c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka    ///
4596c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka    /// This is used to implement assembler directives such as .gpdword on
4606c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka    /// targets that support them.
4616c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka    virtual void EmitGPRel64Value(const MCExpr *Value);
4626c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka
463fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitGPRel32Value - Emit the expression @p Value into the output as a
464718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// gprel32 (32-bit GP relative) value.
465718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    ///
466718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// This is used to implement assembler directives such as .gprel32 on
467718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// targets that support them.
4683e03211625bba5bbb70a193c140ebf4dd8388bb7Rafael Espindola    virtual void EmitGPRel32Value(const MCExpr *Value);
4690dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
470ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner    /// EmitFill - Emit NumBytes bytes worth of the value specified by
471ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner    /// FillValue.  This implements directives such as '.space'.
472aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner    virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
473ca1dd05c3c12e857614ae6837f90894396225dd6Eric Christopher                          unsigned AddrSpace = 0);
4740dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
4756449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    /// EmitZeros - Emit NumBytes worth of zeros.  This is a convenience
4766449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    /// function that just wraps EmitFill.
477ca1dd05c3c12e857614ae6837f90894396225dd6Eric Christopher    void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0) {
4786449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner      EmitFill(NumBytes, 0, AddrSpace);
4796449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    }
4806449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner
481fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValueToAlignment - Emit some number of copies of @p Value until
482fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// the byte alignment @p ByteAlignment is reached.
48384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
48484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// If the number of bytes need to emit for the alignment is not a multiple
485fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// of @p ValueSize, then the contents of the emitted fill bytes is
48684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// undefined.
48784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
48884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// This used to implement the .align assembler directive.
48984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
49084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param ByteAlignment - The alignment to reach. This must be a power of
491c29dfa786a23c9ff0827ce4a56b5b178e4087aaaDaniel Dunbar    /// two on some targets.
49284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param Value - The value to use when filling bytes.
493fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @param ValueSize - The size of the integer (in bytes) to emit for
494fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @p Value. This must match a native machine width.
49584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
49684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// the alignment cannot be reached in this many bytes, no bytes are
49784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// emitted.
49884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
49984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                      unsigned ValueSize = 1,
50084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                      unsigned MaxBytesToEmit = 0) = 0;
5016e72048add2a6464e038121c6c275da37528aa0aKevin Enderby
5026e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
5036e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// is reached.
5046e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    ///
5056e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// This used to align code where the alignment bytes may be executed.  This
5066e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// can emit different bytes for different sizes to optimize execution.
5076e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    ///
5086e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// @param ByteAlignment - The alignment to reach. This must be a power of
5096e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// two on some targets.
5106e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
5116e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// the alignment cannot be reached in this many bytes, no bytes are
5126e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// emitted.
5136e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    virtual void EmitCodeAlignment(unsigned ByteAlignment,
5146e72048add2a6464e038121c6c275da37528aa0aKevin Enderby                                   unsigned MaxBytesToEmit = 0) = 0;
51584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
516fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValueToOffset - Emit some number of copies of @p Value until the
517fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// byte offset @p Offset is reached.
51884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
51984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// This is used to implement assembler directives such as .org.
52084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
5214a1fadaf5207e46d19c64e5773ff8d9e65e607d7Daniel Dunbar    /// @param Offset - The offset to reach. This may be an expression, but the
52284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// expression must be associated with the current section.
52384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param Value - The value to use when filling bytes.
524ebd4c05c3cbd61215366d4d16f1c1a2e57e7156dJim Grosbach    /// @return false on success, true if the offset was invalid.
525ebd4c05c3cbd61215366d4d16f1c1a2e57e7156dJim Grosbach    virtual bool EmitValueToOffset(const MCExpr *Offset,
52684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                   unsigned char Value = 0) = 0;
5270dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
52884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @}
5290dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
530a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// EmitFileDirective - Switch to a new logical file.  This is used to
531a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// implement the '.file "foo.c"' assembler directive.
532a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    virtual void EmitFileDirective(StringRef Filename) = 0;
5330dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
534a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// EmitDwarfFileDirective - Associate a filename with a specified logical
535a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
536a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// directive.
53744d798d9763bc32aaf49fe7c10d604845f4b6685Nick Lewycky    virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
5383de61b4c0144748e4b9157e2c22fe4ea685981a2Manman Ren                                        StringRef Filename, unsigned CUID = 0);
539af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola
540af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola    /// EmitDwarfLocDirective - This implements the DWARF2
541af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola    // '.loc fileno lineno ...' assembler directive.
542af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola    virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
543af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola                                       unsigned Column, unsigned Flags,
544af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola                                       unsigned Isa,
5453f3bf9387b75f4c932e4c59bd7af719d26ae4b99Devang Patel                                       unsigned Discriminator,
5463f3bf9387b75f4c932e4c59bd7af719d26ae4b99Devang Patel                                       StringRef FileName);
54784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
54832a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola    virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
54932a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola                                          const MCSymbol *LastLabel,
550672b93a3324cc1da6d374eed4c75c050a9cad7beEvan Cheng                                          const MCSymbol *Label,
551672b93a3324cc1da6d374eed4c75c050a9cad7beEvan Cheng                                          unsigned PointerSize) = 0;
55232a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola
553245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola    virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
554245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola                                           const MCSymbol *Label) {
555245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola    }
556245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola
55732a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola    void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
55832a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola                              int PointerSize);
55932a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola
560d967578a8c506be341d20a1558eebb31484b8b6dBill Wendling    virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
561f9efd83166401bca542c6702ea329f9901c4e04bRafael Espindola    virtual void EmitCFISections(bool EH, bool Debug);
562547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola    void EmitCFIStartProc();
5631fe9737eb49ecb80fbb547f0e16e10a726cd53cfRafael Espindola    void EmitCFIEndProc();
564066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
565066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIDefCfaOffset(int64_t Offset);
566066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIDefCfaRegister(int64_t Register);
567066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
568066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
569066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
570066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIRememberState();
571066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIRestoreState();
572066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFISameValue(int64_t Register);
573ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola    virtual void EmitCFIRestore(int64_t Register);
574066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
575066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola    virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
5766f0b181bc70318f8d5d4b9bdead7fc748677fe2aRafael Espindola    virtual void EmitCFIEscape(StringRef Values);
57716d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola    virtual void EmitCFISignalFrame();
578c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola    virtual void EmitCFIUndefined(int64_t Register);
579f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola    virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
580cdfecc8759941c2996214070478d30084b79d463Rafael Espindola
581fbc539ff37ddd08c2480be9185e7a40919ce8940Charles Davis    virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
5829c77398d1c89f615735d304cd7eda3c3e9b1504fCharles Davis    virtual void EmitWin64EHEndProc();
583f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis    virtual void EmitWin64EHStartChained();
584f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis    virtual void EmitWin64EHEndChained();
585440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis    virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
586440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis                                    bool Except);
587440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis    virtual void EmitWin64EHHandlerData();
588c3b162857a587c9877e903f038471b882b213232Charles Davis    virtual void EmitWin64EHPushReg(unsigned Register);
589c3b162857a587c9877e903f038471b882b213232Charles Davis    virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
590c3b162857a587c9877e903f038471b882b213232Charles Davis    virtual void EmitWin64EHAllocStack(unsigned Size);
591c3b162857a587c9877e903f038471b882b213232Charles Davis    virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
592c3b162857a587c9877e903f038471b882b213232Charles Davis    virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
593ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis    virtual void EmitWin64EHPushFrame(bool Code);
5949c77398d1c89f615735d304cd7eda3c3e9b1504fCharles Davis    virtual void EmitWin64EHEndProlog();
595ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
596fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitInstruction - Emit the given @p Instruction into the current
597381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// section.
59825e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    virtual void EmitInstruction(const MCInst &Inst) = 0;
599ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar
6004766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky    /// \brief Set the bundle alignment mode from now on in the section.
6014766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky    /// The argument is the power of 2 to which the alignment is set. The
6024766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky    /// value 0 means turn the bundle alignment off.
6034766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky    virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
6044766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky
6054766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky    /// \brief The following instructions are a bundle-locked group.
6066c1d4972cf1cd6b6072e31c05f97abb1ed7a8497Eli Bendersky    ///
6076c1d4972cf1cd6b6072e31c05f97abb1ed7a8497Eli Bendersky    /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
6086c1d4972cf1cd6b6072e31c05f97abb1ed7a8497Eli Bendersky    ///                     the end of a bundle.
6096c1d4972cf1cd6b6072e31c05f97abb1ed7a8497Eli Bendersky    virtual void EmitBundleLock(bool AlignToEnd) = 0;
6104766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky
6114766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky    /// \brief Ends a bundle-locked group.
6124766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky    virtual void EmitBundleUnlock() = 0;
6134766ef41b31e4f97bce1179c3b0398303bf65356Eli Bendersky
61491bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// EmitRawText - If this file is backed by a assembly streamer, this dumps
61591bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// the specified string in the output .s file.  This capability is
61691bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
61791bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    virtual void EmitRawText(StringRef String);
61858bc4dd4a91443ddd3120b0a2f1801ad4d6aae1cChris Lattner    void EmitRawText(const Twine &String);
6190dd2c9331887b9d0aa06b1e201c5eda4361365fcJim Grosbach
620b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    /// ARM-related methods.
621b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    /// FIXME: Eventually we should have some "target MC streamer" and move
622b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    /// these methods there.
623b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    virtual void EmitFnStart();
624b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    virtual void EmitFnEnd();
625b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    virtual void EmitCantUnwind();
626b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    virtual void EmitPersonality(const MCSymbol *Personality);
627b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov    virtual void EmitHandlerData();
62857caad7a33ff145b71545f10dcfbbf2fd0f595d3Anton Korobeynikov    virtual void EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
62957caad7a33ff145b71545f10dcfbbf2fd0f595d3Anton Korobeynikov    virtual void EmitPad(int64_t Offset);
63057caad7a33ff145b71545f10dcfbbf2fd0f595d3Anton Korobeynikov    virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList,
63157caad7a33ff145b71545f10dcfbbf2fd0f595d3Anton Korobeynikov                             bool isVector);
632b5e16af9ea04cc1f94ca631104e5e6be96546aa1Anton Korobeynikov
633f35c62bf025411393c7df0803851010cc0e597baAdhemerval Zanella    /// PPC-related methods.
634f35c62bf025411393c7df0803851010cc0e597baAdhemerval Zanella    /// FIXME: Eventually replace it with some "target MC streamer" and move
635f35c62bf025411393c7df0803851010cc0e597baAdhemerval Zanella    /// these methods there.
636f35c62bf025411393c7df0803851010cc0e597baAdhemerval Zanella    virtual void EmitTCEntry(const MCSymbol &S);
637f35c62bf025411393c7df0803851010cc0e597baAdhemerval Zanella
63899b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola    /// FinishImpl - Streamer specific finalization.
63999b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola    virtual void FinishImpl() = 0;
6404b1000d117f1b7cc5411bc251d141fe182a4ae1cDan Gohman    /// Finish - Finish emission of machine code.
64199b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola    void Finish();
64225e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  };
64325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
644011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  /// createNullStreamer - Create a dummy machine code streamer, which does
645011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  /// nothing. This is useful for timing the assembler front end.
646011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  MCStreamer *createNullStreamer(MCContext &Ctx);
647011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar
648381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// createAsmStreamer - Create a machine code streamer which will print out
649381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// assembly for the native target, suitable for compiling with a native
650381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// assembler.
6519dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
6529dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param InstPrint - If given, the instruction printer to use. If not given
6534c42a6de9f5456cc1b28f2d37db589f580f2adc7Chris Lattner  /// the MCInst representation will be printed.  This method takes ownership of
6544c42a6de9f5456cc1b28f2d37db589f580f2adc7Chris Lattner  /// InstPrint.
6559dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
6569dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param CE - If given, a code emitter to use to show the instruction
657c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko  /// encoding inline with the assembly. This method takes ownership of \p CE.
6589dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
659745dacc91d7ee9531bfba76b21beb5d4eef93a7dDaniel Dunbar  /// \param TAB - If given, a target asm backend to use to show the fixup
660745dacc91d7ee9531bfba76b21beb5d4eef93a7dDaniel Dunbar  /// information in conjunction with encoding information. This method takes
661c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko  /// ownership of \p TAB.
662745dacc91d7ee9531bfba76b21beb5d4eef93a7dDaniel Dunbar  ///
6639dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param ShowInst - Whether to show the MCInst representation inline with
6649dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// the assembly.
66586e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner  MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
66689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola                                bool isVerboseAsm,
66789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola                                bool useLoc,
668f1a5c7ec04002769f1638e64f7439589f0f926e6Rafael Espindola                                bool useCFI,
66944d798d9763bc32aaf49fe7c10d604845f4b6685Nick Lewycky                                bool useDwarfDirectory,
67090edac0e8b35f766599362b6301863229f0ddcdbChris Lattner                                MCInstPrinter *InstPrint = 0,
6719dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar                                MCCodeEmitter *CE = 0,
67278c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Cheng                                MCAsmBackend *TAB = 0,
673e266ce6c6eaf52ebe2b18d85b5e23788cf2f6ef4Bill Wendling                                bool ShowInst = false);
674381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
675d86e6ac9892ee61742d85f9f14f1179216d2e47bDan Gohman  /// createMachOStreamer - Create a machine code streamer which will generate
676381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// Mach-O format object files.
6771abcd06856df324eac98d4bf5ba673fb77ae6a11Benjamin Kramer  ///
678c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko  /// Takes ownership of \p TAB and \p CE.
67978c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Cheng  MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
680ac2884a717daf3ad2aa8425320795d661e8a980bDaniel Dunbar                                  raw_ostream &OS, MCCodeEmitter *CE,
681ac2884a717daf3ad2aa8425320795d661e8a980bDaniel Dunbar                                  bool RelaxAll = false);
68225e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
683eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner  /// createWinCOFFStreamer - Create a machine code streamer which will
684eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner  /// generate Microsoft COFF format object files.
6851abcd06856df324eac98d4bf5ba673fb77ae6a11Benjamin Kramer  ///
686c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko  /// Takes ownership of \p TAB and \p CE.
687eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner  MCStreamer *createWinCOFFStreamer(MCContext &Ctx,
68878c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Cheng                                    MCAsmBackend &TAB,
689e2195d8b357d7081edb5eb09d1d6e9d7b4bfc308Michael J. Spencer                                    MCCodeEmitter &CE, raw_ostream &OS,
690e2195d8b357d7081edb5eb09d1d6e9d7b4bfc308Michael J. Spencer                                    bool RelaxAll = false);
691eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner
6926b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming  /// createELFStreamer - Create a machine code streamer which will generate
6936b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming  /// ELF format object files.
69478c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Cheng  MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
69591f2cce231debf43384fe4ee39c11ba8460503ebJim Grosbach                                raw_ostream &OS, MCCodeEmitter *CE,
69691f2cce231debf43384fe4ee39c11ba8460503ebJim Grosbach                                bool RelaxAll, bool NoExecStack);
6976b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming
698abc756216dbace87826398f8fa1e8e57e401cc86Daniel Dunbar  /// createPureStreamer - Create a machine code streamer which will generate
699abc756216dbace87826398f8fa1e8e57e401cc86Daniel Dunbar  /// "pure" MC object files, for use with MC-JIT and testing tools.
700abc756216dbace87826398f8fa1e8e57e401cc86Daniel Dunbar  ///
701c5252da873d547a19069eaf9030fec203f128f66Dmitri Gribenko  /// Takes ownership of \p TAB and \p CE.
70278c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Cheng  MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
703abc756216dbace87826398f8fa1e8e57e401cc86Daniel Dunbar                                 raw_ostream &OS, MCCodeEmitter *CE);
704abc756216dbace87826398f8fa1e8e57e401cc86Daniel Dunbar
70525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar} // end namespace llvm
70625e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
70725e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar#endif
708