blob: 2f23cd64ee03f5073a10996c9d64ea16ad343051 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- 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/SmallVector.h"
14#include "llvm/MC/MCDirectives.h"
15#include "llvm/MC/MCObjectStreamer.h"
16
17namespace llvm {
18
19class MCAsmBackend;
20class MCCodeEmitter;
21class MCExpr;
22class MCInst;
23
24class MCELFStreamer : public MCObjectStreamer {
25public:
26 MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
27 raw_pwrite_stream &OS, std::unique_ptr<MCCodeEmitter> Emitter);
28
29 ~MCELFStreamer() override = default;
30
31 /// state management
32 void reset() override {
33 SeenIdent = false;
34 BundleGroups.clear();
35 MCObjectStreamer::reset();
36 }
37
38 /// \name MCStreamer Interface
39 /// @{
40
41 void InitSections(bool NoExecStack) override;
42 void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
43 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
44 void EmitLabel(MCSymbol *Symbol, SMLoc Loc, MCFragment *F) override;
45 void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
46 void EmitThumbFunc(MCSymbol *Func) override;
47 void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
48 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
49 void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
50 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
51 unsigned ByteAlignment) override;
52
53 void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
54 void emitELFSymverDirective(StringRef AliasName,
55 const MCSymbol *Aliasee) override;
56
57 void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
58 unsigned ByteAlignment) override;
59
60 void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
61 uint64_t Size = 0, unsigned ByteAlignment = 0) override;
62 void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
63 unsigned ByteAlignment = 0) override;
64 void EmitValueImpl(const MCExpr *Value, unsigned Size,
65 SMLoc Loc = SMLoc()) override;
66
67 void EmitIdent(StringRef IdentString) override;
68
69 void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
70
71 void FinishImpl() override;
72
73 void EmitBundleAlignMode(unsigned AlignPow2) override;
74 void EmitBundleLock(bool AlignToEnd) override;
75 void EmitBundleUnlock() override;
76
77private:
78 bool isBundleLocked() const;
79 void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
80 void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
81
82 void fixSymbolsInTLSFixups(const MCExpr *expr);
83
84 /// \brief Merge the content of the fragment \p EF into the fragment \p DF.
85 void mergeFragment(MCDataFragment *, MCDataFragment *);
86
87 bool SeenIdent = false;
88
89 /// BundleGroups - The stack of fragments holding the bundle-locked
90 /// instructions.
91 SmallVector<MCDataFragment *, 4> BundleGroups;
92};
93
94MCELFStreamer *createARMELFStreamer(MCContext &Context,
95 std::unique_ptr<MCAsmBackend> TAB,
96 raw_pwrite_stream &OS,
97 std::unique_ptr<MCCodeEmitter> Emitter,
98 bool RelaxAll, bool IsThumb);
99
100} // end namespace llvm
101
102#endif // LLVM_MC_MCELFSTREAMER_H