diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-08-31 08:07:22 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-08-31 08:07:22 +0000 |
commit | f363645da20a289a5f72f72a503679402cb9d291 (patch) | |
tree | 8070daf115cf34440ed1332ff116cde2dfd53d68 /llvm/lib/MC/MCExpr.cpp | |
parent | aecc936ea0f40f98af99e5e544d5b82d65881262 (diff) | |
download | bcm5719-llvm-f363645da20a289a5f72f72a503679402cb9d291.tar.gz bcm5719-llvm-f363645da20a289a5f72f72a503679402cb9d291.zip |
llvm-mc: Switch MCExpr construction to using static member functions, and taking the MCContext (which now owns all MCExprs).
llvm-svn: 80569
Diffstat (limited to 'llvm/lib/MC/MCExpr.cpp')
-rw-r--r-- | llvm/lib/MC/MCExpr.cpp | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index 91ef7e77ec8..10759687b2f 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -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; +} |