llvm-mc: Switch MCExpr construction to using static member functions, and taking the MCContext (which now owns all MCExprs).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80569 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2009-08-31 08:07:22 +00:00
parent 869a5e7d66
commit 9643ac5514
4 changed files with 218 additions and 62 deletions

View File

@@ -13,9 +13,30 @@
#include "llvm/MC/MCValue.h"
using namespace llvm;
MCExpr::~MCExpr() {
const MCBinaryExpr * MCBinaryExpr::Create(Opcode Opc,
const MCExpr *LHS,
const MCExpr *RHS,
MCContext &Ctx) {
return new (Ctx) MCBinaryExpr(Opc, LHS, RHS);
}
const MCUnaryExpr * MCUnaryExpr::Create(Opcode Opc,
const MCExpr *Expr,
MCContext &Ctx) {
return new (Ctx) MCUnaryExpr(Opc, Expr);
}
const MCConstantExpr *MCConstantExpr::Create(int64_t Value, MCContext &Ctx) {
return new (Ctx) MCConstantExpr(Value);
}
const MCSymbolRefExpr *MCSymbolRefExpr::Create(const MCSymbol *Sym,
MCContext &Ctx) {
return new (Ctx) MCSymbolRefExpr(Sym);
}
/* *** */
bool MCExpr::EvaluateAsAbsolute(MCContext &Ctx, int64_t &Res) const {
MCValue Value;
@@ -50,19 +71,16 @@ static bool EvaluateSymbolicAdd(const MCValue &LHS, const MCSymbol *RHS_A,
bool MCExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
switch (getKind()) {
default:
assert(0 && "Invalid assembly expression kind!");
case Constant:
Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
return true;
case SymbolRef: {
MCSymbol *Sym = cast<MCSymbolRefExpr>(this)->getSymbol();
if (const MCValue *Value = Ctx.GetSymbolValue(Sym))
const MCSymbol &Sym = cast<MCSymbolRefExpr>(this)->getSymbol();
if (const MCValue *Value = Ctx.GetSymbolValue(&Sym))
Res = *Value;
else
Res = MCValue::get(Sym, 0, 0);
Res = MCValue::get(&Sym, 0, 0);
return true;
}
@@ -158,5 +176,7 @@ bool MCExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
return true;
}
}
}
assert(0 && "Invalid assembly expression kind!");
return false;
}