MCStreamer.h revision 4c42a6de9f5456cc1b28f2d37db589f580f2adc7
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
178b67f774e9c38b7718b2b300b628388f966df4e0Chandler Carruth#include "llvm/System/DataTypes.h"
18a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner#include "llvm/MC/MCDirectives.h"
1984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
2025e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbarnamespace llvm {
214a0abd80f18f9c2a10bf5b14cd6731d51972a426Daniel Dunbar  class MCAsmInfo;
224a0abd80f18f9c2a10bf5b14cd6731d51972a426Daniel Dunbar  class MCCodeEmitter;
2325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCContext;
24821e3334ed3390d931f497300e6a5f1dc21bcfb3Daniel Dunbar  class MCExpr;
2525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCInst;
2690edac0e8b35f766599362b6301863229f0ddcdbChris Lattner  class MCInstPrinter;
2725e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCSection;
2825e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCSymbol;
299a7e2ccf574368b60455f8c8975030475a1f3ce0Daniel Dunbar  class StringRef;
301f3e445184e5ca2aa4295c2a77f2a4e0b957fea1Daniel Dunbarclass TargetAsmBackend;
3186e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner  class Twine;
3225e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class raw_ostream;
3386e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner  class formatted_raw_ostream;
3425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
35e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// MCStreamer - Streaming machine code generation interface.  This interface
36e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// is intended to provide a programatic interface that is very similar to the
37e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// level that an assembler .s file provides.  It has callbacks to emit bytes,
387092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar  /// handle directives, etc.  The implementation of this interface retains
39e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// state to know what the current section is etc.
40e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  ///
41e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// There are multiple implementations of this interface: one for writing out
42e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  /// a .s file, and implementations that write out .o files of various formats.
43e18e0c58dcd740c64e962fefde44249d685d0568Chris Lattner  ///
4425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  class MCStreamer {
4525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    MCContext &Context;
4625e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
4725e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
4825e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
4925e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
50381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  protected:
5125e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    MCStreamer(MCContext &Ctx);
52381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
53dabf07c70a5e13a4560d75667fa5c7db28921a92Chris Lattner    /// CurSection - This is the current section code is being emitted to, it is
54dabf07c70a5e13a4560d75667fa5c7db28921a92Chris Lattner    /// kept up to date by SwitchSection.
55dabf07c70a5e13a4560d75667fa5c7db28921a92Chris Lattner    const MCSection *CurSection;
567092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar
57381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  public:
5825e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    virtual ~MCStreamer();
5925e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
6025e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    MCContext &getContext() const { return Context; }
6125e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
620fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// @name Assembly File Formatting.
630fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// @{
6456591ab218639d8a6e4c756ca37adaf20215c3b6Chris Lattner
6556591ab218639d8a6e4c756ca37adaf20215c3b6Chris Lattner    /// isVerboseAsm - Return true if this streamer supports verbose assembly at
6656591ab218639d8a6e4c756ca37adaf20215c3b6Chris Lattner    /// all.
6756591ab218639d8a6e4c756ca37adaf20215c3b6Chris Lattner    virtual bool isVerboseAsm() const { return false; }
680fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner
69d32c7cfa248f685e6e3064c0958dc2f0c31a4df6Chris Lattner    /// AddComment - Add a comment that can be emitted to the generated .s
7086e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// file if applicable as a QoI issue to make the output of the compiler
7186e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// more readable.  This only affects the MCAsmStreamer, and only when
7286e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// verbose assembly output is enabled.
7386e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    ///
7486e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// If the comment includes embedded \n's, they will each get the comment
7586e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// prefix as appropriate.  The added comment should not end with a \n.
76d32c7cfa248f685e6e3064c0958dc2f0c31a4df6Chris Lattner    virtual void AddComment(const Twine &T) {}
7786e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner
78d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// GetCommentOS - Return a raw_ostream that comments can be written to.
79d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// Unlike AddComment, you are required to terminate comments with \n if you
80d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// use this method.
81d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    virtual raw_ostream &GetCommentOS();
82d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner
830fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
840fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    virtual void AddBlankLine() {}
850fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner
860fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// @}
870fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner
8884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @name Symbol & Section Management
8984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @{
907092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar
917092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// getCurrentSection - Return the current seciton that the streamer is
927092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// emitting code to.
937092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    const MCSection *getCurrentSection() const { return CurSection; }
9484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
95381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// SwitchSection - Set the current section where code is being emitted to
96fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @p Section.  This is required to update CurSection.
97381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
98381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to assembler directives like .section, .text, etc.
99975780bb595b57a45a8e6d72d8151b436314ce22Chris Lattner    virtual void SwitchSection(const MCSection *Section) = 0;
100dabf07c70a5e13a4560d75667fa5c7db28921a92Chris Lattner
101fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitLabel - Emit a label for @p Symbol into the current section.
102381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
103381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to an assembler statement such as:
104381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///   foo:
105381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
106381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Symbol - The symbol to emit. A given symbol should only be
107381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// emitted as a label once, and symbols emitted as a label should never be
108381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// used in an assignment.
109ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar    virtual void EmitLabel(MCSymbol *Symbol) = 0;
110381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
111fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitAssemblerFlag - Note in the output the specified @p Flag
112a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner    virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
113a5c783280f83df5c60a8ed9e32c61b05a11048e3Kevin Enderby
114fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
115381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
116381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to an assembler statement such as:
117381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///  symbol = value
118381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
119381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// The assignment generates no code, but has the side effect of binding the
120381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// value in the current context. For the assembly streamer, this prints the
121381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// binding into the .s file.
122381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
123381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Symbol - The symbol being assigned to.
124381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Value - The value for the symbol.
125821e3334ed3390d931f497300e6a5f1dc21bcfb3Daniel Dunbar    virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
12625e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
127fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
128a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar    virtual void EmitSymbolAttribute(MCSymbol *Symbol,
129a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner                                     MCSymbolAttr Attribute) = 0;
13025e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
131fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
13295cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    ///
13395cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    /// @param Symbol - The symbol to have its n_desc field set.
13495cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    /// @param DescValue - The value to set into the n_desc field.
13595cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
13695cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby
13799328add833807f12a4950c7de29fb2a5df04703Chris Lattner
13899328add833807f12a4950c7de29fb2a5df04703Chris Lattner    /// EmitELFSize - Emit an ELF .size directive.
13999328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///
14099328add833807f12a4950c7de29fb2a5df04703Chris Lattner    /// This corresponds to an assembler statement such as:
14199328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///  .size symbol, expression
14299328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///
14399328add833807f12a4950c7de29fb2a5df04703Chris Lattner    virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
14499328add833807f12a4950c7de29fb2a5df04703Chris Lattner
1459eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// EmitCommonSymbol - Emit a common symbol.
1464e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    ///
1474e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    /// @param Symbol - The common symbol to emit.
1484e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    /// @param Size - The size of the common symbol.
1497092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// @param ByteAlignment - The alignment of the symbol if
1509eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// non-zero. This must be a power of 2.
1519eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
1527092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar                                  unsigned ByteAlignment) = 0;
1534e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner
1549eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
1559eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    ///
1569eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// @param Symbol - The common symbol to emit.
1579eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// @param Size - The size of the common symbol.
1589eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) = 0;
1599eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner
1607092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// EmitZerofill - Emit a the zerofill section and an option symbol.
1619be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    ///
1629be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Section - The zerofill section to create and or to put the symbol
1639be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Symbol - The zerofill symbol to emit, if non-NULL.
1649be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Size - The size of the zerofill symbol.
1657092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// @param ByteAlignment - The alignment of the zerofill symbol if
1667092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// non-zero. This must be a power of 2 on some targets.
1678751b94ffbd9c49df8949a37f78d6bd0be87b256Daniel Dunbar    virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
1687092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar                              unsigned Size = 0,unsigned ByteAlignment = 0) = 0;
1699be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner
17084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @}
17184a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @name Generating Data
17284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @{
17384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
1747092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// EmitBytes - Emit the bytes in \arg Data into the output.
175381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
176381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This is used to implement assembler directives such as .byte, .ascii,
177381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// etc.
178aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner    virtual void EmitBytes(StringRef Data, unsigned AddrSpace) = 0;
179381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
180fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValue - Emit the expression @p Value into the output as a native
181fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// integer of the given @p Size bytes.
182381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
183381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This is used to implement assembler directives such as .word, .quad,
184381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// etc.
185381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
186381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Value - The value to emit.
187381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Size - The size of the integer (in bytes) to emit. This must
188381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// match a native machine width.
189aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner    virtual void EmitValue(const MCExpr *Value, unsigned Size,
190aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner                           unsigned AddrSpace) = 0;
191381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
19232ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner    /// EmitIntValue - Special case of EmitValue that avoids the client having
19332ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner    /// to pass in a MCExpr for constant integers.
19432ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner    virtual void EmitIntValue(uint64_t Value, unsigned Size,unsigned AddrSpace);
1956cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner
1966cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    /// EmitSymbolValue - Special case of EmitValue that avoids the client
1976cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    /// having to pass in a MCExpr for MCSymbols.
1986cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    virtual void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
1996cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner                                 unsigned AddrSpace);
20032ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner
201fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitGPRel32Value - Emit the expression @p Value into the output as a
202718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// gprel32 (32-bit GP relative) value.
203718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    ///
204718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// This is used to implement assembler directives such as .gprel32 on
205718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// targets that support them.
206718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    virtual void EmitGPRel32Value(const MCExpr *Value) = 0;
207718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner
208ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner    /// EmitFill - Emit NumBytes bytes worth of the value specified by
209ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner    /// FillValue.  This implements directives such as '.space'.
210aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner    virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
211aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner                          unsigned AddrSpace);
212ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner
2136449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    /// EmitZeros - Emit NumBytes worth of zeros.  This is a convenience
2146449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    /// function that just wraps EmitFill.
2156449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    void EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
2166449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner      EmitFill(NumBytes, 0, AddrSpace);
2176449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    }
2186449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner
219ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner
220fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValueToAlignment - Emit some number of copies of @p Value until
221fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// the byte alignment @p ByteAlignment is reached.
22284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
22384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// If the number of bytes need to emit for the alignment is not a multiple
224fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// of @p ValueSize, then the contents of the emitted fill bytes is
22584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// undefined.
22684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
22784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// This used to implement the .align assembler directive.
22884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
22984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param ByteAlignment - The alignment to reach. This must be a power of
230c29dfa786a23c9ff0827ce4a56b5b178e4087aaaDaniel Dunbar    /// two on some targets.
23184a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param Value - The value to use when filling bytes.
232fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @param ValueSize - The size of the integer (in bytes) to emit for
233fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @p Value. This must match a native machine width.
23484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
23584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// the alignment cannot be reached in this many bytes, no bytes are
23684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// emitted.
23784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
23884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                      unsigned ValueSize = 1,
23984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                      unsigned MaxBytesToEmit = 0) = 0;
2406e72048add2a6464e038121c6c275da37528aa0aKevin Enderby
2416e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
2426e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// is reached.
2436e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    ///
2446e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// This used to align code where the alignment bytes may be executed.  This
2456e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// can emit different bytes for different sizes to optimize execution.
2466e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    ///
2476e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// @param ByteAlignment - The alignment to reach. This must be a power of
2486e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// two on some targets.
2496e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
2506e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// the alignment cannot be reached in this many bytes, no bytes are
2516e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// emitted.
2526e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    virtual void EmitCodeAlignment(unsigned ByteAlignment,
2536e72048add2a6464e038121c6c275da37528aa0aKevin Enderby                                   unsigned MaxBytesToEmit = 0) = 0;
25484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
255fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValueToOffset - Emit some number of copies of @p Value until the
256fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// byte offset @p Offset is reached.
25784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
25884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// This is used to implement assembler directives such as .org.
25984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
2604a1fadaf5207e46d19c64e5773ff8d9e65e607d7Daniel Dunbar    /// @param Offset - The offset to reach. This may be an expression, but the
26184a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// expression must be associated with the current section.
26284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param Value - The value to use when filling bytes.
263821e3334ed3390d931f497300e6a5f1dc21bcfb3Daniel Dunbar    virtual void EmitValueToOffset(const MCExpr *Offset,
26484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                   unsigned char Value = 0) = 0;
26584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
26684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @}
267a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner
268a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// EmitFileDirective - Switch to a new logical file.  This is used to
269a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// implement the '.file "foo.c"' assembler directive.
270a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    virtual void EmitFileDirective(StringRef Filename) = 0;
271a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner
272a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// EmitDwarfFileDirective - Associate a filename with a specified logical
273a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
274a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// directive.
275a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    virtual void EmitDwarfFileDirective(unsigned FileNo,StringRef Filename) = 0;
27684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
277fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitInstruction - Emit the given @p Instruction into the current
278381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// section.
27925e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    virtual void EmitInstruction(const MCInst &Inst) = 0;
280ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar
281ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar    /// Finish - Finish emission of machine code and flush any output.
282ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar    virtual void Finish() = 0;
28325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  };
28425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
285011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  /// createNullStreamer - Create a dummy machine code streamer, which does
286011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  /// nothing. This is useful for timing the assembler front end.
287011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  MCStreamer *createNullStreamer(MCContext &Ctx);
288011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar
289381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// createAsmStreamer - Create a machine code streamer which will print out
290381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// assembly for the native target, suitable for compiling with a native
291381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// assembler.
2929dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
2939dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param InstPrint - If given, the instruction printer to use. If not given
2944c42a6de9f5456cc1b28f2d37db589f580f2adc7Chris Lattner  /// the MCInst representation will be printed.  This method takes ownership of
2954c42a6de9f5456cc1b28f2d37db589f580f2adc7Chris Lattner  /// InstPrint.
2969dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
2979dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param CE - If given, a code emitter to use to show the instruction
2989dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// encoding inline with the assembly.
2999dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
3009dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param ShowInst - Whether to show the MCInst representation inline with
3019dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// the assembly.
30286e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner  MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
303fdab14b10564283028e9bdb628d095feae7fa071Chris Lattner                                bool isLittleEndian, bool isVerboseAsm,
30490edac0e8b35f766599362b6301863229f0ddcdbChris Lattner                                MCInstPrinter *InstPrint = 0,
3059dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar                                MCCodeEmitter *CE = 0,
3065532cf44a012149ce3afce43dbd0651b4d87a505Daniel Dunbar                                bool ShowInst = false);
307381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
308381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// createMachOStream - Create a machine code streamer which will generative
309381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// Mach-O format object files.
3101f3e445184e5ca2aa4295c2a77f2a4e0b957fea1Daniel Dunbar  MCStreamer *createMachOStreamer(MCContext &Ctx, TargetAsmBackend &TAB,
3111f3e445184e5ca2aa4295c2a77f2a4e0b957fea1Daniel Dunbar                                  raw_ostream &OS, MCCodeEmitter *CE);
31225e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
31325e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar} // end namespace llvm
31425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
31525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar#endif
316