Add ArrayRef variant.
[oota-llvm.git] / lib / MC / MCELFStreamer.h
1 //===- lib/MC/MCELFStreamer.h - ELF Object Output -------------------------===//
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 // This file assembles .s files and emits ELF .o object files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCELFSTREAMER_H
15 #define LLVM_MC_MCELFSTREAMER_H
16
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/MC/MCAssembler.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCObjectStreamer.h"
22 #include "llvm/MC/MCSectionELF.h"
23
24 namespace llvm {
25
26 class MCELFStreamer : public MCObjectStreamer {
27 public:
28   MCELFStreamer(MCContext &Context, TargetAsmBackend &TAB,
29                   raw_ostream &OS, MCCodeEmitter *Emitter)
30     : MCObjectStreamer(Context, TAB, OS, Emitter) {}
31
32   ~MCELFStreamer() {}
33
34   /// @name MCStreamer Interface
35   /// @{
36
37   virtual void InitSections();
38   virtual void ChangeSection(const MCSection *Section);
39   virtual void EmitLabel(MCSymbol *Symbol);
40   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
41   virtual void EmitThumbFunc(MCSymbol *Func);
42   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
43   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
44   virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
45   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
46     assert(0 && "ELF doesn't support this directive");
47   }
48   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
49                                 unsigned ByteAlignment);
50   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {
51     assert(0 && "ELF doesn't support this directive");
52   }
53
54   virtual void EmitCOFFSymbolStorageClass(int StorageClass) {
55     assert(0 && "ELF doesn't support this directive");
56   }
57
58   virtual void EmitCOFFSymbolType(int Type) {
59     assert(0 && "ELF doesn't support this directive");
60   }
61
62   virtual void EndCOFFSymbolDef() {
63     assert(0 && "ELF doesn't support this directive");
64   }
65
66   virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
67      MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
68      SD.setSize(Value);
69   }
70
71   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
72
73   virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
74                             unsigned Size = 0, unsigned ByteAlignment = 0) {
75     assert(0 && "ELF doesn't support this directive");
76   }
77   virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
78                               uint64_t Size, unsigned ByteAlignment = 0) {
79     assert(0 && "ELF doesn't support this directive");
80   }
81   virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
82   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
83                                     unsigned ValueSize = 1,
84                                     unsigned MaxBytesToEmit = 0);
85   virtual void EmitCodeAlignment(unsigned ByteAlignment,
86                                  unsigned MaxBytesToEmit = 0);
87
88   virtual void EmitFileDirective(StringRef Filename);
89
90   virtual void Finish();
91
92 private:
93   virtual void EmitInstToFragment(const MCInst &Inst);
94   virtual void EmitInstToData(const MCInst &Inst);
95
96   void fixSymbolsInTLSFixups(const MCExpr *expr);
97
98   struct LocalCommon {
99     MCSymbolData *SD;
100     uint64_t Size;
101     unsigned ByteAlignment;
102   };
103   std::vector<LocalCommon> LocalCommons;
104
105   SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet;
106   /// @}
107   void SetSection(StringRef Section, unsigned Type, unsigned Flags,
108                   SectionKind Kind) {
109     SwitchSection(getContext().getELFSection(Section, Type, Flags, Kind));
110   }
111
112   void SetSectionData() {
113     SetSection(".data", ELF::SHT_PROGBITS,
114                ELF::SHF_WRITE |ELF::SHF_ALLOC,
115                SectionKind::getDataRel());
116     EmitCodeAlignment(4, 0);
117   }
118   void SetSectionText() {
119     SetSection(".text", ELF::SHT_PROGBITS,
120                ELF::SHF_EXECINSTR |
121                ELF::SHF_ALLOC, SectionKind::getText());
122     EmitCodeAlignment(4, 0);
123   }
124   void SetSectionBss() {
125     SetSection(".bss", ELF::SHT_NOBITS,
126                ELF::SHF_WRITE |
127                ELF::SHF_ALLOC, SectionKind::getBSS());
128     EmitCodeAlignment(4, 0);
129   }
130 };
131
132 } // end llvm namespace
133
134 #endif
135 //===- lib/MC/MCELFStreamer.h - ELF Object Output -------------------------===//
136 //
137 //                     The LLVM Compiler Infrastructure
138 //
139 // This file is distributed under the University of Illinois Open Source
140 // License. See LICENSE.TXT for details.
141 //
142 //===----------------------------------------------------------------------===//
143 //
144 // This file assembles .s files and emits ELF .o object files.
145 //
146 //===----------------------------------------------------------------------===//
147
148 #ifndef LLVM_MC_MCELFSTREAMER_H
149 #define LLVM_MC_MCELFSTREAMER_H
150
151 #include "llvm/ADT/SmallPtrSet.h"
152 #include "llvm/ADT/DenseMap.h"
153 #include "llvm/MC/MCAssembler.h"
154 #include "llvm/MC/MCContext.h"
155 #include "llvm/MC/MCObjectStreamer.h"
156 #include "llvm/MC/MCSectionELF.h"
157
158 namespace llvm {
159
160 class MCELFStreamer : public MCObjectStreamer {
161 public:
162   MCELFStreamer(MCContext &Context, TargetAsmBackend &TAB,
163                   raw_ostream &OS, MCCodeEmitter *Emitter)
164     : MCObjectStreamer(Context, TAB, OS, Emitter) {}
165
166   ~MCELFStreamer() {}
167
168   /// @name MCStreamer Interface
169   /// @{
170
171   virtual void InitSections();
172   virtual void ChangeSection(const MCSection *Section);
173   virtual void EmitLabel(MCSymbol *Symbol);
174   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
175   virtual void EmitThumbFunc(MCSymbol *Func);
176   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
177   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
178   virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
179   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
180     assert(0 && "ELF doesn't support this directive");
181   }
182   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
183                                 unsigned ByteAlignment);
184   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {
185     assert(0 && "ELF doesn't support this directive");
186   }
187
188   virtual void EmitCOFFSymbolStorageClass(int StorageClass) {
189     assert(0 && "ELF doesn't support this directive");
190   }
191
192   virtual void EmitCOFFSymbolType(int Type) {
193     assert(0 && "ELF doesn't support this directive");
194   }
195
196   virtual void EndCOFFSymbolDef() {
197     assert(0 && "ELF doesn't support this directive");
198   }
199
200   virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
201      MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
202      SD.setSize(Value);
203   }
204
205   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
206
207   virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
208                             unsigned Size = 0, unsigned ByteAlignment = 0) {
209     assert(0 && "ELF doesn't support this directive");
210   }
211   virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
212                               uint64_t Size, unsigned ByteAlignment = 0) {
213     assert(0 && "ELF doesn't support this directive");
214   }
215   virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
216   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
217                                     unsigned ValueSize = 1,
218                                     unsigned MaxBytesToEmit = 0);
219   virtual void EmitCodeAlignment(unsigned ByteAlignment,
220                                  unsigned MaxBytesToEmit = 0);
221
222   virtual void EmitFileDirective(StringRef Filename);
223
224   virtual void Finish();
225
226 private:
227   virtual void EmitInstToFragment(const MCInst &Inst);
228   virtual void EmitInstToData(const MCInst &Inst);
229
230   void fixSymbolsInTLSFixups(const MCExpr *expr);
231
232   struct LocalCommon {
233     MCSymbolData *SD;
234     uint64_t Size;
235     unsigned ByteAlignment;
236   };
237   std::vector<LocalCommon> LocalCommons;
238
239   SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet;
240   /// @}
241   void SetSection(StringRef Section, unsigned Type, unsigned Flags,
242                   SectionKind Kind) {
243     SwitchSection(getContext().getELFSection(Section, Type, Flags, Kind));
244   }
245
246   void SetSectionData() {
247     SetSection(".data", ELF::SHT_PROGBITS,
248                ELF::SHF_WRITE |ELF::SHF_ALLOC,
249                SectionKind::getDataRel());
250     EmitCodeAlignment(4, 0);
251   }
252   void SetSectionText() {
253     SetSection(".text", ELF::SHT_PROGBITS,
254                ELF::SHF_EXECINSTR |
255                ELF::SHF_ALLOC, SectionKind::getText());
256     EmitCodeAlignment(4, 0);
257   }
258   void SetSectionBss() {
259     SetSection(".bss", ELF::SHT_NOBITS,
260                ELF::SHF_WRITE |
261                ELF::SHF_ALLOC, SectionKind::getBSS());
262     EmitCodeAlignment(4, 0);
263   }
264 };
265
266 } // end llvm namespace
267
268 #endif