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
This commit is contained in:
Rafael Espindola 2010-12-06 22:30:54 +00:00
parent a3b2200472
commit 22373b230a
4 changed files with 15 additions and 18 deletions

View File

@ -41,6 +41,8 @@ private:
MCExpr(const MCExpr&); // DO NOT IMPLEMENT MCExpr(const MCExpr&); // DO NOT IMPLEMENT
void operator=(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: protected:
explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {} explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
@ -72,10 +74,8 @@ public:
/// evaluated. /// evaluated.
/// @result - True on success. /// @result - True on success.
bool EvaluateAsAbsolute(int64_t &Res) const; bool EvaluateAsAbsolute(int64_t &Res) const;
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) 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 MCAsmLayout &Layout) const;
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout) const;
/// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
/// value, i.e. an expression of the fixed form (a - b + constant). /// value, i.e. an expression of the fixed form (a - b + constant).

View File

@ -780,7 +780,7 @@ bool MCAssembler::RelaxOrg(const MCObjectWriter &Writer,
MCAsmLayout &Layout, MCAsmLayout &Layout,
MCOrgFragment &OF) { MCOrgFragment &OF) {
int64_t TargetLocation; int64_t TargetLocation;
if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, &Layout)) if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, Layout))
report_fatal_error("expected assembly-time absolute expression"); report_fatal_error("expected assembly-time absolute expression");
// FIXME: We need a way to communicate this error. // FIXME: We need a way to communicate this error.
@ -800,7 +800,7 @@ bool MCAssembler::RelaxLEB(const MCObjectWriter &Writer,
MCLEBFragment &LF) { MCLEBFragment &LF) {
int64_t Value = 0; int64_t Value = 0;
uint64_t OldSize = LF.getContents().size(); uint64_t OldSize = LF.getContents().size();
LF.getValue().EvaluateAsAbsolute(Value, &Layout); LF.getValue().EvaluateAsAbsolute(Value, Layout);
SmallString<8> &Data = LF.getContents(); SmallString<8> &Data = LF.getContents();
Data.clear(); Data.clear();
raw_svector_ostream OSE(Data); raw_svector_ostream OSE(Data);
@ -817,7 +817,7 @@ bool MCAssembler::RelaxDwarfLineAddr(const MCObjectWriter &Writer,
MCDwarfLineAddrFragment &DF) { MCDwarfLineAddrFragment &DF) {
int64_t AddrDelta = 0; int64_t AddrDelta = 0;
uint64_t OldSize = DF.getContents().size(); uint64_t OldSize = DF.getContents().size();
DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, &Layout); DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout);
int64_t LineDelta; int64_t LineDelta;
LineDelta = DF.getLineDelta(); LineDelta = DF.getLineDelta();
SmallString<8> &Data = DF.getContents(); SmallString<8> &Data = DF.getContents();

View File

@ -242,15 +242,12 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const {
} }
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, bool MCExpr::EvaluateAsAbsolute(int64_t &Res,
const MCAsmLayout *Layout) const { const MCAsmLayout &Layout) const {
if (Layout) return EvaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout);
return EvaluateAsAbsolute(Res, &Layout->getAssembler(), Layout);
else
return EvaluateAsAbsolute(Res, 0, 0);
} }
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const { bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
return EvaluateAsAbsolute(Res, Asm, 0); return EvaluateAsAbsolute(Res, &Asm, 0);
} }
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,

View File

@ -83,7 +83,7 @@ void MCObjectStreamer::EmitValue(const MCExpr *Value, unsigned Size,
// Avoid fixups when possible. // Avoid fixups when possible.
int64_t AbsValue; int64_t AbsValue;
if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue, &getAssembler())) { if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue, getAssembler())) {
EmitIntValue(AbsValue, Size, AddrSpace); EmitIntValue(AbsValue, Size, AddrSpace);
return; return;
} }
@ -114,7 +114,7 @@ void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) {
void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value, void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value,
unsigned AddrSpace) { unsigned AddrSpace) {
int64_t IntValue; int64_t IntValue;
if (Value->EvaluateAsAbsolute(IntValue, &getAssembler())) { if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) {
EmitULEB128IntValue(IntValue, AddrSpace); EmitULEB128IntValue(IntValue, AddrSpace);
return; return;
} }
@ -124,7 +124,7 @@ void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value,
void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value, void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value,
unsigned AddrSpace) { unsigned AddrSpace) {
int64_t IntValue; int64_t IntValue;
if (Value->EvaluateAsAbsolute(IntValue, &getAssembler())) { if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) {
EmitSLEB128IntValue(IntValue, AddrSpace); EmitSLEB128IntValue(IntValue, AddrSpace);
return; return;
} }
@ -204,7 +204,7 @@ void MCObjectStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
MCBinaryExpr::Create(MCBinaryExpr::Sub, LabelRef, LastLabelRef, MCBinaryExpr::Create(MCBinaryExpr::Sub, LabelRef, LastLabelRef,
getContext()); getContext());
int64_t Res; int64_t Res;
if (AddrDelta->EvaluateAsAbsolute(Res, &getAssembler())) { if (AddrDelta->EvaluateAsAbsolute(Res, getAssembler())) {
MCDwarfLineAddr::Emit(this, LineDelta, Res); MCDwarfLineAddr::Emit(this, LineDelta, Res);
return; return;
} }