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;
39 virtual void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0;
40 void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
41 void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
44 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
45 MCCodeEmitter *_Emitter);
46 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
47 MCCodeEmitter *_Emitter, MCAssembler *_Assembler);
52 void reset() override;
54 /// Object streamers require the integrated assembler.
55 bool isIntegratedAssemblerRequired() const override { return true; }
58 MCSectionData *getCurrentSectionData() const {
59 return CurSectionData;
62 MCFragment *getCurrentFragment() const;
64 void insert(MCFragment *F) const {
65 CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
66 F->setParent(CurSectionData);
69 /// Get a data fragment to write into, creating a new one if the current
70 /// fragment is not a data fragment.
71 MCDataFragment *getOrCreateDataFragment() const;
73 const MCExpr *AddValueSymbols(const MCExpr *Value);
76 MCAssembler &getAssembler() { return *Assembler; }
78 /// @name MCStreamer Interface
81 void EmitLabel(MCSymbol *Symbol) override;
82 void EmitDebugLabel(MCSymbol *Symbol) override;
83 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
84 void EmitValueImpl(const MCExpr *Value, unsigned Size,
85 const SMLoc &Loc = SMLoc()) override;
86 void EmitULEB128Value(const MCExpr *Value) override;
87 void EmitSLEB128Value(const MCExpr *Value) override;
88 void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
89 void ChangeSection(const MCSection *Section,
90 const MCExpr *Subsection) override;
91 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo& STI) override;
93 /// \brief Emit an instruction to a special fragment, because this instruction
94 /// can change its size during relaxation.
95 virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &);
97 void EmitBundleAlignMode(unsigned AlignPow2) override;
98 void EmitBundleLock(bool AlignToEnd) override;
99 void EmitBundleUnlock() override;
100 void EmitBytes(StringRef Data) override;
101 void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
102 unsigned ValueSize = 1,
103 unsigned MaxBytesToEmit = 0) override;
104 void EmitCodeAlignment(unsigned ByteAlignment,
105 unsigned MaxBytesToEmit = 0) override;
106 bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value) override;
107 void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
108 unsigned Column, unsigned Flags,
109 unsigned Isa, unsigned Discriminator,
110 StringRef FileName) override;
111 void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
112 const MCSymbol *Label,
113 unsigned PointerSize) override;
114 void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
115 const MCSymbol *Label) override;
116 void EmitGPRel32Value(const MCExpr *Value) override;
117 void EmitGPRel64Value(const MCExpr *Value) override;
118 void EmitFill(uint64_t NumBytes, uint8_t FillValue) override;
119 void EmitZeros(uint64_t NumBytes) override;
120 void FinishImpl() override;
123 } // end namespace llvm