MCStreamer.h revision 6b2e257e74b2c8e2f93bb244e0c80cb73005b74a
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;
30b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner  class 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
6591bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// isVerboseAsm - Return true if this streamer supports verbose assembly
6691bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// and if it is enabled.
6756591ab218639d8a6e4c756ca37adaf20215c3b6Chris Lattner    virtual bool isVerboseAsm() const { return false; }
6891bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner
6991bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// hasRawTextSupport - Return true if this asm streamer supports emitting
7091bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// unformatted text to the .s file with EmitRawText.
7191bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    virtual bool hasRawTextSupport() const { return false; }
720fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner
73d32c7cfa248f685e6e3064c0958dc2f0c31a4df6Chris Lattner    /// AddComment - Add a comment that can be emitted to the generated .s
7486e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// file if applicable as a QoI issue to make the output of the compiler
7586e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// more readable.  This only affects the MCAsmStreamer, and only when
7686e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// verbose assembly output is enabled.
7786e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    ///
7886e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// If the comment includes embedded \n's, they will each get the comment
7986e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner    /// prefix as appropriate.  The added comment should not end with a \n.
80d32c7cfa248f685e6e3064c0958dc2f0c31a4df6Chris Lattner    virtual void AddComment(const Twine &T) {}
8186e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner
82d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// GetCommentOS - Return a raw_ostream that comments can be written to.
83d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// Unlike AddComment, you are required to terminate comments with \n if you
84d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    /// use this method.
85d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner    virtual raw_ostream &GetCommentOS();
86d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner
870fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
880fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    virtual void AddBlankLine() {}
890fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner
900fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner    /// @}
910fd90fd8d1c2143a763dee509c66a5b3c74088b1Chris Lattner
9284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @name Symbol & Section Management
9384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @{
947092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar
956a4824c466bbfbcbe7dc4d95ec1e23a14ec73d87Dan Gohman    /// getCurrentSection - Return the current section that the streamer is
967092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// emitting code to.
977092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    const MCSection *getCurrentSection() const { return CurSection; }
9884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
99381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// SwitchSection - Set the current section where code is being emitted to
100fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @p Section.  This is required to update CurSection.
101381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
102381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to assembler directives like .section, .text, etc.
103975780bb595b57a45a8e6d72d8151b436314ce22Chris Lattner    virtual void SwitchSection(const MCSection *Section) = 0;
104dabf07c70a5e13a4560d75667fa5c7db28921a92Chris Lattner
105fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitLabel - Emit a label for @p Symbol into the current section.
106381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
107381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to an assembler statement such as:
108381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///   foo:
109381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
110381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Symbol - The symbol to emit. A given symbol should only be
111381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// emitted as a label once, and symbols emitted as a label should never be
112381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// used in an assignment.
113ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar    virtual void EmitLabel(MCSymbol *Symbol) = 0;
114381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
115fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitAssemblerFlag - Note in the output the specified @p Flag
116a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner    virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
117a5c783280f83df5c60a8ed9e32c61b05a11048e3Kevin Enderby
118fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
119381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
120381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This corresponds to an assembler statement such as:
121381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///  symbol = value
122381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
123381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// The assignment generates no code, but has the side effect of binding the
124381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// value in the current context. For the assembly streamer, this prints the
125381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// binding into the .s file.
126381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
127381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Symbol - The symbol being assigned to.
128381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Value - The value for the symbol.
129821e3334ed3390d931f497300e6a5f1dc21bcfb3Daniel Dunbar    virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
13025e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
131fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
132a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar    virtual void EmitSymbolAttribute(MCSymbol *Symbol,
133a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner                                     MCSymbolAttr Attribute) = 0;
13425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
135fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
13695cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    ///
13795cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    /// @param Symbol - The symbol to have its n_desc field set.
13895cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    /// @param DescValue - The value to set into the n_desc field.
13995cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby    virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
14095cf30c444707634bbd950f13405b6c8bcfe496bKevin Enderby
141b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
142b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    ///
143b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// @param Symbol - The symbol to have its External & Type fields set.
144b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
145b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
146b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
147b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    ///
148b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// @param StorageClass - The storage class the symbol should have.
149b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
150b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
151b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// EmitCOFFSymbolType - Emit the type of the symbol.
152b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    ///
153b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
154b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void EmitCOFFSymbolType(int Type) = 0;
155b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
156b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    /// EndCOFFSymbolDef - Marks the end of the symbol definition.
157b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    virtual void EndCOFFSymbolDef() = 0;
158b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner
15999328add833807f12a4950c7de29fb2a5df04703Chris Lattner    /// EmitELFSize - Emit an ELF .size directive.
16099328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///
16199328add833807f12a4950c7de29fb2a5df04703Chris Lattner    /// This corresponds to an assembler statement such as:
16299328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///  .size symbol, expression
16399328add833807f12a4950c7de29fb2a5df04703Chris Lattner    ///
16499328add833807f12a4950c7de29fb2a5df04703Chris Lattner    virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
16599328add833807f12a4950c7de29fb2a5df04703Chris Lattner
1669eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// EmitCommonSymbol - Emit a common symbol.
1674e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    ///
1684e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    /// @param Symbol - The common symbol to emit.
1694e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner    /// @param Size - The size of the common symbol.
1707092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// @param ByteAlignment - The alignment of the symbol if
1719eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// non-zero. This must be a power of 2.
1729eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
1737092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar                                  unsigned ByteAlignment) = 0;
1744e4db7adfc9858a8f77f841c7467bc6fcbb8110eChris Lattner
1759eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
1769eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    ///
1779eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// @param Symbol - The common symbol to emit.
1789eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    /// @param Size - The size of the common symbol.
1799eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner    virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) = 0;
1809eb158d5b4cd4f6fc80912e2dd77bdf13c3ca0e7Chris Lattner
1810df4a80e2063424929bbfaa61dd7973062218ad4Eric Christopher    /// EmitZerofill - Emit the zerofill section and an optional symbol.
1829be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    ///
1839be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Section - The zerofill section to create and or to put the symbol
1849be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Symbol - The zerofill symbol to emit, if non-NULL.
1859be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner    /// @param Size - The size of the zerofill symbol.
1867092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// @param ByteAlignment - The alignment of the zerofill symbol if
1877092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// non-zero. This must be a power of 2 on some targets.
1888751b94ffbd9c49df8949a37f78d6bd0be87b256Daniel Dunbar    virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
1897092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar                              unsigned Size = 0,unsigned ByteAlignment = 0) = 0;
1909be3fee2bdc3126fb87e4e1b31935905f4bcc4d0Chris Lattner
191482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
192482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    ///
1934d01cbe93b0e1a349b5c2881f1b319963f9e0504Eric Christopher    /// @param Section - The thread local common section.
194482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// @param Symbol - The thread local common symbol to emit.
195482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// @param Size - The size of the symbol.
196482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// @param ByteAlignment - The alignment of the thread local common symbol
197482eba054ab3543ee0e1f453d3d6441092f4b76dEric Christopher    /// if non-zero.  This must be a power of 2 on some targets.
1984d01cbe93b0e1a349b5c2881f1b319963f9e0504Eric Christopher    virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
1990df4a80e2063424929bbfaa61dd7973062218ad4Eric Christopher                                uint64_t Size, unsigned ByteAlignment = 0) = 0;
20084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @}
20184a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @name Generating Data
20284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @{
20384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
2047092c7e1dcf9d05741b400dd54bbd7d3419773b2Daniel Dunbar    /// EmitBytes - Emit the bytes in \arg Data into the output.
205381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
206381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This is used to implement assembler directives such as .byte, .ascii,
207381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// etc.
208aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner    virtual void EmitBytes(StringRef Data, unsigned AddrSpace) = 0;
209381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
210fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValue - Emit the expression @p Value into the output as a native
211fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// integer of the given @p Size bytes.
212381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
213381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// This is used to implement assembler directives such as .word, .quad,
214381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// etc.
215381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    ///
216381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Value - The value to emit.
217381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// @param Size - The size of the integer (in bytes) to emit. This must
218381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// match a native machine width.
219aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner    virtual void EmitValue(const MCExpr *Value, unsigned Size,
220c257c669df0412606bfd06668367a0fc7f96df0aDaniel Dunbar                           unsigned AddrSpace = 0) = 0;
221381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
22232ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner    /// EmitIntValue - Special case of EmitValue that avoids the client having
22332ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner    /// to pass in a MCExpr for constant integers.
224c257c669df0412606bfd06668367a0fc7f96df0aDaniel Dunbar    virtual void EmitIntValue(uint64_t Value, unsigned Size,
225c257c669df0412606bfd06668367a0fc7f96df0aDaniel Dunbar                              unsigned AddrSpace = 0);
226c257c669df0412606bfd06668367a0fc7f96df0aDaniel Dunbar
2276cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    /// EmitSymbolValue - Special case of EmitValue that avoids the client
2286cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    /// having to pass in a MCExpr for MCSymbols.
2296cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner    virtual void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
2306cde3e6e993126df756e3be5b9ef43540b904644Chris Lattner                                 unsigned AddrSpace);
23132ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner
232fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitGPRel32Value - Emit the expression @p Value into the output as a
233718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// gprel32 (32-bit GP relative) value.
234718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    ///
235718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// This is used to implement assembler directives such as .gprel32 on
236718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    /// targets that support them.
237718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner    virtual void EmitGPRel32Value(const MCExpr *Value) = 0;
238718fb59801320b8cb22363d115b5fc5ec40dc1f5Chris Lattner
239ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner    /// EmitFill - Emit NumBytes bytes worth of the value specified by
240ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner    /// FillValue.  This implements directives such as '.space'.
241aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner    virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
242aaec205b87637cd0d59d4f11630db603686eb73dChris Lattner                          unsigned AddrSpace);
243ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner
2446449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    /// EmitZeros - Emit NumBytes worth of zeros.  This is a convenience
2456449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    /// function that just wraps EmitFill.
2466449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    void EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
2476449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner      EmitFill(NumBytes, 0, AddrSpace);
2486449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner    }
2496449abfbc86310edbbe0b5ffb3fad5c14301307fChris Lattner
250ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner
251fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValueToAlignment - Emit some number of copies of @p Value until
252fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// the byte alignment @p ByteAlignment is reached.
25384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
25484a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// If the number of bytes need to emit for the alignment is not a multiple
255fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// of @p ValueSize, then the contents of the emitted fill bytes is
25684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// undefined.
25784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
25884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// This used to implement the .align assembler directive.
25984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
26084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param ByteAlignment - The alignment to reach. This must be a power of
261c29dfa786a23c9ff0827ce4a56b5b178e4087aaaDaniel Dunbar    /// two on some targets.
26284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param Value - The value to use when filling bytes.
263fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @param ValueSize - The size of the integer (in bytes) to emit for
264fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// @p Value. This must match a native machine width.
26584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
26684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// the alignment cannot be reached in this many bytes, no bytes are
26784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// emitted.
26884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
26984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                      unsigned ValueSize = 1,
27084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                      unsigned MaxBytesToEmit = 0) = 0;
2716e72048add2a6464e038121c6c275da37528aa0aKevin Enderby
2726e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
2736e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// is reached.
2746e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    ///
2756e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// This used to align code where the alignment bytes may be executed.  This
2766e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// can emit different bytes for different sizes to optimize execution.
2776e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    ///
2786e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// @param ByteAlignment - The alignment to reach. This must be a power of
2796e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// two on some targets.
2806e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
2816e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// the alignment cannot be reached in this many bytes, no bytes are
2826e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    /// emitted.
2836e72048add2a6464e038121c6c275da37528aa0aKevin Enderby    virtual void EmitCodeAlignment(unsigned ByteAlignment,
2846e72048add2a6464e038121c6c275da37528aa0aKevin Enderby                                   unsigned MaxBytesToEmit = 0) = 0;
28584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
286fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitValueToOffset - Emit some number of copies of @p Value until the
287fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// byte offset @p Offset is reached.
28884a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
28984a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// This is used to implement assembler directives such as .org.
29084a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    ///
2914a1fadaf5207e46d19c64e5773ff8d9e65e607d7Daniel Dunbar    /// @param Offset - The offset to reach. This may be an expression, but the
29284a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// expression must be associated with the current section.
29384a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @param Value - The value to use when filling bytes.
294821e3334ed3390d931f497300e6a5f1dc21bcfb3Daniel Dunbar    virtual void EmitValueToOffset(const MCExpr *Offset,
29584a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar                                   unsigned char Value = 0) = 0;
29684a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
29784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar    /// @}
298a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner
299a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// EmitFileDirective - Switch to a new logical file.  This is used to
300a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// implement the '.file "foo.c"' assembler directive.
301a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    virtual void EmitFileDirective(StringRef Filename) = 0;
302a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner
303a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// EmitDwarfFileDirective - Associate a filename with a specified logical
304a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
305a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    /// directive.
306a6594fc7156c0afbe6fd5a6aab9b099aaf950c53Chris Lattner    virtual void EmitDwarfFileDirective(unsigned FileNo,StringRef Filename) = 0;
30784a2926fb7ab388d688a133b0b375a26e669fd55Daniel Dunbar
308fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// EmitInstruction - Emit the given @p Instruction into the current
309381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar    /// section.
31025e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar    virtual void EmitInstruction(const MCInst &Inst) = 0;
311ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar
31291bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// EmitRawText - If this file is backed by a assembly streamer, this dumps
31391bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// the specified string in the output .s file.  This capability is
31491bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
31591bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner    virtual void EmitRawText(StringRef String);
31658bc4dd4a91443ddd3120b0a2f1801ad4d6aae1cChris Lattner    void EmitRawText(const Twine &String);
31791bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner
3184b1000d117f1b7cc5411bc251d141fe182a4ae1cDan Gohman    /// Finish - Finish emission of machine code.
319ba1da8a7b10b8a7df04f3ca47ca36ad18adad80eDaniel Dunbar    virtual void Finish() = 0;
32025e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar  };
32125e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
322011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  /// createNullStreamer - Create a dummy machine code streamer, which does
323011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  /// nothing. This is useful for timing the assembler front end.
324011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar  MCStreamer *createNullStreamer(MCContext &Ctx);
325011e4db845b5c4166142338c77adc8ac03e5e041Daniel Dunbar
326381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// createAsmStreamer - Create a machine code streamer which will print out
327381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// assembly for the native target, suitable for compiling with a native
328381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// assembler.
3299dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
3309dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param InstPrint - If given, the instruction printer to use. If not given
3314c42a6de9f5456cc1b28f2d37db589f580f2adc7Chris Lattner  /// the MCInst representation will be printed.  This method takes ownership of
3324c42a6de9f5456cc1b28f2d37db589f580f2adc7Chris Lattner  /// InstPrint.
3339dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
3349dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param CE - If given, a code emitter to use to show the instruction
3351abcd06856df324eac98d4bf5ba673fb77ae6a11Benjamin Kramer  /// encoding inline with the assembly. This method takes ownership of \arg CE.
3369dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  ///
3379dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// \param ShowInst - Whether to show the MCInst representation inline with
3389dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar  /// the assembly.
33986e2211d0a496f470ea1d320161c8dc43593c5c6Chris Lattner  MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
340fdab14b10564283028e9bdb628d095feae7fa071Chris Lattner                                bool isLittleEndian, bool isVerboseAsm,
34190edac0e8b35f766599362b6301863229f0ddcdbChris Lattner                                MCInstPrinter *InstPrint = 0,
3429dee8e3009408fd08c656558397a8ac8604139baDaniel Dunbar                                MCCodeEmitter *CE = 0,
3435532cf44a012149ce3afce43dbd0651b4d87a505Daniel Dunbar                                bool ShowInst = false);
344381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar
345d86e6ac9892ee61742d85f9f14f1179216d2e47bDan Gohman  /// createMachOStreamer - Create a machine code streamer which will generate
346381e92c66a98ee766ea53039b0cd8ce3bde7be2dDaniel Dunbar  /// Mach-O format object files.
3471abcd06856df324eac98d4bf5ba673fb77ae6a11Benjamin Kramer  ///
3481abcd06856df324eac98d4bf5ba673fb77ae6a11Benjamin Kramer  /// Takes ownership of \arg TAB and \arg CE.
3491f3e445184e5ca2aa4295c2a77f2a4e0b957fea1Daniel Dunbar  MCStreamer *createMachOStreamer(MCContext &Ctx, TargetAsmBackend &TAB,
350ac2884a717daf3ad2aa8425320795d661e8a980bDaniel Dunbar                                  raw_ostream &OS, MCCodeEmitter *CE,
351ac2884a717daf3ad2aa8425320795d661e8a980bDaniel Dunbar                                  bool RelaxAll = false);
35225e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
353eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner  /// createWinCOFFStreamer - Create a machine code streamer which will
354eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner  /// generate Microsoft COFF format object files.
3551abcd06856df324eac98d4bf5ba673fb77ae6a11Benjamin Kramer  ///
3561abcd06856df324eac98d4bf5ba673fb77ae6a11Benjamin Kramer  /// Takes ownership of \arg TAB and \arg CE.
357eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner  MCStreamer *createWinCOFFStreamer(MCContext &Ctx,
358eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner                                    TargetAsmBackend &TAB,
359e2195d8b357d7081edb5eb09d1d6e9d7b4bfc308Michael J. Spencer                                    MCCodeEmitter &CE, raw_ostream &OS,
360e2195d8b357d7081edb5eb09d1d6e9d7b4bfc308Michael J. Spencer                                    bool RelaxAll = false);
361eb72dcaef7423069cf8f9e802fa8de64dc8f8f30Chris Lattner
3626b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming  /// createELFStreamer - Create a machine code streamer which will generate
3636b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming  /// ELF format object files.
3646b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming  MCStreamer *createELFStreamer(MCContext &Ctx, TargetAsmBackend &TAB,
3656b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming				raw_ostream &OS, MCCodeEmitter *CE,
3666b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming				bool RelaxAll = false);
3676b2e257e74b2c8e2f93bb244e0c80cb73005b74aMatt Fleming
368fdb5a8617996a20370756962e34c2e80176d6e87Daniel Dunbar  /// createLoggingStreamer - Create a machine code streamer which just logs the
369fdb5a8617996a20370756962e34c2e80176d6e87Daniel Dunbar  /// API calls and then dispatches to another streamer.
370fdb5a8617996a20370756962e34c2e80176d6e87Daniel Dunbar  ///
371fdb5a8617996a20370756962e34c2e80176d6e87Daniel Dunbar  /// The new streamer takes ownership of the \arg Child.
372fdb5a8617996a20370756962e34c2e80176d6e87Daniel Dunbar  MCStreamer *createLoggingStreamer(MCStreamer *Child, raw_ostream &OS);
373fdb5a8617996a20370756962e34c2e80176d6e87Daniel Dunbar
37425e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar} // end namespace llvm
37525e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar
37625e0d8f755736b0a17400adbdd367aee89fbecfcDaniel Dunbar#endif
377