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