llvm.org GIT mirror llvm / 5da3665
Give the MCStreamer class hierarchy LLVM RTTI facilities for use with isa<> and dyn_cast<>. In several places, code is already hacking around the absence of this, and there seem to be several interfaces that might be lifted and/or devirtualized using this. This change was based on a discussion with Jim Grosbach about how best to handle testing for specific MCStreamer subclasses. He said that this was the correct end state, and everything else was too hacky so I decided to just make it so. No functionality should be changed here, this is just threading the kind through all the constructors and setting up the classof overloads. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174113 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
12 changed file(s) with 104 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
2727 class raw_ostream;
2828
2929 class MCELFStreamer : public MCObjectStreamer {
30 protected:
31 MCELFStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB,
32 raw_ostream &OS, MCCodeEmitter *Emitter)
33 : MCObjectStreamer(Kind, Context, TAB, OS, Emitter) {}
34
3035 public:
31 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB,
32 raw_ostream &OS, MCCodeEmitter *Emitter)
33 : MCObjectStreamer(Context, TAB, OS, Emitter) {}
36 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS,
37 MCCodeEmitter *Emitter)
38 : MCObjectStreamer(SK_ELFStreamer, Context, TAB, OS, Emitter) {}
3439
35 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB,
36 raw_ostream &OS, MCCodeEmitter *Emitter,
37 MCAssembler *Assembler)
38 : MCObjectStreamer(Context, TAB, OS, Emitter, Assembler) {}
40 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS,
41 MCCodeEmitter *Emitter, MCAssembler *Assembler)
42 : MCObjectStreamer(SK_ELFStreamer, Context, TAB, OS, Emitter,
43 Assembler) {}
3944
4045 virtual ~MCELFStreamer();
4146
8085 virtual void FinishImpl();
8186 /// @}
8287
88 static bool classof(const MCStreamer *S) {
89 return S->getKind() == SK_ELFStreamer && S->getKind() == SK_ARMELFStreamer;
90 }
91
8392 private:
8493 virtual void EmitInstToFragment(const MCInst &Inst);
8594 virtual void EmitInstToData(const MCInst &Inst);
3737 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame);
3838
3939 protected:
40 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
40 MCObjectStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB,
4141 raw_ostream &_OS, MCCodeEmitter *_Emitter);
42 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
42 MCObjectStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB,
4343 raw_ostream &_OS, MCCodeEmitter *_Emitter,
4444 MCAssembler *_Assembler);
4545 ~MCObjectStreamer();
106106 virtual void FinishImpl();
107107
108108 /// @}
109
110 static bool classof(const MCStreamer *S) {
111 return S->getKind() >= SK_ELFStreamer && S->getKind() <= SK_WinCOFFStreamer;
112 }
109113 };
110114
111115 } // end namespace llvm
4545 /// a .s file, and implementations that write out .o files of various formats.
4646 ///
4747 class MCStreamer {
48 public:
49 enum StreamerKind {
50 SK_AsmStreamer,
51 SK_NullStreamer,
52 SK_RecordStreamer,
53
54 // MCObjectStreamer subclasses.
55 SK_ELFStreamer,
56 SK_ARMELFStreamer,
57 SK_MachOStreamer,
58 SK_PureStreamer,
59 SK_WinCOFFStreamer
60 };
61
62 private:
63 const StreamerKind Kind;
4864 MCContext &Context;
4965
5066 MCStreamer(const MCStreamer&) LLVM_DELETED_FUNCTION;
7389 bool AutoInitSections;
7490
7591 protected:
76 MCStreamer(MCContext &Ctx);
92 MCStreamer(StreamerKind Kind, MCContext &Ctx);
7793
7894 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
7995 const MCSymbol *B);
91107
92108 public:
93109 virtual ~MCStreamer();
110
111 StreamerKind getKind() const { return Kind; }
94112
95113 /// State management
96114 ///
7070 MCInstPrinter *printer, MCCodeEmitter *emitter,
7171 MCAsmBackend *asmbackend,
7272 bool showInst)
73 : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()),
73 : MCStreamer(SK_AsmStreamer, Context), OS(os), MAI(Context.getAsmInfo()),
7474 InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend),
7575 CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
7676 ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI),
276276 virtual void FinishImpl();
277277
278278 /// @}
279
280 static bool classof(const MCStreamer *S) {
281 return S->getKind() == SK_NullStreamer;
282 }
279283 };
280284
281285 } // end anonymous namespace.
3333 void EmitDataRegion(DataRegionData::KindTy Kind);
3434 void EmitDataRegionEnd();
3535 public:
36 MCMachOStreamer(MCContext &Context, MCAsmBackend &MAB,
37 raw_ostream &OS, MCCodeEmitter *Emitter)
38 : MCObjectStreamer(Context, MAB, OS, Emitter) {}
36 MCMachOStreamer(MCContext &Context, MCAsmBackend &MAB, raw_ostream &OS,
37 MCCodeEmitter *Emitter)
38 : MCObjectStreamer(SK_MachOStreamer, Context, MAB, OS, Emitter) {}
3939
4040 /// @name MCStreamer Interface
4141 /// @{
8686 virtual void FinishImpl();
8787
8888 /// @}
89
90 static bool classof(const MCStreamer *S) {
91 return S->getKind() == SK_MachOStreamer;
92 }
8993 };
9094
9195 } // end anonymous namespace.
1818
1919 class MCNullStreamer : public MCStreamer {
2020 public:
21 MCNullStreamer(MCContext &Context) : MCStreamer(Context) {}
21 MCNullStreamer(MCContext &Context) : MCStreamer(SK_NullStreamer, Context) {}
2222
2323 /// @name MCStreamer Interface
2424 /// @{
108108 }
109109
110110 /// @}
111
112 static bool classof(const MCStreamer *S) {
113 return S->getKind() == SK_NullStreamer;
114 }
115
111116 };
112117
113118 }
1919 #include "llvm/Support/ErrorHandling.h"
2020 using namespace llvm;
2121
22 MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
23 raw_ostream &OS, MCCodeEmitter *Emitter_)
24 : MCStreamer(Context),
25 Assembler(new MCAssembler(Context, TAB,
26 *Emitter_, *TAB.createObjectWriter(OS),
27 OS)),
28 CurSectionData(0)
29 {
30 }
31
32 MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
33 raw_ostream &OS, MCCodeEmitter *Emitter_,
22 MCObjectStreamer::MCObjectStreamer(StreamerKind Kind, MCContext &Context,
23 MCAsmBackend &TAB, raw_ostream &OS,
24 MCCodeEmitter *Emitter_)
25 : MCStreamer(Kind, Context),
26 Assembler(new MCAssembler(Context, TAB, *Emitter_,
27 *TAB.createObjectWriter(OS), OS)),
28 CurSectionData(0) {}
29
30 MCObjectStreamer::MCObjectStreamer(StreamerKind Kind, MCContext &Context,
31 MCAsmBackend &TAB, raw_ostream &OS,
32 MCCodeEmitter *Emitter_,
3433 MCAssembler *_Assembler)
35 : MCStreamer(Context), Assembler(_Assembler), CurSectionData(0)
36 {
37 }
34 : MCStreamer(Kind, Context), Assembler(_Assembler), CurSectionData(0) {}
3835
3936 MCObjectStreamer::~MCObjectStreamer() {
4037 delete &Assembler->getBackend();
2727 virtual void EmitInstToData(const MCInst &Inst);
2828
2929 public:
30 MCPureStreamer(MCContext &Context, MCAsmBackend &TAB,
31 raw_ostream &OS, MCCodeEmitter *Emitter)
32 : MCObjectStreamer(Context, TAB, OS, Emitter) {}
30 MCPureStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS,
31 MCCodeEmitter *Emitter)
32 : MCObjectStreamer(SK_PureStreamer, Context, TAB, OS, Emitter) {}
3333
3434 /// @name MCStreamer Interface
3535 /// @{
9999 }
100100
101101 /// @}
102
103 static bool classof(const MCStreamer *S) {
104 return S->getKind() == SK_PureStreamer;
105 }
102106 };
103107
104108 } // end anonymous namespace.
2020 #include
2121 using namespace llvm;
2222
23 MCStreamer::MCStreamer(MCContext &Ctx)
24 : Context(Ctx), EmitEHFrame(true), EmitDebugFrame(false),
25 CurrentW64UnwindInfo(0), LastSymbol(0),
26 AutoInitSections(false) {
23 MCStreamer::MCStreamer(StreamerKind Kind, MCContext &Ctx)
24 : Kind(Kind), Context(Ctx), EmitEHFrame(true), EmitDebugFrame(false),
25 CurrentW64UnwindInfo(0), LastSymbol(0), AutoInitSections(false) {
2726 const MCSection *section = NULL;
2827 SectionStack.push_back(std::make_pair(section, section));
2928 }
7474 virtual void EmitWin64EHHandlerData();
7575 virtual void FinishImpl();
7676
77 static bool classof(const MCStreamer *S) {
78 return S->getKind() == SK_WinCOFFStreamer;
79 }
80
7781 private:
7882 virtual void EmitInstToData(const MCInst &Inst) {
7983 MCDataFragment *DF = getOrCreateDataFragment();
127131 };
128132 } // end anonymous namespace.
129133
130 WinCOFFStreamer::WinCOFFStreamer(MCContext &Context,
131 MCAsmBackend &MAB,
132 MCCodeEmitter &CE,
133 raw_ostream &OS)
134 : MCObjectStreamer(Context, MAB, OS, &CE)
135 , CurSymbol(NULL) {
136 }
134 WinCOFFStreamer::WinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB,
135 MCCodeEmitter &CE, raw_ostream &OS)
136 : MCObjectStreamer(SK_WinCOFFStreamer, Context, MAB, OS, &CE),
137 CurSymbol(NULL) {}
137138
138139 void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
139140 unsigned ByteAlignment, bool External) {
5353 /// by MachO. Beware!
5454 class ARMELFStreamer : public MCELFStreamer {
5555 public:
56 ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
57 raw_ostream &OS, MCCodeEmitter *Emitter, bool IsThumb)
58 : MCELFStreamer(Context, TAB, OS, Emitter),
59 IsThumb(IsThumb), MappingSymbolCounter(0), LastEMS(EMS_None),
60 ExTab(0), FnStart(0), Personality(0), CantUnwind(false) {
61 }
56 ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS,
57 MCCodeEmitter *Emitter, bool IsThumb)
58 : MCELFStreamer(SK_ARMELFStreamer, Context, TAB, OS, Emitter),
59 IsThumb(IsThumb), MappingSymbolCounter(0), LastEMS(EMS_None), ExTab(0),
60 FnStart(0), Personality(0), CantUnwind(false) {}
6261
6362 ~ARMELFStreamer() {}
6463
133132 }
134133 }
135134
135 static bool classof(const MCStreamer *S) {
136 return S->getKind() == SK_ARMELFStreamer;
137 }
138
136139 private:
137140 enum ElfMappingSymbol {
138141 EMS_None,
732732 return Symbols.end();
733733 }
734734
735 RecordStreamer(MCContext &Context) : MCStreamer(Context) {}
735 RecordStreamer(MCContext &Context)
736 : MCStreamer(SK_RecordStreamer, Context) {}
736737
737738 virtual void EmitInstruction(const MCInst &Inst) {
738739 // Scan for values.
803804 const MCSymbol *Label,
804805 unsigned PointerSize) {}
805806 virtual void FinishImpl() {}
807
808 static bool classof(const MCStreamer *S) {
809 return S->getKind == SK_RecordStreamer;
810 }
806811 };
807812 } // end anonymous namespace
808813