MCStreamer: Add a few more "symbol attributes".
[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 MCAtom;
15   class MCContext;
16   class MCValue;
17   class MCInst;
18   class MCSection;
19   class MCSymbol;
20   class raw_ostream;
21
22   /// MCStreamer - Streaming machine code generation interface.
23   class MCStreamer {
24   public:
25     enum SymbolAttr {
26       Global,         /// .globl
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)
35       Weak,           /// .weak
36       WeakDefinition, /// .weak_definition (Apple)
37       WeakReference,  /// .weak_reference (Apple)
38
39       SymbolAttrFirst = Global,
40       SymbolAttrLast = WeakReference
41     };
42
43   private:
44     MCContext &Context;
45
46     MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
47     MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
48
49   protected:
50     MCStreamer(MCContext &Ctx);
51
52   public:
53     virtual ~MCStreamer();
54
55     MCContext &getContext() const { return Context; }
56
57     /// SwitchSection - Set the current section where code is being emitted to
58     /// @param Section.
59     ///
60     /// This corresponds to assembler directives like .section, .text, etc.
61     virtual void SwitchSection(MCSection *Section) = 0;
62
63     /// EmitLabel - Emit a label for @param Symbol into the current section.
64     ///
65     /// This corresponds to an assembler statement such as:
66     ///   foo:
67     ///
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.
71     //
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;
75
76     /// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
77     ///
78     /// This corresponds to an assembler statement such as:
79     ///  symbol = value
80     ///
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.
84     ///
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;
92
93     /// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
94     //
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
98     // matter.
99     virtual void EmitSymbolAttribute(MCSymbol *Symbol,
100                                      SymbolAttr Attribute) = 0;
101
102     /// EmitBytes - Emit @param Length bytes starting at @param Data into the
103     /// output.
104     ///
105     /// This is used to implement assembler directives such as .byte, .ascii,
106     /// etc.
107     virtual void EmitBytes(const char *Data, unsigned Length) = 0;
108
109     /// EmitValue - Emit the expression @param Value into the output as a native
110     /// integer of the given @param Size bytes.
111     ///
112     /// This is used to implement assembler directives such as .word, .quad,
113     /// etc.
114     ///
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;
119
120     /// EmitInstruction - Emit the given @param Instruction into the current
121     /// section.
122     virtual void EmitInstruction(const MCInst &Inst) = 0;
123
124     /// Finish - Finish emission of machine code and flush any output.
125     virtual void Finish() = 0;
126   };
127
128   /// createAsmStreamer - Create a machine code streamer which will print out
129   /// assembly for the native target, suitable for compiling with a native
130   /// assembler.
131   MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS);
132
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.
136
137   /// createMachOStream - Create a machine code streamer which will generative
138   /// Mach-O format object files.
139   MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
140
141   /// createELFStreamer - Create a machine code streamer which will generative
142   /// ELF format object files.
143   MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
144
145 } // end namespace llvm
146
147 #endif