llvm.org GIT mirror llvm / c7abd27
Move expression visitation logic up to MCStreamer. Remove the duplicate from MCRecordStreamer. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211714 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
17 changed file(s) with 50 addition(s) and 70 deletion(s). Raw diff Collapse all Expand all
2020 class MCContext;
2121 class MCSection;
2222 class MCSectionData;
23 class MCObjectStreamer;
23 class MCStreamer;
2424 class MCSymbol;
2525 class MCValue;
2626 class raw_ostream;
524524 virtual void PrintImpl(raw_ostream &OS) const = 0;
525525 virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
526526 const MCAsmLayout *Layout) const = 0;
527 virtual void visitUsedExpr(MCObjectStreamer& Streamer) const = 0;
527 virtual void visitUsedExpr(MCStreamer& Streamer) const = 0;
528528 virtual const MCSection *FindAssociatedSection() const = 0;
529529
530530 virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0;
7878 MCDataFragment *getOrCreateDataFragment() const;
7979
8080 public:
81 void visitUsedExpr(const MCExpr &Expr);
82 void visitUsedSymbol(const MCSymbol &Sym);
81 void visitUsedSymbol(const MCSymbol &Sym) override;
8382
8483 MCAssembler &getAssembler() { return *Assembler; }
8584
212212
213213 public:
214214 virtual ~MCStreamer();
215
216 void visitUsedExpr(const MCExpr &Expr);
217 virtual void visitUsedSymbol(const MCSymbol &Sym);
215218
216219 void setTargetStreamer(MCTargetStreamer *TS) {
217220 TargetStreamer.reset(TS);
604604 }
605605 }
606606
607 // FIXME: mostly copied for the obj streamer.
608 void AddValueSymbols(const MCExpr *Value) {
609 switch (Value->getKind()) {
610 case MCExpr::Target:
611 // FIXME: What should we do in here?
612 break;
613
614 case MCExpr::Constant:
615 break;
616
617 case MCExpr::Binary: {
618 const MCBinaryExpr *BE = cast(Value);
619 AddValueSymbols(BE->getLHS());
620 AddValueSymbols(BE->getRHS());
621 break;
622 }
623
624 case MCExpr::SymbolRef:
625 markUsed(cast(Value)->getSymbol());
626 break;
627
628 case MCExpr::Unary:
629 AddValueSymbols(cast(Value)->getSubExpr());
630 break;
631 }
607 void visitUsedSymbol(const MCSymbol &Sym) override {
608 markUsed(Sym);
632609 }
633610
634611 public:
649626 // Scan for values.
650627 for (unsigned i = Inst.getNumOperands(); i--; )
651628 if (Inst.getOperand(i).isExpr())
652 AddValueSymbols(Inst.getOperand(i).getExpr());
629 visitUsedExpr(*Inst.getOperand(i).getExpr());
653630 }
654631 void EmitLabel(MCSymbol *Symbol) override {
655632 MCStreamer::EmitLabel(Symbol);
658635 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override {
659636 // FIXME: should we handle aliases?
660637 markDefined(*Symbol);
661 AddValueSymbols(Value);
638 visitUsedExpr(*Value);
662639 }
663640 bool EmitSymbolAttribute(MCSymbol *Symbol,
664641 MCSymbolAttr Attribute) override {
8686 Assembler->getOrCreateSymbolData(Sym);
8787 }
8888
89 void MCObjectStreamer::visitUsedExpr(const MCExpr &Expr) {
90 switch (Expr.getKind()) {
91 case MCExpr::Target:
92 cast(Expr).visitUsedExpr(*this);
93 break;
94
95 case MCExpr::Constant:
96 break;
97
98 case MCExpr::Binary: {
99 const MCBinaryExpr &BE = cast(Expr);
100 visitUsedExpr(*BE.getLHS());
101 visitUsedExpr(*BE.getRHS());
102 break;
103 }
104
105 case MCExpr::SymbolRef:
106 visitUsedSymbol(cast(Expr).getSymbol());
107 break;
108
109 case MCExpr::Unary:
110 visitUsedExpr(*cast(Expr).getSubExpr());
111 break;
112 }
113 }
114
11589 void MCObjectStreamer::EmitCFISections(bool EH, bool Debug) {
11690 MCStreamer::EmitCFISections(EH, Debug);
11791 EmitEHFrame = EH;
611611 MCTargetStreamer *TS = getTargetStreamer();
612612 if (TS)
613613 TS->emitAssignment(Symbol, Value);
614 }
615
616 void MCStreamer::visitUsedSymbol(const MCSymbol &Sym) {
617 }
618
619 void MCStreamer::visitUsedExpr(const MCExpr &Expr) {
620 switch (Expr.getKind()) {
621 case MCExpr::Target:
622 cast(Expr).visitUsedExpr(*this);
623 break;
624
625 case MCExpr::Constant:
626 break;
627
628 case MCExpr::Binary: {
629 const MCBinaryExpr &BE = cast(Expr);
630 visitUsedExpr(*BE.getLHS());
631 visitUsedExpr(*BE.getRHS());
632 break;
633 }
634
635 case MCExpr::SymbolRef:
636 visitUsedSymbol(cast(Expr).getSymbol());
637 break;
638
639 case MCExpr::Unary:
640 visitUsedExpr(*cast(Expr).getSubExpr());
641 break;
642 }
614643 }
615644
616645 void MCStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {}
1515 #include "llvm/MC/MCAssembler.h"
1616 #include "llvm/MC/MCContext.h"
1717 #include "llvm/MC/MCELF.h"
18 #include "llvm/MC/MCObjectStreamer.h"
1918 #include "llvm/MC/MCSymbol.h"
2019 #include "llvm/MC/MCValue.h"
2120 #include "llvm/Object/ELF.h"
8180 OS << *Expr;
8281 }
8382
84 void AArch64MCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
83 void AArch64MCExpr::visitUsedExpr(MCStreamer &Streamer) const {
8584 Streamer.visitUsedExpr(*getSubExpr());
8685 }
8786
146146
147147 void PrintImpl(raw_ostream &OS) const override;
148148
149 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
149 void visitUsedExpr(MCStreamer &Streamer) const override;
150150
151151 const MCSection *FindAssociatedSection() const override;
152152
99 #include "ARMMCExpr.h"
1010 #include "llvm/MC/MCAssembler.h"
1111 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCObjectStreamer.h"
1312 using namespace llvm;
1413
1514 #define DEBUG_TYPE "armmcexpr"
4140 return false;
4241 }
4342
44 void ARMMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
43 void ARMMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
4544 Streamer.visitUsedExpr(*getSubExpr());
4645 }
5858 void PrintImpl(raw_ostream &OS) const override;
5959 bool EvaluateAsRelocatableImpl(MCValue &Res,
6060 const MCAsmLayout *Layout) const override;
61 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
61 void visitUsedExpr(MCStreamer &Streamer) const override;
6262 const MCSection *FindAssociatedSection() const override {
6363 return getSubExpr()->FindAssociatedSection();
6464 }
8383 return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
8484 }
8585
86 void MipsMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
86 void MipsMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
8787 Streamer.visitUsedExpr(*getSubExpr());
8888 }
4848 void PrintImpl(raw_ostream &OS) const override;
4949 bool EvaluateAsRelocatableImpl(MCValue &Res,
5050 const MCAsmLayout *Layout) const override;
51 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
51 void visitUsedExpr(MCStreamer &Streamer) const override;
5252 const MCSection *FindAssociatedSection() const override {
5353 return getSubExpr()->FindAssociatedSection();
5454 }
6565 const MCAsmLayout *Layout) const override {
6666 return false;
6767 }
68 void visitUsedExpr(MCObjectStreamer &Streamer) const override {};
68 void visitUsedExpr(MCStreamer &Streamer) const override {};
6969 const MCSection *FindAssociatedSection() const override {
7070 return nullptr;
7171 }
127127 return true;
128128 }
129129
130 void PPCMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
130 void PPCMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
131131 Streamer.visitUsedExpr(*getSubExpr());
132132 }
7878 void PrintImpl(raw_ostream &OS) const override;
7979 bool EvaluateAsRelocatableImpl(MCValue &Res,
8080 const MCAsmLayout *Layout) const override;
81 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
81 void visitUsedExpr(MCStreamer &Streamer) const override;
8282 const MCSection *FindAssociatedSection() const override {
8383 return getSubExpr()->FindAssociatedSection();
8484 }
219219 fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
220220 }
221221
222 void SparcMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
222 void SparcMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
223223 Streamer.visitUsedExpr(*getSubExpr());
224224 }
8787 void PrintImpl(raw_ostream &OS) const override;
8888 bool EvaluateAsRelocatableImpl(MCValue &Res,
8989 const MCAsmLayout *Layout) const override;
90 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
90 void visitUsedExpr(MCStreamer &Streamer) const override;
9191 const MCSection *FindAssociatedSection() const override {
9292 return getSubExpr()->FindAssociatedSection();
9393 }