From ef76b273f96d99a4a260f3dcadde8fbb96256cf3 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 7 Dec 2012 17:42:41 +0000 Subject: [PATCH] Lift EmitAssignment into MCObjectStreamer which gets rid of at least three duplicate implementations in format-specific streamers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169613 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCELFStreamer.h | 1 - include/llvm/MC/MCObjectStreamer.h | 1 + lib/MC/MCELFStreamer.cpp | 8 -------- lib/MC/MCMachOStreamer.cpp | 9 --------- lib/MC/MCObjectStreamer.cpp | 5 +++++ lib/MC/MCPureStreamer.cpp | 9 --------- lib/MC/WinCOFFStreamer.cpp | 2 -- 7 files changed, 6 insertions(+), 29 deletions(-) diff --git a/include/llvm/MC/MCELFStreamer.h b/include/llvm/MC/MCELFStreamer.h index c3fea6f3006..05727e4cf10 100644 --- a/include/llvm/MC/MCELFStreamer.h +++ b/include/llvm/MC/MCELFStreamer.h @@ -50,7 +50,6 @@ public: virtual void EmitLabel(MCSymbol *Symbol); virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); virtual void EmitThumbFunc(MCSymbol *Func); - virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol); virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute); virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h index 08b00f1c478..db305626499 100644 --- a/include/llvm/MC/MCObjectStreamer.h +++ b/include/llvm/MC/MCObjectStreamer.h @@ -64,6 +64,7 @@ public: /// @{ virtual void EmitLabel(MCSymbol *Symbol); + virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, unsigned AddrSpace); virtual void EmitULEB128Value(const MCExpr *Value); diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index c58a6ae52c6..b1952bf1756 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -100,14 +100,6 @@ void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) { llvm_unreachable("invalid assembler flag!"); } -void MCELFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { - // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into - // MCObjectStreamer. - // FIXME: Lift context changes into super class. - getAssembler().getOrCreateSymbolData(*Symbol); - Symbol->setVariableValue(AddValueSymbols(Value)); -} - void MCELFStreamer::ChangeSection(const MCSection *Section) { const MCSymbol *Grp = static_cast(Section)->getGroup(); if (Grp) diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 1be5a7f0bb9..cc6c853c771 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -48,7 +48,6 @@ public: virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); virtual void EmitDataRegion(MCDataRegionType Kind); virtual void EmitThumbFunc(MCSymbol *Func); - virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute); virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, @@ -200,14 +199,6 @@ void MCMachOStreamer::EmitThumbFunc(MCSymbol *Symbol) { SD.setFlags(SD.getFlags() | SF_ThumbFunc); } -void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { - // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into - // MCObjectStreamer. - // FIXME: Lift context changes into super class. - getAssembler().getOrCreateSymbolData(*Symbol); - Symbol->setVariableValue(AddValueSymbols(Value)); -} - void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { // Indirect symbols are handled differently, to match how 'as' handles diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 774632306d9..08200eb8f0c 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -159,6 +159,11 @@ void MCObjectStreamer::ChangeSection(const MCSection *Section) { CurSectionData = &getAssembler().getOrCreateSectionData(*Section); } +void MCObjectStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { + getAssembler().getOrCreateSymbolData(*Symbol); + Symbol->setVariableValue(AddValueSymbols(Value)); +} + void MCObjectStreamer::EmitInstruction(const MCInst &Inst) { // Scan for values. for (unsigned i = Inst.getNumOperands(); i--; ) diff --git a/lib/MC/MCPureStreamer.cpp b/lib/MC/MCPureStreamer.cpp index 9ccab930673..fd9ccf74551 100644 --- a/lib/MC/MCPureStreamer.cpp +++ b/lib/MC/MCPureStreamer.cpp @@ -37,7 +37,6 @@ public: virtual void InitSections(); virtual void EmitLabel(MCSymbol *Symbol); - virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, uint64_t Size = 0, unsigned ByteAlignment = 0); virtual void EmitBytes(StringRef Data, unsigned AddrSpace); @@ -135,14 +134,6 @@ void MCPureStreamer::EmitLabel(MCSymbol *Symbol) { SD.setOffset(F->getContents().size()); } -void MCPureStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { - // TODO: This is exactly the same as WinCOFFStreamer. Consider merging into - // MCObjectStreamer. - // FIXME: Lift context changes into super class. - getAssembler().getOrCreateSymbolData(*Symbol); - Symbol->setVariableValue(AddValueSymbols(Value)); -} - void MCPureStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { report_fatal_error("not yet implemented in pure streamer"); diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index e648a73653c..e8fe68016f3 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -193,8 +193,6 @@ void WinCOFFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { // don't really even do. if (Value->getKind() != MCExpr::SymbolRef) { - // TODO: This is exactly the same as MachOStreamer. Consider merging into - // MCObjectStreamer. getAssembler().getOrCreateSymbolData(*Symbol); AddValueSymbols(Value); Symbol->setVariableValue(Value); -- 2.34.1