We decided to not worry about Atoms for now, it should be straightforward to
[oota-llvm.git] / include / llvm / MC / MCStreamer.h
1 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCSTREAMER_H
11 #define LLVM_MC_MCSTREAMER_H
12
13 namespace llvm {
14   class MCContext;
15   class MCValue;
16   class MCInst;
17   class MCSection;
18   class MCSymbol;
19   class raw_ostream;
20
21   /// MCStreamer - Streaming machine code generation interface.
22   class MCStreamer {
23   public:
24     enum SymbolAttr {
25       Global,         /// .globl
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)
34       Weak,           /// .weak
35       WeakDefinition, /// .weak_definition (Apple)
36       WeakReference,  /// .weak_reference (Apple)
37
38       SymbolAttrFirst = Global,
39       SymbolAttrLast = WeakReference
40     };
41
42   private:
43     MCContext &Context;
44
45     MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
46     MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
47
48   protected:
49     MCStreamer(MCContext &Ctx);
50
51   public:
52     virtual ~MCStreamer();
53
54     MCContext &getContext() const { return Context; }
55
56     /// SwitchSection - Set the current section where code is being emitted to
57     /// @param Section.
58     ///
59     /// This corresponds to assembler directives like .section, .text, etc.
60     virtual void SwitchSection(MCSection *Section) = 0;
61
62     /// EmitLabel - Emit a label for @param Symbol into the current section.
63     ///
64     /// This corresponds to an assembler statement such as:
65     ///   foo:
66     ///
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.
70     //
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;
74
75     /// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
76     ///
77     /// This corresponds to an assembler statement such as:
78     ///  symbol = value
79     ///
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.
83     ///
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;
91
92     /// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
93     //
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
97     // matter.
98     virtual void EmitSymbolAttribute(MCSymbol *Symbol,
99                                      SymbolAttr Attribute) = 0;
100
101     /// EmitBytes - Emit @param Length bytes starting at @param Data into the
102     /// output.
103     ///
104     /// This is used to implement assembler directives such as .byte, .ascii,
105     /// etc.
106     virtual void EmitBytes(const char *Data, unsigned Length) = 0;
107
108     /// EmitValue - Emit the expression @param Value into the output as a native
109     /// integer of the given @param Size bytes.
110     ///
111     /// This is used to implement assembler directives such as .word, .quad,
112     /// etc.
113     ///
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;
118
119     /// EmitInstruction - Emit the given @param Instruction into the current
120     /// section.
121     virtual void EmitInstruction(const MCInst &Inst) = 0;
122
123     /// Finish - Finish emission of machine code and flush any output.
124     virtual void Finish() = 0;
125   };
126
127   /// createAsmStreamer - Create a machine code streamer which will print out
128   /// assembly for the native target, suitable for compiling with a native
129   /// assembler.
130   MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS);
131
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.
135
136   /// createMachOStream - Create a machine code streamer which will generative
137   /// Mach-O format object files.
138   MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
139
140   /// createELFStreamer - Create a machine code streamer which will generative
141   /// ELF format object files.
142   MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
143
144 } // end namespace llvm
145
146 #endif