Create a MCSymbolELF.
[oota-llvm.git] / include / llvm / MC / MCELFStreamer.h
1 //===- MCELFStreamer.h - MCStreamer ELF Object File Interface ---*- 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_MCELFSTREAMER_H
11 #define LLVM_MC_MCELFSTREAMER_H
12
13 #include "llvm/ADT/SmallPtrSet.h"
14 #include "llvm/MC/MCDirectives.h"
15 #include "llvm/MC/MCObjectStreamer.h"
16 #include "llvm/MC/SectionKind.h"
17 #include "llvm/Support/DataTypes.h"
18 #include <vector>
19
20 namespace llvm {
21 class MCAsmBackend;
22 class MCAssembler;
23 class MCCodeEmitter;
24 class MCExpr;
25 class MCInst;
26 class raw_ostream;
27
28 class MCELFStreamer : public MCObjectStreamer {
29 public:
30   MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS,
31                 MCCodeEmitter *Emitter)
32       : MCObjectStreamer(Context, TAB, OS, Emitter), SeenIdent(false) {}
33
34   ~MCELFStreamer() override;
35
36   /// state management
37   void reset() override {
38     SeenIdent = false;
39     LocalCommons.clear();
40     BindingExplicitlySet.clear();
41     BundleGroups.clear();
42     MCObjectStreamer::reset();
43   }
44
45   /// \name MCStreamer Interface
46   /// @{
47
48   void InitSections(bool NoExecStack) override;
49   void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
50   void EmitLabel(MCSymbol *Symbol) override;
51   void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
52   void EmitThumbFunc(MCSymbol *Func) override;
53   void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
54   bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
55   void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
56   void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
57                         unsigned ByteAlignment) override;
58   void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
59   void EmitCOFFSymbolStorageClass(int StorageClass) override;
60   void EmitCOFFSymbolType(int Type) override;
61   void EndCOFFSymbolDef() override;
62
63   void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
64
65   void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
66                              unsigned ByteAlignment) override;
67
68   void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
69                     uint64_t Size = 0, unsigned ByteAlignment = 0) override;
70   void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
71                       unsigned ByteAlignment = 0) override;
72   void EmitValueImpl(const MCExpr *Value, unsigned Size,
73                      const SMLoc &Loc = SMLoc()) override;
74
75   void EmitFileDirective(StringRef Filename) override;
76
77   void EmitIdent(StringRef IdentString) override;
78
79   void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
80
81   void Flush() override;
82
83   void FinishImpl() override;
84
85   void EmitBundleAlignMode(unsigned AlignPow2) override;
86   void EmitBundleLock(bool AlignToEnd) override;
87   void EmitBundleUnlock() override;
88
89 private:
90   bool isBundleLocked() const;
91   void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
92   void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
93
94   void fixSymbolsInTLSFixups(const MCExpr *expr);
95
96   /// \brief Merge the content of the fragment \p EF into the fragment \p DF.
97   void mergeFragment(MCDataFragment *, MCEncodedFragmentWithFixups *);
98
99   bool SeenIdent;
100
101   struct LocalCommon {
102     const MCSymbol *Symbol;
103     uint64_t Size;
104     unsigned ByteAlignment;
105   };
106
107   std::vector<LocalCommon> LocalCommons;
108
109   SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet;
110
111   /// BundleGroups - The stack of fragments holding the bundle-locked
112   /// instructions.
113   llvm::SmallVector<MCDataFragment *, 4> BundleGroups;
114 };
115
116 MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
117                                     raw_pwrite_stream &OS,
118                                     MCCodeEmitter *Emitter, bool RelaxAll,
119                                     bool IsThumb);
120
121 } // end namespace llvm
122
123 #endif