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
21 /// MCStreamer - Streaming machine code generation interface.
26 Hidden, /// .hidden (ELF)
27 IndirectSymbol, /// .indirect_symbol (Apple)
28 Internal, /// .internal (ELF)
29 LazyReference, /// .lazy_reference (Apple)
30 NoDeadStrip, /// .no_dead_strip (Apple)
31 PrivateExtern, /// .private_extern (Apple)
32 Protected, /// .protected (ELF)
33 Reference, /// .reference (Apple)
35 WeakDefinition, /// .weak_definition (Apple)
36 WeakReference, /// .weak_reference (Apple)
38 SymbolAttrFirst = Global,
39 SymbolAttrLast = WeakReference
45 MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
46 MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
49 MCStreamer(MCContext &Ctx);
52 virtual ~MCStreamer();
54 MCContext &getContext() const { return Context; }
56 /// SwitchSection - Set the current section where code is being emitted to
59 /// This corresponds to assembler directives like .section, .text, etc.
60 virtual void SwitchSection(MCSection *Section) = 0;
62 /// EmitLabel - Emit a label for @param Symbol into the current section.
64 /// This corresponds to an assembler statement such as:
67 /// @param Symbol - The symbol to emit. A given symbol should only be
68 /// emitted as a label once, and symbols emitted as a label should never be
69 /// used in an assignment.
71 // FIXME: What to do about the current section? Should we get rid of the
72 // symbol section in the constructor and initialize it here?
73 virtual void EmitLabel(MCSymbol *Symbol) = 0;
75 /// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
77 /// This corresponds to an assembler statement such as:
80 /// The assignment generates no code, but has the side effect of binding the
81 /// value in the current context. For the assembly streamer, this prints the
82 /// binding into the .s file.
84 /// @param Symbol - The symbol being assigned to.
85 /// @param Value - The value for the symbol.
86 /// @param MakeAbsolute - If true, then the symbol should be given the
87 /// absolute value of @param Value, even if @param Value would be
88 /// relocatable expression. This corresponds to the ".set" directive.
89 virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
90 bool MakeAbsolute = false) = 0;
92 /// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
94 // FIXME: This doesn't make much sense, could we just have attributes be on
95 // the symbol and make the printer smart enough to add the right symbols?
96 // This should work as long as the order of attributes in the file doesn't
98 virtual void EmitSymbolAttribute(MCSymbol *Symbol,
99 SymbolAttr Attribute) = 0;
101 /// EmitBytes - Emit @param Length bytes starting at @param Data into the
104 /// This is used to implement assembler directives such as .byte, .ascii,
106 virtual void EmitBytes(const char *Data, unsigned Length) = 0;
108 /// EmitValue - Emit the expression @param Value into the output as a native
109 /// integer of the given @param Size bytes.
111 /// This is used to implement assembler directives such as .word, .quad,
114 /// @param Value - The value to emit.
115 /// @param Size - The size of the integer (in bytes) to emit. This must
116 /// match a native machine width.
117 virtual void EmitValue(const MCValue &Value, unsigned Size) = 0;
119 /// EmitInstruction - Emit the given @param Instruction into the current
121 virtual void EmitInstruction(const MCInst &Inst) = 0;
123 /// Finish - Finish emission of machine code and flush any output.
124 virtual void Finish() = 0;
127 /// createAsmStreamer - Create a machine code streamer which will print out
128 /// assembly for the native target, suitable for compiling with a native
130 MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS);
132 // FIXME: These two may end up getting rolled into a single
133 // createObjectStreamer interface, which implements the assembler backend, and
134 // is parameterized on an output object file writer.
136 /// createMachOStream - Create a machine code streamer which will generative
137 /// Mach-O format object files.
138 MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
140 /// createELFStreamer - Create a machine code streamer which will generative
141 /// ELF format object files.
142 MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
144 } // end namespace llvm