MC: Sketch initial MCAsmLayout class, which encapsulates the current layout of an assembly file. The MCAsmLayout is also available for use by MCExpr::EvaluateAs{Absolute,Relocatable}, to allow target specific hooks and "absolutizing" of symbols.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98227 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp
index 4439eba..e364069 100644
--- a/lib/MC/MCExpr.cpp
+++ b/lib/MC/MCExpr.cpp
@@ -142,10 +142,10 @@
/* *** */
-bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const {
+bool MCExpr::EvaluateAsAbsolute(int64_t &Res, MCAsmLayout *Layout) const {
MCValue Value;
- if (!EvaluateAsRelocatable(Value) || !Value.isAbsolute())
+ if (!EvaluateAsRelocatable(Value, Layout) || !Value.isAbsolute())
return false;
Res = Value.getConstant();
@@ -174,10 +174,10 @@
return true;
}
-bool MCExpr::EvaluateAsRelocatable(MCValue &Res) const {
+bool MCExpr::EvaluateAsRelocatable(MCValue &Res, MCAsmLayout *Layout) const {
switch (getKind()) {
case Target:
- return cast<MCTargetExpr>(this)->EvaluateAsRelocatableImpl(Res);
+ return cast<MCTargetExpr>(this)->EvaluateAsRelocatableImpl(Res, Layout);
case Constant:
Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
@@ -188,7 +188,7 @@
// Evaluate recursively if this is a variable.
if (Sym.isVariable())
- return Sym.getValue()->EvaluateAsRelocatable(Res);
+ return Sym.getValue()->EvaluateAsRelocatable(Res, Layout);
Res = MCValue::get(&Sym, 0, 0);
return true;
@@ -198,7 +198,7 @@
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
MCValue Value;
- if (!AUE->getSubExpr()->EvaluateAsRelocatable(Value))
+ if (!AUE->getSubExpr()->EvaluateAsRelocatable(Value, Layout))
return false;
switch (AUE->getOpcode()) {
@@ -231,8 +231,8 @@
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
MCValue LHSValue, RHSValue;
- if (!ABE->getLHS()->EvaluateAsRelocatable(LHSValue) ||
- !ABE->getRHS()->EvaluateAsRelocatable(RHSValue))
+ if (!ABE->getLHS()->EvaluateAsRelocatable(LHSValue, Layout) ||
+ !ABE->getRHS()->EvaluateAsRelocatable(RHSValue, Layout))
return false;
// We only support a few operations on non-constant expressions, handle
diff --git a/lib/Target/X86/X86MCTargetExpr.cpp b/lib/Target/X86/X86MCTargetExpr.cpp
index 17b4fe8..de56d31 100644
--- a/lib/Target/X86/X86MCTargetExpr.cpp
+++ b/lib/Target/X86/X86MCTargetExpr.cpp
@@ -36,12 +36,13 @@
}
}
-bool X86MCTargetExpr::EvaluateAsRelocatableImpl(MCValue &Res) const {
+bool X86MCTargetExpr::EvaluateAsRelocatableImpl(MCValue &Res,
+ MCAsmLayout *Layout) const {
// FIXME: I don't know if this is right, it followed MCSymbolRefExpr.
// Evaluate recursively if this is a variable.
if (Sym->isVariable())
- return Sym->getValue()->EvaluateAsRelocatable(Res);
+ return Sym->getValue()->EvaluateAsRelocatable(Res, Layout);
Res = MCValue::get(Sym, 0, 0);
return true;
diff --git a/lib/Target/X86/X86MCTargetExpr.h b/lib/Target/X86/X86MCTargetExpr.h
index 7de8a5c..56011eb 100644
--- a/lib/Target/X86/X86MCTargetExpr.h
+++ b/lib/Target/X86/X86MCTargetExpr.h
@@ -41,7 +41,7 @@
MCContext &Ctx);
void PrintImpl(raw_ostream &OS) const;
- bool EvaluateAsRelocatableImpl(MCValue &Res) const;
+ bool EvaluateAsRelocatableImpl(MCValue &Res, MCAsmLayout *Layout) const;
};
} // end namespace llvm