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
22 /// MCStreamer - Streaming machine code generation interface.
34 MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
35 MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
38 MCStreamer(MCContext &Ctx);
41 virtual ~MCStreamer();
43 MCContext &getContext() const { return Context; }
45 /// SwitchSection - Set the current section where code is being emitted to
48 /// This corresponds to assembler directives like .section, .text, etc.
49 virtual void SwitchSection(MCSection *Section) = 0;
51 /// EmitLabel - Emit a label for @param Symbol into the current section.
53 /// This corresponds to an assembler statement such as:
56 /// @param Symbol - The symbol to emit. A given symbol should only be
57 /// emitted as a label once, and symbols emitted as a label should never be
58 /// used in an assignment.
60 // FIXME: What to do about the current section? Should we get rid of the
61 // symbol section in the constructor and initialize it here?
62 virtual void EmitLabel(MCSymbol *Symbol) = 0;
64 /// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
66 /// This corresponds to an assembler statement such as:
69 /// The assignment generates no code, but has the side effect of binding the
70 /// value in the current context. For the assembly streamer, this prints the
71 /// binding into the .s file.
73 /// @param Symbol - The symbol being assigned to.
74 /// @param Value - The value for the symbol.
75 /// @param MakeAbsolute - If true, then the symbol should be given the
76 /// absolute value of @param Value, even if @param Value would be
77 /// relocatable expression. This corresponds to the ".set" directive.
78 virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
79 bool MakeAbsolute = false) = 0;
81 /// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
83 // FIXME: This doesn't make much sense, could we just have attributes be on
84 // the symbol and make the printer smart enough to add the right symbols?
85 // This should work as long as the order of attributes in the file doesn't
87 virtual void EmitSymbolAttribute(MCSymbol *Symbol,
88 SymbolAttr Attribute) = 0;
90 /// EmitBytes - Emit @param Length bytes starting at @param Data into the
93 /// This is used to implement assembler directives such as .byte, .ascii,
95 virtual void EmitBytes(const char *Data, unsigned Length) = 0;
97 /// EmitValue - Emit the expression @param Value into the output as a native
98 /// integer of the given @param Size bytes.
100 /// This is used to implement assembler directives such as .word, .quad,
103 /// @param Value - The value to emit.
104 /// @param Size - The size of the integer (in bytes) to emit. This must
105 /// match a native machine width.
106 virtual void EmitValue(const MCValue &Value, unsigned Size) = 0;
108 /// EmitInstruction - Emit the given @param Instruction into the current
110 virtual void EmitInstruction(const MCInst &Inst) = 0;
112 /// Finish - Finish emission of machine code and flush any output.
113 virtual void Finish() = 0;
116 /// createAsmStreamer - Create a machine code streamer which will print out
117 /// assembly for the native target, suitable for compiling with a native
119 MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS);
121 // FIXME: These two may end up getting rolled into a single
122 // createObjectStreamer interface, which implements the assembler backend, and
123 // is parameterized on an output object file writer.
125 /// createMachOStream - Create a machine code streamer which will generative
126 /// Mach-O format object files.
127 MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
129 /// createELFStreamer - Create a machine code streamer which will generative
130 /// ELF format object files.
131 MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
133 } // end namespace llvm