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.
27 Hidden, /// .hidden (ELF)
28 IndirectSymbol, /// .indirect_symbol (Apple)
29 Internal, /// .internal (ELF)
30 LazyReference, /// .lazy_reference (Apple)
31 NoDeadStrip, /// .no_dead_strip (Apple)
32 PrivateExtern, /// .private_extern (Apple)
33 Protected, /// .protected (ELF)
34 Reference, /// .reference (Apple)
36 WeakDefinition, /// .weak_definition (Apple)
37 WeakReference, /// .weak_reference (Apple)
39 SymbolAttrFirst = Global,
40 SymbolAttrLast = WeakReference
46 MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
47 MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
50 MCStreamer(MCContext &Ctx);
53 virtual ~MCStreamer();
55 MCContext &getContext() const { return Context; }
57 /// SwitchSection - Set the current section where code is being emitted to
60 /// This corresponds to assembler directives like .section, .text, etc.
61 virtual void SwitchSection(MCSection *Section) = 0;
63 /// EmitLabel - Emit a label for @param Symbol into the current section.
65 /// This corresponds to an assembler statement such as:
68 /// @param Symbol - The symbol to emit. A given symbol should only be
69 /// emitted as a label once, and symbols emitted as a label should never be
70 /// used in an assignment.
72 // FIXME: What to do about the current section? Should we get rid of the
73 // symbol section in the constructor and initialize it here?
74 virtual void EmitLabel(MCSymbol *Symbol) = 0;
76 /// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
78 /// This corresponds to an assembler statement such as:
81 /// The assignment generates no code, but has the side effect of binding the
82 /// value in the current context. For the assembly streamer, this prints the
83 /// binding into the .s file.
85 /// @param Symbol - The symbol being assigned to.
86 /// @param Value - The value for the symbol.
87 /// @param MakeAbsolute - If true, then the symbol should be given the
88 /// absolute value of @param Value, even if @param Value would be
89 /// relocatable expression. This corresponds to the ".set" directive.
90 virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
91 bool MakeAbsolute = false) = 0;
93 /// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
95 // FIXME: This doesn't make much sense, could we just have attributes be on
96 // the symbol and make the printer smart enough to add the right symbols?
97 // This should work as long as the order of attributes in the file doesn't
99 virtual void EmitSymbolAttribute(MCSymbol *Symbol,
100 SymbolAttr Attribute) = 0;
102 /// EmitBytes - Emit @param Length bytes starting at @param Data into the
105 /// This is used to implement assembler directives such as .byte, .ascii,
107 virtual void EmitBytes(const char *Data, unsigned Length) = 0;
109 /// EmitValue - Emit the expression @param Value into the output as a native
110 /// integer of the given @param Size bytes.
112 /// This is used to implement assembler directives such as .word, .quad,
115 /// @param Value - The value to emit.
116 /// @param Size - The size of the integer (in bytes) to emit. This must
117 /// match a native machine width.
118 virtual void EmitValue(const MCValue &Value, unsigned Size) = 0;
120 /// EmitInstruction - Emit the given @param Instruction into the current
122 virtual void EmitInstruction(const MCInst &Inst) = 0;
124 /// Finish - Finish emission of machine code and flush any output.
125 virtual void Finish() = 0;
128 /// createAsmStreamer - Create a machine code streamer which will print out
129 /// assembly for the native target, suitable for compiling with a native
131 MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS);
133 // FIXME: These two may end up getting rolled into a single
134 // createObjectStreamer interface, which implements the assembler backend, and
135 // is parameterized on an output object file writer.
137 /// createMachOStream - Create a machine code streamer which will generative
138 /// Mach-O format object files.
139 MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
141 /// createELFStreamer - Create a machine code streamer which will generative
142 /// ELF format object files.
143 MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
145 } // end namespace llvm