From: Chris Lattner Date: Mon, 8 Feb 2010 19:41:07 +0000 (+0000) Subject: add scaffolding for target-specific MCExprs. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=5d917a8952c09a345180ec36f0df4ee5dd5eddea;p=oota-llvm.git add scaffolding for target-specific MCExprs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95559 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h index 73d5f8ef515..ca30b1e444f 100644 --- a/include/llvm/MC/MCExpr.h +++ b/include/llvm/MC/MCExpr.h @@ -29,7 +29,8 @@ public: Binary, ///< Binary expressions. Constant, ///< Constant expressions. SymbolRef, ///< References to labels and assigned expressions. - Unary ///< Unary expressions. + Unary, ///< Unary expressions. + Target ///< Target specific expression. }; private: @@ -326,6 +327,28 @@ public: static bool classof(const MCBinaryExpr *) { return true; } }; +/// MCTargetExpr - This is an extension point for target-specific MCExpr +/// subclasses to implement. +/// +/// NOTE: All subclasses are required to have trivial destructors because +/// MCExprs are bump pointer allocated and not destructed. +class MCTargetExpr : public MCExpr { + virtual ~MCTargetExpr(); // Not accessible. +protected: + MCTargetExpr() : MCExpr(Target) {} + +public: + + virtual void PrintImpl(raw_ostream &OS) const = 0; + virtual bool EvaluateAsRelocatableImpl(MCValue &Res) const = 0; + + + static bool classof(const MCExpr *E) { + return E->getKind() == MCExpr::Target; + } + static bool classof(const MCTargetExpr *) { return true; } +}; + } // end namespace llvm #endif diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index 1ee1b1bddb7..07546c1b29b 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -17,6 +17,8 @@ using namespace llvm; void MCExpr::print(raw_ostream &OS) const { switch (getKind()) { + case MCExpr::Target: + return cast(this)->PrintImpl(OS); case MCExpr::Constant: OS << cast(*this).getValue(); return; @@ -131,6 +133,7 @@ const MCSymbolRefExpr *MCSymbolRefExpr::Create(StringRef Name, MCContext &Ctx) { return Create(Ctx.GetOrCreateSymbol(Name), Ctx); } +MCTargetExpr::~MCTargetExpr() {} /* *** */ @@ -168,6 +171,9 @@ static bool EvaluateSymbolicAdd(const MCValue &LHS, const MCSymbol *RHS_A, bool MCExpr::EvaluateAsRelocatable(MCValue &Res) const { switch (getKind()) { + case Target: + return cast(this)->EvaluateAsRelocatableImpl(Res); + case Constant: Res = MCValue::get(cast(this)->getValue()); return true; diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 981eb72d14c..40a21ad5dd2 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -87,6 +87,7 @@ public: const MCExpr *AddValueSymbols(const MCExpr *Value) { switch (Value->getKind()) { + case MCExpr::Target: assert(0 && "Can't handle target exprs yet!"); case MCExpr::Constant: break;