aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MC
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-31 08:07:22 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-31 08:07:22 +0000
commit9643ac55142d40da404caa8e5fedfef2cd7b4afc (patch)
treef925fcae59497a061b91541242aeb85adfcea514 /lib/MC
parent869a5e7d66cdc756608190bff1e837fe5809d16e (diff)
downloadexternal_llvm-9643ac55142d40da404caa8e5fedfef2cd7b4afc.zip
external_llvm-9643ac55142d40da404caa8e5fedfef2cd7b4afc.tar.gz
external_llvm-9643ac55142d40da404caa8e5fedfef2cd7b4afc.tar.bz2
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
Diffstat (limited to 'lib/MC')
-rw-r--r--lib/MC/MCExpr.cpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp
index 91ef7e7..1075968 100644
--- a/lib/MC/MCExpr.cpp
+++ b/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;
+}