#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
/// 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; }
/// 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!");
R.SymB = SymB;
return R;
}
-
+
static MCValue get(int64_t Val) {
MCValue R;
R.Cst = Val;
R.SymB = 0;
return R;
}
-
+
};
} // end namespace llvm
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())
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.
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);
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()) {
// 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;
}
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] == '$')
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:
return;
}
}
-
+
OS << '+';
break;
case MCBinaryExpr::And: OS << '&'; break;
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();
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const {
MCValue Value;
-
+
if (!EvaluateAsRelocatable(Value, Layout) || !Value.isAbsolute())
return false;
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
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()) {
// 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());
return true;
}
- Res = MCValue::get(&Sym, 0, 0);
+ Res = MCValue::get(SRE, 0, 0);
return true;
}
/// -(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;
case Binary: {
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
MCValue LHSValue, RHSValue;
-
+
if (!ABE->getLHS()->EvaluateAsRelocatable(LHSValue, Layout) ||
!ABE->getRHS()->EvaluateAsRelocatable(RHSValue, Layout))
return false;
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCValue.h"
+#include "llvm/MC/MCExpr.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
return;
}
- OS << *getSymA();
+ getSymA()->print(OS);
- if (getSymB())
- OS << " - " << *getSymB();
+ if (getSymB()) {
+ OS << " - ";
+ getSymB()->print(OS);
+ }
if (getConstant())
OS << " + " << getConstant();