add scaffolding for target-specific MCExprs.
authorChris Lattner <sabre@nondot.org>
Mon, 8 Feb 2010 19:41:07 +0000 (19:41 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 8 Feb 2010 19:41:07 +0000 (19:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95559 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCExpr.h
lib/MC/MCExpr.cpp
lib/MC/MCMachOStreamer.cpp

index 73d5f8ef51516b055647ce5784c089bd6dc0e2d2..ca30b1e444f2ad54e991114d574b868790b6369d 100644 (file)
@@ -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
index 1ee1b1bddb7b10da7a0e5ae11f0addc7fa20ffb8..07546c1b29b0e0c3dcf33f44cc4f296a071cec1e 100644 (file)
@@ -17,6 +17,8 @@ using namespace llvm;
 
 void MCExpr::print(raw_ostream &OS) const {
   switch (getKind()) {
+  case MCExpr::Target:
+    return cast<MCTargetExpr>(this)->PrintImpl(OS);
   case MCExpr::Constant:
     OS << cast<MCConstantExpr>(*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<MCTargetExpr>(this)->EvaluateAsRelocatableImpl(Res);
+      
   case Constant:
     Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
     return true;
index 981eb72d14c9993bf24050d40b8112a9df65b8cb..40a21ad5dd23575f000b056c465f7de2d0140b87 100644 (file)
@@ -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;