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"
26 /// \brief Streaming object file generation interface.
28 /// This class provides an implementation of the MCStreamer interface which is
29 /// suitable for use with the assembler backend. Specific object file formats
30 /// are expected to subclass this interface to implement directives specific
31 /// to that file format or custom semantics expected by the object writer
33 class MCObjectStreamer : public MCStreamer {
34 MCAssembler *Assembler;
35 MCSectionData *CurSectionData;
36 MCSectionData::iterator CurInsertionPoint;
38 virtual void EmitInstToData(const MCInst &Inst) = 0;
39 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
40 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame);
43 MCObjectStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB,
44 raw_ostream &_OS, MCCodeEmitter *_Emitter);
45 MCObjectStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB,
46 raw_ostream &_OS, MCCodeEmitter *_Emitter,
47 MCAssembler *_Assembler);
55 MCSectionData *getCurrentSectionData() const {
56 return CurSectionData;
59 MCFragment *getCurrentFragment() const;
61 void insert(MCFragment *F) const {
62 CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
63 F->setParent(CurSectionData);
66 /// Get a data fragment to write into, creating a new one if the current
67 /// fragment is not a data fragment.
68 MCDataFragment *getOrCreateDataFragment() const;
70 const MCExpr *AddValueSymbols(const MCExpr *Value);
73 MCAssembler &getAssembler() { return *Assembler; }
75 /// @name MCStreamer Interface
78 virtual void EmitLabel(MCSymbol *Symbol);
79 virtual void EmitDebugLabel(MCSymbol *Symbol);
80 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
81 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size);
82 virtual void EmitULEB128Value(const MCExpr *Value);
83 virtual void EmitSLEB128Value(const MCExpr *Value);
84 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
85 virtual void ChangeSection(const MCSection *Section,
86 const MCExpr *Subsection);
87 virtual void EmitInstruction(const MCInst &Inst);
89 /// \brief Emit an instruction to a special fragment, because this instruction
90 /// can change its size during relaxation.
91 virtual void EmitInstToFragment(const MCInst &Inst);
93 virtual void EmitBundleAlignMode(unsigned AlignPow2);
94 virtual void EmitBundleLock(bool AlignToEnd);
95 virtual void EmitBundleUnlock();
96 virtual void EmitBytes(StringRef Data);
97 virtual void EmitValueToAlignment(unsigned ByteAlignment,
99 unsigned ValueSize = 1,
100 unsigned MaxBytesToEmit = 0);
101 virtual void EmitCodeAlignment(unsigned ByteAlignment,
102 unsigned MaxBytesToEmit = 0);
103 virtual bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
104 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
105 unsigned Column, unsigned Flags,
106 unsigned Isa, unsigned Discriminator,
108 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
109 const MCSymbol *LastLabel,
110 const MCSymbol *Label,
111 unsigned PointerSize);
112 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
113 const MCSymbol *Label);
114 virtual void EmitGPRel32Value(const MCExpr *Value);
115 virtual void EmitGPRel64Value(const MCExpr *Value);
116 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
117 virtual void EmitZeros(uint64_t NumBytes);
118 virtual void FinishImpl();
122 static bool classof(const MCStreamer *S) {
123 return S->getKind() >= SK_ELFStreamer && S->getKind() <= SK_WinCOFFStreamer;
127 } // end namespace llvm