[llvm-commits] [llvm] r98791 - in /llvm/trunk: include/llvm/MC/MCValue.h lib/MC/MCAssembler.cpp lib/MC/MCExpr.cpp lib/MC/MCValue.cpp
Daniel Dunbar
daniel at zuster.org
Wed Mar 17 17:59:10 PDT 2010
Author: ddunbar
Date: Wed Mar 17 19:59:10 2010
New Revision: 98791
URL: http://llvm.org/viewvc/llvm-project?rev=98791&view=rev
Log:
MCValue: Change to holding MCSymbolRefExprs instead of MCSymbols, we will need this for accessing to symbol modifiers.
Modified:
llvm/trunk/include/llvm/MC/MCValue.h
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/lib/MC/MCValue.cpp
Modified: llvm/trunk/include/llvm/MC/MCValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCValue.h?rev=98791&r1=98790&r2=98791&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCValue.h (original)
+++ llvm/trunk/include/llvm/MC/MCValue.h Wed Mar 17 19:59:10 2010
@@ -19,8 +19,9 @@
#include <cassert>
namespace llvm {
-class MCSymbol;
class MCAsmInfo;
+class MCSymbol;
+class MCSymbolRefExpr;
class raw_ostream;
/// MCValue - This represents an "assembler immediate". In its most general
@@ -34,13 +35,13 @@
/// Note that this class must remain a simple POD value class, because we need
/// it to live in unions etc.
class MCValue {
- const MCSymbol *SymA, *SymB;
+ const MCSymbolRefExpr *SymA, *SymB;
int64_t Cst;
public:
int64_t getConstant() const { return Cst; }
- const MCSymbol *getSymA() const { return SymA; }
- const MCSymbol *getSymB() const { return SymB; }
+ const MCSymbolRefExpr *getSymA() const { return SymA; }
+ const MCSymbolRefExpr *getSymB() const { return SymB; }
/// isAbsolute - Is this an absolute (as opposed to relocatable) value.
bool isAbsolute() const { return !SymA && !SymB; }
@@ -57,11 +58,11 @@
/// print - Print the value to the stream \arg OS.
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
-
+
/// dump - Print the value to stderr.
void dump() const;
- static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB = 0,
+ static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=0,
int64_t Val = 0) {
MCValue R;
assert((!SymB || SymA) && "Invalid relocatable MCValue!");
@@ -70,7 +71,7 @@
R.SymB = SymB;
return R;
}
-
+
static MCValue get(int64_t Val) {
MCValue R;
R.Cst = Val;
@@ -78,7 +79,7 @@
R.SymB = 0;
return R;
}
-
+
};
} // end namespace llvm
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=98791&r1=98790&r2=98791&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Wed Mar 17 19:59:10 2010
@@ -478,7 +478,7 @@
unsigned Type = RIT_Vanilla;
// See <reloc.h>.
- const MCSymbol *A = Target.getSymA();
+ const MCSymbol *A = &Target.getSymA()->getSymbol();
MCSymbolData *A_SD = &Asm.getSymbolData(*A);
if (!A_SD->getFragment())
@@ -488,11 +488,11 @@
uint32_t Value = A_SD->getAddress();
uint32_t Value2 = 0;
- if (const MCSymbol *B = Target.getSymB()) {
- MCSymbolData *B_SD = &Asm.getSymbolData(*B);
+ if (const MCSymbolRefExpr *B = Target.getSymB()) {
+ MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());
if (!B_SD->getFragment())
- llvm_report_error("symbol '" + B->getName() +
+ llvm_report_error("symbol '" + B->getSymbol().getName() +
"' can not be undefined in a subtraction expression");
// Select the appropriate difference relocation type.
@@ -545,7 +545,7 @@
if (IsPCRel)
Offset += 1 << Log2Size;
if (Target.getSymB() ||
- (Target.getSymA() && !Target.getSymA()->isUndefined() &&
+ (Target.getSymA() && !Target.getSymA()->getSymbol().isUndefined() &&
Offset))
return ComputeScatteredRelocationInfo(Asm, Fragment, Fixup, Target,
Relocs);
@@ -565,7 +565,7 @@
Type = RIT_Vanilla;
Value = 0;
} else {
- const MCSymbol *Symbol = Target.getSymA();
+ const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
MCSymbolData *SD = &Asm.getSymbolData(*Symbol);
if (Symbol->isUndefined()) {
@@ -1033,28 +1033,28 @@
// atom, and so the value is resolved. We need explicit atom's to implement
// this more precisely.
bool IsResolved = true, IsPCRel = isFixupKindPCRel(Fixup.Kind);
- if (const MCSymbol *Symbol = Target.getSymA()) {
- if (Symbol->isDefined())
- Value += getSymbolData(*Symbol).getAddress();
+ if (const MCSymbolRefExpr *A = Target.getSymA()) {
+ if (A->getSymbol().isDefined())
+ Value += getSymbolData(A->getSymbol()).getAddress();
else
IsResolved = false;
// With scattered symbols, we assume anything that isn't a PCrel temporary
// access can have an arbitrary value.
if (getBackend().hasScatteredSymbols() &&
- (!IsPCRel || !Symbol->isTemporary()))
+ (!IsPCRel || !A->getSymbol().isTemporary()))
IsResolved = false;
}
- if (const MCSymbol *Symbol = Target.getSymB()) {
- if (Symbol->isDefined())
- Value -= getSymbolData(*Symbol).getAddress();
+ if (const MCSymbolRefExpr *B = Target.getSymB()) {
+ if (B->getSymbol().isDefined())
+ Value -= getSymbolData(B->getSymbol()).getAddress();
else
IsResolved = false;
// With scattered symbols, we assume anything that isn't a PCrel temporary
// access can have an arbitrary value.
if (getBackend().hasScatteredSymbols() &&
- (!IsPCRel || !Symbol->isTemporary()))
+ (!IsPCRel || !B->getSymbol().isTemporary()))
IsResolved = false;
}
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=98791&r1=98790&r2=98791&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Wed Mar 17 19:59:10 2010
@@ -30,7 +30,7 @@
case MCExpr::SymbolRef: {
const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
const MCSymbol &Sym = SRE.getSymbol();
-
+
// Parenthesize names that start with $ so that they don't look like
// absolute names.
if (Sym.getName()[0] == '$')
@@ -59,14 +59,14 @@
case MCExpr::Binary: {
const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this);
-
+
// Only print parens around the LHS if it is non-trivial.
if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) {
OS << *BE.getLHS();
} else {
OS << '(' << *BE.getLHS() << ')';
}
-
+
switch (BE.getOpcode()) {
default: assert(0 && "Invalid opcode!");
case MCBinaryExpr::Add:
@@ -77,7 +77,7 @@
return;
}
}
-
+
OS << '+';
break;
case MCBinaryExpr::And: OS << '&'; break;
@@ -98,7 +98,7 @@
case MCBinaryExpr::Sub: OS << '-'; break;
case MCBinaryExpr::Xor: OS << '^'; break;
}
-
+
// Only print parens around the LHS if it is non-trivial.
if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) {
OS << *BE.getRHS();
@@ -193,7 +193,7 @@
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const {
MCValue Value;
-
+
if (!EvaluateAsRelocatable(Value, Layout) || !Value.isAbsolute())
return false;
@@ -201,16 +201,16 @@
return true;
}
-static bool EvaluateSymbolicAdd(const MCValue &LHS, const MCSymbol *RHS_A,
- const MCSymbol *RHS_B, int64_t RHS_Cst,
+static bool EvaluateSymbolicAdd(const MCValue &LHS,const MCSymbolRefExpr *RHS_A,
+ const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst,
MCValue &Res) {
// We can't add or subtract two symbols.
if ((LHS.getSymA() && RHS_A) ||
(LHS.getSymB() && RHS_B))
return false;
- const MCSymbol *A = LHS.getSymA() ? LHS.getSymA() : RHS_A;
- const MCSymbol *B = LHS.getSymB() ? LHS.getSymB() : RHS_B;
+ const MCSymbolRefExpr *A = LHS.getSymA() ? LHS.getSymA() : RHS_A;
+ const MCSymbolRefExpr *B = LHS.getSymB() ? LHS.getSymB() : RHS_B;
if (B) {
// If we have a negated symbol, then we must have also have a non-negated
// symbol in order to encode the expression. We can do this check later to
@@ -228,13 +228,14 @@
switch (getKind()) {
case Target:
return cast<MCTargetExpr>(this)->EvaluateAsRelocatableImpl(Res, Layout);
-
+
case Constant:
Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
return true;
case SymbolRef: {
- const MCSymbol &Sym = cast<MCSymbolRefExpr>(this)->getSymbol();
+ const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
+ const MCSymbol &Sym = SRE->getSymbol();
// Evaluate recursively if this is a variable.
if (Sym.isVariable()) {
@@ -245,9 +246,12 @@
// layout object and the target requests it.
if (Layout && Res.getSymB() &&
Layout->getAssembler().getBackend().hasAbsolutizedSet() &&
- Res.getSymA()->isDefined() && Res.getSymB()->isDefined()) {
- MCSymbolData &A = Layout->getAssembler().getSymbolData(*Res.getSymA());
- MCSymbolData &B = Layout->getAssembler().getSymbolData(*Res.getSymB());
+ Res.getSymA()->getSymbol().isDefined() &&
+ Res.getSymB()->getSymbol().isDefined()) {
+ MCSymbolData &A =
+ Layout->getAssembler().getSymbolData(Res.getSymA()->getSymbol());
+ MCSymbolData &B =
+ Layout->getAssembler().getSymbolData(Res.getSymB()->getSymbol());
Res = MCValue::get(+ A.getFragment()->getAddress() + A.getOffset()
- B.getFragment()->getAddress() - B.getOffset()
+ Res.getConstant());
@@ -256,7 +260,7 @@
return true;
}
- Res = MCValue::get(&Sym, 0, 0);
+ Res = MCValue::get(SRE, 0, 0);
return true;
}
@@ -277,13 +281,13 @@
/// -(a - b + const) ==> (b - a - const)
if (Value.getSymA() && !Value.getSymB())
return false;
- Res = MCValue::get(Value.getSymB(), Value.getSymA(),
- -Value.getConstant());
+ Res = MCValue::get(Value.getSymB(), Value.getSymA(),
+ -Value.getConstant());
break;
case MCUnaryExpr::Not:
if (!Value.isAbsolute())
return false;
- Res = MCValue::get(~Value.getConstant());
+ Res = MCValue::get(~Value.getConstant());
break;
case MCUnaryExpr::Plus:
Res = Value;
@@ -296,7 +300,7 @@
case Binary: {
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
MCValue LHSValue, RHSValue;
-
+
if (!ABE->getLHS()->EvaluateAsRelocatable(LHSValue, Layout) ||
!ABE->getRHS()->EvaluateAsRelocatable(RHSValue, Layout))
return false;
Modified: llvm/trunk/lib/MC/MCValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCValue.cpp?rev=98791&r1=98790&r2=98791&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCValue.cpp (original)
+++ llvm/trunk/lib/MC/MCValue.cpp Wed Mar 17 19:59:10 2010
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCValue.h"
+#include "llvm/MC/MCExpr.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -19,10 +20,12 @@
return;
}
- OS << *getSymA();
+ getSymA()->print(OS);
- if (getSymB())
- OS << " - " << *getSymB();
+ if (getSymB()) {
+ OS << " - ";
+ getSymB()->print(OS);
+ }
if (getConstant())
OS << " + " << getConstant();
More information about the llvm-commits
mailing list