MCObjectStreamer.h revision f89671d994ba27e2816a7e49eb8bbc1b43d2a147
1//===- MCObjectStreamer.h - MCStreamer 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_MCOBJECTSTREAMER_H
11#define LLVM_MC_MCOBJECTSTREAMER_H
12
13#include "llvm/MC/MCStreamer.h"
14
15namespace llvm {
16class MCAssembler;
17class MCCodeEmitter;
18class MCSectionData;
19class MCExpr;
20class MCFragment;
21class MCDataFragment;
22class TargetAsmBackend;
23class raw_ostream;
24
25/// \brief Streaming object file generation interface.
26///
27/// This class provides an implementation of the MCStreamer interface which is
28/// suitable for use with the assembler backend. Specific object file formats
29/// are expected to subclass this interface to implement directives specific
30/// to that file format or custom semantics expected by the object writer
31/// implementation.
32class MCObjectStreamer : public MCStreamer {
33  MCAssembler *Assembler;
34  MCSectionData *CurSectionData;
35
36  virtual void EmitInstToFragment(const MCInst &Inst) = 0;
37  virtual void EmitInstToData(const MCInst &Inst) = 0;
38
39protected:
40  MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
41                   raw_ostream &_OS, MCCodeEmitter *_Emitter,
42                   bool _PadSectionToAlignment);
43  ~MCObjectStreamer();
44
45  MCSectionData *getCurrentSectionData() const {
46    return CurSectionData;
47  }
48
49  MCFragment *getCurrentFragment() const;
50
51  /// Get a data fragment to write into, creating a new one if the current
52  /// fragment is not a data fragment.
53  MCDataFragment *getOrCreateDataFragment() const;
54
55  const MCExpr *AddValueSymbols(const MCExpr *Value);
56
57public:
58  MCAssembler &getAssembler() { return *Assembler; }
59
60  /// @name MCStreamer Interface
61  /// @{
62
63  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
64  virtual void SwitchSection(const MCSection *Section);
65  virtual void EmitInstruction(const MCInst &Inst);
66  virtual void Finish();
67
68  /// @}
69};
70
71} // end namespace llvm
72
73#endif
74