From 22373b230a053a154f6c7792c6a33d4f78f5479d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 6 Dec 2010 22:30:54 +0000 Subject: [PATCH] Use references to simplify the code a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121050 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCExpr.h | 8 ++++---- lib/MC/MCAssembler.cpp | 6 +++--- lib/MC/MCExpr.cpp | 11 ++++------- lib/MC/MCObjectStreamer.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h index e953a111868..888934e822f 100644 --- a/include/llvm/MC/MCExpr.h +++ b/include/llvm/MC/MCExpr.h @@ -41,6 +41,8 @@ private: MCExpr(const MCExpr&); // DO NOT IMPLEMENT void operator=(const MCExpr&); // DO NOT IMPLEMENT + bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, + const MCAsmLayout *Layout) const; protected: explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {} @@ -72,10 +74,8 @@ public: /// evaluated. /// @result - True on success. bool EvaluateAsAbsolute(int64_t &Res) const; - bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const; - bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const; - bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, - const MCAsmLayout *Layout) const; + bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const; + bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const; /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable /// value, i.e. an expression of the fixed form (a - b + constant). diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index e13b3adea43..299eb0ab67c 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -780,7 +780,7 @@ bool MCAssembler::RelaxOrg(const MCObjectWriter &Writer, MCAsmLayout &Layout, MCOrgFragment &OF) { int64_t TargetLocation; - if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, &Layout)) + if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, Layout)) report_fatal_error("expected assembly-time absolute expression"); // FIXME: We need a way to communicate this error. @@ -800,7 +800,7 @@ bool MCAssembler::RelaxLEB(const MCObjectWriter &Writer, MCLEBFragment &LF) { int64_t Value = 0; uint64_t OldSize = LF.getContents().size(); - LF.getValue().EvaluateAsAbsolute(Value, &Layout); + LF.getValue().EvaluateAsAbsolute(Value, Layout); SmallString<8> &Data = LF.getContents(); Data.clear(); raw_svector_ostream OSE(Data); @@ -817,7 +817,7 @@ bool MCAssembler::RelaxDwarfLineAddr(const MCObjectWriter &Writer, MCDwarfLineAddrFragment &DF) { int64_t AddrDelta = 0; uint64_t OldSize = DF.getContents().size(); - DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, &Layout); + DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout); int64_t LineDelta; LineDelta = DF.getLineDelta(); SmallString<8> &Data = DF.getContents(); diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index cee5673bc07..b4712c20355 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -242,15 +242,12 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const { } bool MCExpr::EvaluateAsAbsolute(int64_t &Res, - const MCAsmLayout *Layout) const { - if (Layout) - return EvaluateAsAbsolute(Res, &Layout->getAssembler(), Layout); - else - return EvaluateAsAbsolute(Res, 0, 0); + const MCAsmLayout &Layout) const { + return EvaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout); } -bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const { - return EvaluateAsAbsolute(Res, Asm, 0); +bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const { + return EvaluateAsAbsolute(Res, &Asm, 0); } bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index ad8fb495840..6348a2b69ec 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -83,7 +83,7 @@ void MCObjectStreamer::EmitValue(const MCExpr *Value, unsigned Size, // Avoid fixups when possible. int64_t AbsValue; - if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue, &getAssembler())) { + if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue, getAssembler())) { EmitIntValue(AbsValue, Size, AddrSpace); return; } @@ -114,7 +114,7 @@ void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) { void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace) { int64_t IntValue; - if (Value->EvaluateAsAbsolute(IntValue, &getAssembler())) { + if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) { EmitULEB128IntValue(IntValue, AddrSpace); return; } @@ -124,7 +124,7 @@ void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value, void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace) { int64_t IntValue; - if (Value->EvaluateAsAbsolute(IntValue, &getAssembler())) { + if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) { EmitSLEB128IntValue(IntValue, AddrSpace); return; } @@ -204,7 +204,7 @@ void MCObjectStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta, MCBinaryExpr::Create(MCBinaryExpr::Sub, LabelRef, LastLabelRef, getContext()); int64_t Res; - if (AddrDelta->EvaluateAsAbsolute(Res, &getAssembler())) { + if (AddrDelta->EvaluateAsAbsolute(Res, getAssembler())) { MCDwarfLineAddr::Emit(this, LineDelta, Res); return; } -- 2.34.1