1 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCSTREAMER_H
11 #define LLVM_MC_MCSTREAMER_H
13 #include "llvm/Support/DataTypes.h"
23 /// MCStreamer - Streaming machine code generation interface.
28 Hidden, /// .hidden (ELF)
29 IndirectSymbol, /// .indirect_symbol (Apple)
30 Internal, /// .internal (ELF)
31 LazyReference, /// .lazy_reference (Apple)
32 NoDeadStrip, /// .no_dead_strip (Apple)
33 PrivateExtern, /// .private_extern (Apple)
34 Protected, /// .protected (ELF)
35 Reference, /// .reference (Apple)
37 WeakDefinition, /// .weak_definition (Apple)
38 WeakReference, /// .weak_reference (Apple)
40 SymbolAttrFirst = Global,
41 SymbolAttrLast = WeakReference
47 MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
48 MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
51 MCStreamer(MCContext &Ctx);
54 virtual ~MCStreamer();
56 MCContext &getContext() const { return Context; }
58 /// @name Symbol & Section Management
61 /// SwitchSection - Set the current section where code is being emitted to
64 /// This corresponds to assembler directives like .section, .text, etc.
65 virtual void SwitchSection(MCSection *Section) = 0;
67 /// EmitLabel - Emit a label for @param Symbol into the current section.
69 /// This corresponds to an assembler statement such as:
72 /// @param Symbol - The symbol to emit. A given symbol should only be
73 /// emitted as a label once, and symbols emitted as a label should never be
74 /// used in an assignment.
76 // FIXME: What to do about the current section? Should we get rid of the
77 // symbol section in the constructor and initialize it here?
78 virtual void EmitLabel(MCSymbol *Symbol) = 0;
80 /// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
82 /// This corresponds to an assembler statement such as:
85 /// The assignment generates no code, but has the side effect of binding the
86 /// value in the current context. For the assembly streamer, this prints the
87 /// binding into the .s file.
89 /// @param Symbol - The symbol being assigned to.
90 /// @param Value - The value for the symbol.
91 /// @param MakeAbsolute - If true, then the symbol should be given the
92 /// absolute value of @param Value, even if @param Value would be
93 /// relocatable expression. This corresponds to the ".set" directive.
94 virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
95 bool MakeAbsolute = false) = 0;
97 /// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
99 // FIXME: This doesn't make much sense, could we just have attributes be on
100 // the symbol and make the printer smart enough to add the right symbols?
101 // This should work as long as the order of attributes in the file doesn't
103 virtual void EmitSymbolAttribute(MCSymbol *Symbol,
104 SymbolAttr Attribute) = 0;
107 /// @name Generating Data
110 /// EmitBytes - Emit @param Length bytes starting at @param Data into the
113 /// This is used to implement assembler directives such as .byte, .ascii,
115 virtual void EmitBytes(const char *Data, unsigned Length) = 0;
117 /// EmitValue - Emit the expression @param Value into the output as a native
118 /// integer of the given @param Size bytes.
120 /// This is used to implement assembler directives such as .word, .quad,
123 /// @param Value - The value to emit.
124 /// @param Size - The size of the integer (in bytes) to emit. This must
125 /// match a native machine width.
126 virtual void EmitValue(const MCValue &Value, unsigned Size) = 0;
128 /// EmitValueToAlignment - Emit some number of copies of @param Value until
129 /// the byte alignment @param ByteAlignment is reached.
131 /// If the number of bytes need to emit for the alignment is not a multiple
132 /// of @param ValueSize, then the contents of the emitted fill bytes is
135 /// This used to implement the .align assembler directive.
137 /// @param ByteAlignment - The alignment to reach. This must be a power of
139 /// @param Value - The value to use when filling bytes.
140 /// @param Size - The size of the integer (in bytes) to emit for @param
141 /// Value. This must match a native machine width.
142 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
143 /// the alignment cannot be reached in this many bytes, no bytes are
145 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
146 unsigned ValueSize = 1,
147 unsigned MaxBytesToEmit = 0) = 0;
149 /// EmitValueToOffset - Emit some number of copies of @param Value until the
150 /// byte offset @param Offset is reached.
152 /// This is used to implement assembler directives such as .org.
154 /// @param Offset - The offset to reach.This may be an expression, but the
155 /// expression must be associated with the current section.
156 /// @param Value - The value to use when filling bytes.
158 // FIXME: How are we going to signal failures out of this?
159 virtual void EmitValueToOffset(const MCValue &Offset,
160 unsigned char Value = 0) = 0;
164 /// EmitInstruction - Emit the given @param Instruction into the current
166 virtual void EmitInstruction(const MCInst &Inst) = 0;
168 /// Finish - Finish emission of machine code and flush any output.
169 virtual void Finish() = 0;
172 /// createAsmStreamer - Create a machine code streamer which will print out
173 /// assembly for the native target, suitable for compiling with a native
175 MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS);
177 // FIXME: These two may end up getting rolled into a single
178 // createObjectStreamer interface, which implements the assembler backend, and
179 // is parameterized on an output object file writer.
181 /// createMachOStream - Create a machine code streamer which will generative
182 /// Mach-O format object files.
183 MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
185 /// createELFStreamer - Create a machine code streamer which will generative
186 /// ELF format object files.
187 MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
189 } // end namespace llvm