]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/MC/MCELFStreamer.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / 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(MCContext &Context, TargetAsmBackend &TAB,
33                 raw_ostream &OS, MCCodeEmitter *Emitter,
34                 MCAssembler *Assembler)
35     : MCObjectStreamer(Context, TAB, OS, Emitter, Assembler) {}
36
37
38   ~MCELFStreamer() {}
39
40   /// @name MCStreamer Interface
41   /// @{
42
43   virtual void InitSections();
44   virtual void ChangeSection(const MCSection *Section);
45   virtual void EmitLabel(MCSymbol *Symbol);
46   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
47   virtual void EmitThumbFunc(MCSymbol *Func);
48   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
49   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
50   virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
51   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
52     assert(0 && "ELF doesn't support this directive");
53   }
54   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
55                                 unsigned ByteAlignment);
56   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {
57     assert(0 && "ELF doesn't support this directive");
58   }
59
60   virtual void EmitCOFFSymbolStorageClass(int StorageClass) {
61     assert(0 && "ELF doesn't support this directive");
62   }
63
64   virtual void EmitCOFFSymbolType(int Type) {
65     assert(0 && "ELF doesn't support this directive");
66   }
67
68   virtual void EndCOFFSymbolDef() {
69     assert(0 && "ELF doesn't support this directive");
70   }
71
72   virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
73      MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
74      SD.setSize(Value);
75   }
76
77   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
78
79   virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
80                             unsigned Size = 0, unsigned ByteAlignment = 0) {
81     assert(0 && "ELF doesn't support this directive");
82   }
83   virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
84                               uint64_t Size, unsigned ByteAlignment = 0) {
85     assert(0 && "ELF doesn't support this directive");
86   }
87   virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
88   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
89                                     unsigned ValueSize = 1,
90                                     unsigned MaxBytesToEmit = 0);
91   virtual void EmitCodeAlignment(unsigned ByteAlignment,
92                                  unsigned MaxBytesToEmit = 0);
93
94   virtual void EmitFileDirective(StringRef Filename);
95
96   virtual void Finish();
97
98 private:
99   virtual void EmitInstToFragment(const MCInst &Inst);
100   virtual void EmitInstToData(const MCInst &Inst);
101
102   void fixSymbolsInTLSFixups(const MCExpr *expr);
103
104   struct LocalCommon {
105     MCSymbolData *SD;
106     uint64_t Size;
107     unsigned ByteAlignment;
108   };
109   std::vector<LocalCommon> LocalCommons;
110
111   SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet;
112   /// @}
113   void SetSection(StringRef Section, unsigned Type, unsigned Flags,
114                   SectionKind Kind) {
115     SwitchSection(getContext().getELFSection(Section, Type, Flags, Kind));
116   }
117
118   void SetSectionData() {
119     SetSection(".data", ELF::SHT_PROGBITS,
120                ELF::SHF_WRITE |ELF::SHF_ALLOC,
121                SectionKind::getDataRel());
122     EmitCodeAlignment(4, 0);
123   }
124   void SetSectionText() {
125     SetSection(".text", ELF::SHT_PROGBITS,
126                ELF::SHF_EXECINSTR |
127                ELF::SHF_ALLOC, SectionKind::getText());
128     EmitCodeAlignment(4, 0);
129   }
130   void SetSectionBss() {
131     SetSection(".bss", ELF::SHT_NOBITS,
132                ELF::SHF_WRITE |
133                ELF::SHF_ALLOC, SectionKind::getBSS());
134     EmitCodeAlignment(4, 0);
135   }
136 };
137
138 } // end llvm namespace
139
140 #endif