1 //===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCOBJECTSTREAMER_H
11 #define LLVM_MC_MCOBJECTSTREAMER_H
13 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCStreamer.h"
20 class MCSubtargetInfo;
27 /// \brief Streaming object file generation interface.
29 /// This class provides an implementation of the MCStreamer interface which is
30 /// suitable for use with the assembler backend. Specific object file formats
31 /// are expected to subclass this interface to implement directives specific
32 /// to that file format or custom semantics expected by the object writer
34 class MCObjectStreamer : public MCStreamer {
35 MCAssembler *Assembler;
36 MCSectionData *CurSectionData;
37 MCSectionData::iterator CurInsertionPoint;
41 virtual void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0;
42 void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
43 void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
46 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
47 MCCodeEmitter *_Emitter);
48 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
49 MCCodeEmitter *_Emitter, MCAssembler *_Assembler);
54 void reset() override;
56 /// Object streamers require the integrated assembler.
57 bool isIntegratedAssemblerRequired() const override { return true; }
59 MCSymbolData &getOrCreateSymbolData(const MCSymbol *Symbol) {
60 return getAssembler().getOrCreateSymbolData(*Symbol);
62 void EmitFrames(MCAsmBackend *MAB);
63 void EmitCFISections(bool EH, bool Debug) override;
66 MCSectionData *getCurrentSectionData() const {
67 return CurSectionData;
70 MCFragment *getCurrentFragment() const;
72 void insert(MCFragment *F) const {
73 CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
74 F->setParent(CurSectionData);
77 /// Get a data fragment to write into, creating a new one if the current
78 /// fragment is not a data fragment.
79 MCDataFragment *getOrCreateDataFragment() const;
81 const MCExpr *AddValueSymbols(const MCExpr *Value);
84 MCAssembler &getAssembler() { return *Assembler; }
86 /// @name MCStreamer Interface
89 void EmitLabel(MCSymbol *Symbol) override;
90 void EmitDebugLabel(MCSymbol *Symbol) override;
91 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
92 void EmitValueImpl(const MCExpr *Value, unsigned Size,
93 const SMLoc &Loc = SMLoc()) override;
94 void EmitULEB128Value(const MCExpr *Value) override;
95 void EmitSLEB128Value(const MCExpr *Value) override;
96 void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
97 void ChangeSection(const MCSection *Section,
98 const MCExpr *Subsection) override;
99 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo& STI) override;
101 /// \brief Emit an instruction to a special fragment, because this instruction
102 /// can change its size during relaxation.
103 virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &);
105 void EmitBundleAlignMode(unsigned AlignPow2) override;
106 void EmitBundleLock(bool AlignToEnd) override;
107 void EmitBundleUnlock() override;
108 void EmitBytes(StringRef Data) override;
109 void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
110 unsigned ValueSize = 1,
111 unsigned MaxBytesToEmit = 0) override;
112 void EmitCodeAlignment(unsigned ByteAlignment,
113 unsigned MaxBytesToEmit = 0) override;
114 bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value) override;
115 void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
116 unsigned Column, unsigned Flags,
117 unsigned Isa, unsigned Discriminator,
118 StringRef FileName) override;
119 void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
120 const MCSymbol *Label,
121 unsigned PointerSize);
122 void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
123 const MCSymbol *Label);
124 void EmitGPRel32Value(const MCExpr *Value) override;
125 void EmitGPRel64Value(const MCExpr *Value) override;
126 void EmitFill(uint64_t NumBytes, uint8_t FillValue) override;
127 void EmitZeros(uint64_t NumBytes) override;
128 void FinishImpl() override;
131 } // end namespace llvm