diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-08-31 08:09:28 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-08-31 08:09:28 +0000 |
commit | d79f43204be2893e74872f1062e2a44f023d39e1 (patch) | |
tree | 6ce6d23d121ee064f82737807150ca127e97d574 /lib/MC | |
parent | f4c67959b5ea0bbd3a39085c91c2d3162c6fd973 (diff) | |
download | external_llvm-d79f43204be2893e74872f1062e2a44f023d39e1.zip external_llvm-d79f43204be2893e74872f1062e2a44f023d39e1.tar.gz external_llvm-d79f43204be2893e74872f1062e2a44f023d39e1.tar.bz2 |
llvm-mc: Pass values to MCStreamer as MCExprs, not MCValues.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 28 | ||||
-rw-r--r-- | lib/MC/MCMachOStreamer.cpp | 36 | ||||
-rw-r--r-- | lib/MC/MCNullStreamer.cpp | 7 |
3 files changed, 37 insertions, 34 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index c220b8a..d976028 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -17,7 +17,6 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/MC/MCValue.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Format.h" @@ -47,7 +46,7 @@ public: virtual void EmitAssemblerFlag(AssemblerFlag Flag); - virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value); + virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute); @@ -61,13 +60,13 @@ public: virtual void EmitBytes(const StringRef &Data); - virtual void EmitValue(const MCValue &Value, unsigned Size); + virtual void EmitValue(const MCExpr *Value, unsigned Size); virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, unsigned ValueSize = 1, unsigned MaxBytesToEmit = 0); - virtual void EmitValueToOffset(const MCValue &Offset, + virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value = 0); virtual void EmitInstruction(const MCInst &Inst); @@ -86,7 +85,7 @@ static inline raw_ostream &operator<<(raw_ostream &os, const MCSymbol *S) { } /// Allow printing values directly to a raw_ostream. -static inline raw_ostream &operator<<(raw_ostream &os, const MCValue &Value) { +static inline raw_ostream &operator<<(raw_ostream &os, const MCExpr &Value) { Value.print(os); return os; } @@ -96,9 +95,10 @@ static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) { return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8)); } -static inline MCValue truncateToSize(const MCValue &Value, unsigned Bytes) { - return MCValue::get(Value.getSymA(), Value.getSymB(), - truncateToSize(Value.getConstant(), Bytes)); +static inline const MCExpr *truncateToSize(const MCExpr *Value, + unsigned Bytes) { + // FIXME: Do we really need this routine? + return Value; } void MCAsmStreamer::SwitchSection(const MCSection *Section) { @@ -125,12 +125,12 @@ void MCAsmStreamer::EmitAssemblerFlag(AssemblerFlag Flag) { OS << '\n'; } -void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value) { +void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { // Only absolute symbols can be redefined. assert((Symbol->isUndefined() || Symbol->isAbsolute()) && "Cannot define a symbol twice!"); - OS << Symbol << " = " << Value << '\n'; + OS << Symbol << " = " << *Value << '\n'; } void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol, @@ -189,7 +189,7 @@ void MCAsmStreamer::EmitBytes(const StringRef &Data) { OS << ".byte " << (unsigned) (unsigned char) Data[i] << '\n'; } -void MCAsmStreamer::EmitValue(const MCValue &Value, unsigned Size) { +void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size) { assert(CurSection && "Cannot emit contents before setting section!"); // Need target hooks to know how to print this. switch (Size) { @@ -201,7 +201,7 @@ void MCAsmStreamer::EmitValue(const MCValue &Value, unsigned Size) { case 8: OS << ".quad"; break; } - OS << ' ' << truncateToSize(Value, Size) << '\n'; + OS << ' ' << *truncateToSize(Value, Size) << '\n'; } void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, @@ -251,10 +251,10 @@ void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, OS << '\n'; } -void MCAsmStreamer::EmitValueToOffset(const MCValue &Offset, +void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset, unsigned char Value) { // FIXME: Verify that Offset is associated with the current section. - OS << ".org " << Offset << ", " << (unsigned) Value << '\n'; + OS << ".org " << *Offset << ", " << (unsigned) Value << '\n'; } void MCAsmStreamer::EmitInstruction(const MCInst &Inst) { diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index c92d8a8..e04bd1f 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -16,6 +16,7 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCValue.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -88,14 +89,6 @@ public: CurSectionData(0) {} ~MCMachOStreamer() {} - const MCValue &AddValueSymbols(const MCValue &Value) { - if (Value.getSymA()) - getSymbolData(*const_cast<MCSymbol*>(Value.getSymA())); - if (Value.getSymB()) - getSymbolData(*const_cast<MCSymbol*>(Value.getSymB())); - return Value; - } - const MCExpr *AddValueSymbols(const MCExpr *Value) { switch (Value->getKind()) { case MCExpr::Constant: @@ -129,7 +122,7 @@ public: virtual void EmitAssemblerFlag(AssemblerFlag Flag); - virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value); + virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute); @@ -143,13 +136,13 @@ public: virtual void EmitBytes(const StringRef &Data); - virtual void EmitValue(const MCValue &Value, unsigned Size); + virtual void EmitValue(const MCExpr *Value, unsigned Size); virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, unsigned ValueSize = 1, unsigned MaxBytesToEmit = 0); - virtual void EmitValueToOffset(const MCValue &Offset, + virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value = 0); virtual void EmitInstruction(const MCInst &Inst); @@ -200,7 +193,7 @@ void MCMachOStreamer::EmitAssemblerFlag(AssemblerFlag Flag) { assert(0 && "invalid assembler flag!"); } -void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value) { +void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { // Only absolute symbols can be redefined. assert((Symbol->isUndefined() || Symbol->isAbsolute()) && "Cannot define a symbol twice!"); @@ -327,8 +320,13 @@ void MCMachOStreamer::EmitBytes(const StringRef &Data) { DF->getContents().append(Data.begin(), Data.end()); } -void MCMachOStreamer::EmitValue(const MCValue &Value, unsigned Size) { - new MCFillFragment(AddValueSymbols(Value), Size, 1, CurSectionData); +void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size) { + MCValue RelocValue; + + if (!AddValueSymbols(Value)->EvaluateAsRelocatable(getContext(), RelocValue)) + return llvm_report_error("expected relocatable expression"); + + new MCFillFragment(RelocValue, Size, 1, CurSectionData); } void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment, @@ -344,9 +342,15 @@ void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment, CurSectionData->setAlignment(ByteAlignment); } -void MCMachOStreamer::EmitValueToOffset(const MCValue &Offset, +void MCMachOStreamer::EmitValueToOffset(const MCExpr *Offset, unsigned char Value) { - new MCOrgFragment(AddValueSymbols(Offset), Value, CurSectionData); + MCValue RelocOffset; + + if (!AddValueSymbols(Offset)->EvaluateAsRelocatable(getContext(), + RelocOffset)) + return llvm_report_error("expected relocatable expression"); + + new MCOrgFragment(RelocOffset, Value, CurSectionData); } void MCMachOStreamer::EmitInstruction(const MCInst &Inst) { diff --git a/lib/MC/MCNullStreamer.cpp b/lib/MC/MCNullStreamer.cpp index 9ccea04..3cd22ca 100644 --- a/lib/MC/MCNullStreamer.cpp +++ b/lib/MC/MCNullStreamer.cpp @@ -13,7 +13,6 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/MC/MCValue.h" using namespace llvm; @@ -34,7 +33,7 @@ namespace { virtual void EmitAssemblerFlag(AssemblerFlag Flag) {} - virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value) {} + virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {} virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute) {} @@ -48,13 +47,13 @@ namespace { virtual void EmitBytes(const StringRef &Data) {} - virtual void EmitValue(const MCValue &Value, unsigned Size) {} + virtual void EmitValue(const MCExpr *Value, unsigned Size) {} virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, unsigned ValueSize = 1, unsigned MaxBytesToEmit = 0) {} - virtual void EmitValueToOffset(const MCValue &Offset, + virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value = 0) {} virtual void EmitInstruction(const MCInst &Inst) {} |