[llvm-commits] [llvm] r80567 - in /llvm/trunk: include/llvm/MC/MCExpr.h lib/MC/CMakeLists.txt lib/MC/MCExpr.cpp tools/llvm-mc/AsmExpr.cpp tools/llvm-mc/AsmExpr.h tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h tools/llvm-mc/CMakeLists.txt

Daniel Dunbar daniel at zuster.org
Mon Aug 31 01:07:00 PDT 2009


Author: ddunbar
Date: Mon Aug 31 03:06:59 2009
New Revision: 80567

URL: http://llvm.org/viewvc/llvm-project?rev=80567&view=rev
Log:
llvm-mc: Move AsmExpr into MC lib (as MCExpr).

Added:
    llvm/trunk/include/llvm/MC/MCExpr.h
      - copied, changed from r80566, llvm/trunk/tools/llvm-mc/AsmExpr.h
    llvm/trunk/lib/MC/MCExpr.cpp
      - copied, changed from r80566, llvm/trunk/tools/llvm-mc/AsmExpr.cpp
Removed:
    llvm/trunk/tools/llvm-mc/AsmExpr.cpp
    llvm/trunk/tools/llvm-mc/AsmExpr.h
Modified:
    llvm/trunk/lib/MC/CMakeLists.txt
    llvm/trunk/tools/llvm-mc/AsmParser.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.h
    llvm/trunk/tools/llvm-mc/CMakeLists.txt

Copied: llvm/trunk/include/llvm/MC/MCExpr.h (from r80566, llvm/trunk/tools/llvm-mc/AsmExpr.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCExpr.h?p2=llvm/trunk/include/llvm/MC/MCExpr.h&p1=llvm/trunk/tools/llvm-mc/AsmExpr.h&r1=80566&r2=80567&rev=80567&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmExpr.h (original)
+++ llvm/trunk/include/llvm/MC/MCExpr.h Mon Aug 31 03:06:59 2009
@@ -1,4 +1,4 @@
-//===- AsmExpr.h - Assembly file expressions --------------------*- C++ -*-===//
+//===- MCExpr.h - Assembly Level Expressions --------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef ASMEXPR_H
-#define ASMEXPR_H
+#ifndef LLVM_MC_MCEXPR_H
+#define LLVM_MC_MCEXPR_H
 
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/DataTypes.h"
@@ -18,11 +18,11 @@
 class MCSymbol;
 class MCValue;
 
-/// AsmExpr - Base class for the full range of assembler expressions which are
+/// MCExpr - Base class for the full range of assembler expressions which are
 /// needed for parsing.  
-class AsmExpr {
+class MCExpr {
 public:
-  enum AsmExprKind {
+  enum ExprKind {
     Binary,    ///< Binary expressions.
     Constant,  ///< Constant expressions.
     SymbolRef, ///< References to labels and assigned expressions.
@@ -30,15 +30,15 @@
   };
   
 private:
-  AsmExprKind Kind;
+  ExprKind Kind;
   
 protected:
-  AsmExpr(AsmExprKind _Kind) : Kind(_Kind) {}
+  MCExpr(ExprKind _Kind) : Kind(_Kind) {}
   
 public:
-  virtual ~AsmExpr();
+  virtual ~MCExpr();
 
-  AsmExprKind getKind() const { return Kind; }
+  ExprKind getKind() const { return Kind; }
 
   /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
   ///
@@ -53,48 +53,48 @@
   /// @result - True on success.
   bool EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const;
 
-  static bool classof(const AsmExpr *) { return true; }
+  static bool classof(const MCExpr *) { return true; }
 };
 
-//// AsmConstantExpr - Represent a constant integer expression.
-class AsmConstantExpr : public AsmExpr {
+//// MCConstantExpr - Represent a constant integer expression.
+class MCConstantExpr : public MCExpr {
   int64_t Value;
 
 public:
-  AsmConstantExpr(int64_t _Value) 
-    : AsmExpr(AsmExpr::Constant), Value(_Value) {}
+  MCConstantExpr(int64_t _Value) 
+    : MCExpr(MCExpr::Constant), Value(_Value) {}
   
   int64_t getValue() const { return Value; }
 
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::Constant; 
+  static bool classof(const MCExpr *E) { 
+    return E->getKind() == MCExpr::Constant; 
   }
-  static bool classof(const AsmConstantExpr *) { return true; }
+  static bool classof(const MCConstantExpr *) { return true; }
 };
 
-/// AsmSymbolRefExpr - Represent a reference to a symbol from inside an
+/// MCSymbolRefExpr - Represent a reference to a symbol from inside an
 /// expression.
 ///
 /// A symbol reference in an expression may be a use of a label, a use of an
 /// assembler variable (defined constant), or constitute an implicit definition
 /// of the symbol as external.
-class AsmSymbolRefExpr : public AsmExpr {
+class MCSymbolRefExpr : public MCExpr {
   MCSymbol *Symbol;
 
 public:
-  AsmSymbolRefExpr(MCSymbol *_Symbol) 
-    : AsmExpr(AsmExpr::SymbolRef), Symbol(_Symbol) {}
+  MCSymbolRefExpr(MCSymbol *_Symbol) 
+    : MCExpr(MCExpr::SymbolRef), Symbol(_Symbol) {}
   
   MCSymbol *getSymbol() const { return Symbol; }
 
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::SymbolRef; 
+  static bool classof(const MCExpr *E) { 
+    return E->getKind() == MCExpr::SymbolRef; 
   }
-  static bool classof(const AsmSymbolRefExpr *) { return true; }
+  static bool classof(const MCSymbolRefExpr *) { return true; }
 };
 
-/// AsmUnaryExpr - Unary assembler expressions.
-class AsmUnaryExpr : public AsmExpr {
+/// MCUnaryExpr - Unary assembler expressions.
+class MCUnaryExpr : public MCExpr {
 public:
   enum Opcode {
     LNot,  ///< Logical negation.
@@ -105,27 +105,27 @@
 
 private:
   Opcode Op;
-  AsmExpr *Expr;
+  MCExpr *Expr;
 
 public:
-  AsmUnaryExpr(Opcode _Op, AsmExpr *_Expr)
-    : AsmExpr(AsmExpr::Unary), Op(_Op), Expr(_Expr) {}
-  ~AsmUnaryExpr() {
+  MCUnaryExpr(Opcode _Op, MCExpr *_Expr)
+    : MCExpr(MCExpr::Unary), Op(_Op), Expr(_Expr) {}
+  ~MCUnaryExpr() {
     delete Expr;
   }
 
   Opcode getOpcode() const { return Op; }
 
-  AsmExpr *getSubExpr() const { return Expr; }
+  MCExpr *getSubExpr() const { return Expr; }
 
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::Unary; 
+  static bool classof(const MCExpr *E) { 
+    return E->getKind() == MCExpr::Unary; 
   }
-  static bool classof(const AsmUnaryExpr *) { return true; }
+  static bool classof(const MCUnaryExpr *) { return true; }
 };
 
-/// AsmBinaryExpr - Binary assembler expressions.
-class AsmBinaryExpr : public AsmExpr {
+/// MCBinaryExpr - Binary assembler expressions.
+class MCBinaryExpr : public MCExpr {
 public:
   enum Opcode {
     Add,  ///< Addition.
@@ -150,12 +150,12 @@
 
 private:
   Opcode Op;
-  AsmExpr *LHS, *RHS;
+  MCExpr *LHS, *RHS;
 
 public:
-  AsmBinaryExpr(Opcode _Op, AsmExpr *_LHS, AsmExpr *_RHS)
-    : AsmExpr(AsmExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
-  ~AsmBinaryExpr() {
+  MCBinaryExpr(Opcode _Op, MCExpr *_LHS, MCExpr *_RHS)
+    : MCExpr(MCExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
+  ~MCBinaryExpr() {
     delete LHS;
     delete RHS;
   }
@@ -163,15 +163,15 @@
   Opcode getOpcode() const { return Op; }
 
   /// getLHS - Get the left-hand side expression of the binary operator.
-  AsmExpr *getLHS() const { return LHS; }
+  MCExpr *getLHS() const { return LHS; }
 
   /// getRHS - Get the right-hand side expression of the binary operator.
-  AsmExpr *getRHS() const { return RHS; }
+  MCExpr *getRHS() const { return RHS; }
 
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::Binary; 
+  static bool classof(const MCExpr *E) { 
+    return E->getKind() == MCExpr::Binary; 
   }
-  static bool classof(const AsmBinaryExpr *) { return true; }
+  static bool classof(const MCBinaryExpr *) { return true; }
 };
 
 } // end namespace llvm

Modified: llvm/trunk/lib/MC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/CMakeLists.txt?rev=80567&r1=80566&r2=80567&view=diff

==============================================================================
--- llvm/trunk/lib/MC/CMakeLists.txt (original)
+++ llvm/trunk/lib/MC/CMakeLists.txt Mon Aug 31 03:06:59 2009
@@ -8,6 +8,7 @@
   MCAssembler.cpp
   MCCodeEmitter.cpp
   MCContext.cpp
+  MCExpr.cpp
   MCInst.cpp
   MCMachOStreamer.cpp
   MCNullStreamer.cpp

Copied: llvm/trunk/lib/MC/MCExpr.cpp (from r80566, llvm/trunk/tools/llvm-mc/AsmExpr.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?p2=llvm/trunk/lib/MC/MCExpr.cpp&p1=llvm/trunk/tools/llvm-mc/AsmExpr.cpp&r1=80566&r2=80567&rev=80567&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Mon Aug 31 03:06:59 2009
@@ -1,4 +1,4 @@
-//===- AsmExpr.cpp - Assembly file expressions ----------------------------===//
+//===- MCExpr.cpp - Assembly Level Expression Implementation --------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,16 +7,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "AsmExpr.h"
+#include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/MC/MCValue.h"
 using namespace llvm;
 
-AsmExpr::~AsmExpr() {
+MCExpr::~MCExpr() {
 }
 
-bool AsmExpr::EvaluateAsAbsolute(MCContext &Ctx, int64_t &Res) const {
+bool MCExpr::EvaluateAsAbsolute(MCContext &Ctx, int64_t &Res) const {
   MCValue Value;
   
   if (!EvaluateAsRelocatable(Ctx, Value) || !Value.isAbsolute())
@@ -48,17 +48,17 @@
   return true;
 }
 
-bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
+bool MCExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
   switch (getKind()) {
   default:
     assert(0 && "Invalid assembly expression kind!");
 
   case Constant:
-    Res = MCValue::get(cast<AsmConstantExpr>(this)->getValue());
+    Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
     return true;
 
   case SymbolRef: {
-    MCSymbol *Sym = cast<AsmSymbolRefExpr>(this)->getSymbol();
+    MCSymbol *Sym = cast<MCSymbolRefExpr>(this)->getSymbol();
     if (const MCValue *Value = Ctx.GetSymbolValue(Sym))
       Res = *Value;
     else
@@ -67,31 +67,31 @@
   }
 
   case Unary: {
-    const AsmUnaryExpr *AUE = cast<AsmUnaryExpr>(this);
+    const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
     MCValue Value;
 
     if (!AUE->getSubExpr()->EvaluateAsRelocatable(Ctx, Value))
       return false;
 
     switch (AUE->getOpcode()) {
-    case AsmUnaryExpr::LNot:
+    case MCUnaryExpr::LNot:
       if (!Value.isAbsolute())
         return false;
       Res = MCValue::get(!Value.getConstant());
       break;
-    case AsmUnaryExpr::Minus:
+    case MCUnaryExpr::Minus:
       /// -(a - b + const) ==> (b - a - const)
       if (Value.getSymA() && !Value.getSymB())
         return false;
       Res = MCValue::get(Value.getSymB(), Value.getSymA(), 
                          -Value.getConstant()); 
       break;
-    case AsmUnaryExpr::Not:
+    case MCUnaryExpr::Not:
       if (!Value.isAbsolute())
         return false;
       Res = MCValue::get(~Value.getConstant()); 
       break;
-    case AsmUnaryExpr::Plus:
+    case MCUnaryExpr::Plus:
       Res = Value;
       break;
     }
@@ -100,7 +100,7 @@
   }
 
   case Binary: {
-    const AsmBinaryExpr *ABE = cast<AsmBinaryExpr>(this);
+    const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
     MCValue LHSValue, RHSValue;
     
     if (!ABE->getLHS()->EvaluateAsRelocatable(Ctx, LHSValue) ||
@@ -113,14 +113,14 @@
       switch (ABE->getOpcode()) {
       default:
         return false;
-      case AsmBinaryExpr::Sub:
+      case MCBinaryExpr::Sub:
         // Negate RHS and add.
         return EvaluateSymbolicAdd(LHSValue,
                                    RHSValue.getSymB(), RHSValue.getSymA(),
                                    -RHSValue.getConstant(),
                                    Res);
 
-      case AsmBinaryExpr::Add:
+      case MCBinaryExpr::Add:
         return EvaluateSymbolicAdd(LHSValue,
                                    RHSValue.getSymA(), RHSValue.getSymB(),
                                    RHSValue.getConstant(),
@@ -134,24 +134,24 @@
     int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
     int64_t Result = 0;
     switch (ABE->getOpcode()) {
-    case AsmBinaryExpr::Add:  Result = LHS + RHS; break;
-    case AsmBinaryExpr::And:  Result = LHS & RHS; break;
-    case AsmBinaryExpr::Div:  Result = LHS / RHS; break;
-    case AsmBinaryExpr::EQ:   Result = LHS == RHS; break;
-    case AsmBinaryExpr::GT:   Result = LHS > RHS; break;
-    case AsmBinaryExpr::GTE:  Result = LHS >= RHS; break;
-    case AsmBinaryExpr::LAnd: Result = LHS && RHS; break;
-    case AsmBinaryExpr::LOr:  Result = LHS || RHS; break;
-    case AsmBinaryExpr::LT:   Result = LHS < RHS; break;
-    case AsmBinaryExpr::LTE:  Result = LHS <= RHS; break;
-    case AsmBinaryExpr::Mod:  Result = LHS % RHS; break;
-    case AsmBinaryExpr::Mul:  Result = LHS * RHS; break;
-    case AsmBinaryExpr::NE:   Result = LHS != RHS; break;
-    case AsmBinaryExpr::Or:   Result = LHS | RHS; break;
-    case AsmBinaryExpr::Shl:  Result = LHS << RHS; break;
-    case AsmBinaryExpr::Shr:  Result = LHS >> RHS; break;
-    case AsmBinaryExpr::Sub:  Result = LHS - RHS; break;
-    case AsmBinaryExpr::Xor:  Result = LHS ^ RHS; break;
+    case MCBinaryExpr::Add:  Result = LHS + RHS; break;
+    case MCBinaryExpr::And:  Result = LHS & RHS; break;
+    case MCBinaryExpr::Div:  Result = LHS / RHS; break;
+    case MCBinaryExpr::EQ:   Result = LHS == RHS; break;
+    case MCBinaryExpr::GT:   Result = LHS > RHS; break;
+    case MCBinaryExpr::GTE:  Result = LHS >= RHS; break;
+    case MCBinaryExpr::LAnd: Result = LHS && RHS; break;
+    case MCBinaryExpr::LOr:  Result = LHS || RHS; break;
+    case MCBinaryExpr::LT:   Result = LHS < RHS; break;
+    case MCBinaryExpr::LTE:  Result = LHS <= RHS; break;
+    case MCBinaryExpr::Mod:  Result = LHS % RHS; break;
+    case MCBinaryExpr::Mul:  Result = LHS * RHS; break;
+    case MCBinaryExpr::NE:   Result = LHS != RHS; break;
+    case MCBinaryExpr::Or:   Result = LHS | RHS; break;
+    case MCBinaryExpr::Shl:  Result = LHS << RHS; break;
+    case MCBinaryExpr::Shr:  Result = LHS >> RHS; break;
+    case MCBinaryExpr::Sub:  Result = LHS - RHS; break;
+    case MCBinaryExpr::Xor:  Result = LHS ^ RHS; break;
     }
 
     Res = MCValue::get(Result);

Removed: llvm/trunk/tools/llvm-mc/AsmExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmExpr.cpp?rev=80566&view=auto

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmExpr.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmExpr.cpp (removed)
@@ -1,162 +0,0 @@
-//===- AsmExpr.cpp - Assembly file expressions ----------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "AsmExpr.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCValue.h"
-using namespace llvm;
-
-AsmExpr::~AsmExpr() {
-}
-
-bool AsmExpr::EvaluateAsAbsolute(MCContext &Ctx, int64_t &Res) const {
-  MCValue Value;
-  
-  if (!EvaluateAsRelocatable(Ctx, Value) || !Value.isAbsolute())
-    return false;
-
-  Res = Value.getConstant();
-  return true;
-}
-
-static bool EvaluateSymbolicAdd(const MCValue &LHS, const MCSymbol *RHS_A, 
-                                const MCSymbol *RHS_B, int64_t RHS_Cst,
-                                MCValue &Res) {
-  // We can't add or subtract two symbols.
-  if ((LHS.getSymA() && RHS_A) ||
-      (LHS.getSymB() && RHS_B))
-    return false;
-
-  const MCSymbol *A = LHS.getSymA() ? LHS.getSymA() : RHS_A;
-  const MCSymbol *B = LHS.getSymB() ? LHS.getSymB() : RHS_B;
-  if (B) {
-    // If we have a negated symbol, then we must have also have a non-negated
-    // symbol in order to encode the expression. We can do this check later to
-    // permit expressions which eventually fold to a representable form -- such
-    // as (a + (0 - b)) -- if necessary.
-    if (!A)
-      return false;
-  }
-  Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst);
-  return true;
-}
-
-bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
-  switch (getKind()) {
-  default:
-    assert(0 && "Invalid assembly expression kind!");
-
-  case Constant:
-    Res = MCValue::get(cast<AsmConstantExpr>(this)->getValue());
-    return true;
-
-  case SymbolRef: {
-    MCSymbol *Sym = cast<AsmSymbolRefExpr>(this)->getSymbol();
-    if (const MCValue *Value = Ctx.GetSymbolValue(Sym))
-      Res = *Value;
-    else
-      Res = MCValue::get(Sym, 0, 0);
-    return true;
-  }
-
-  case Unary: {
-    const AsmUnaryExpr *AUE = cast<AsmUnaryExpr>(this);
-    MCValue Value;
-
-    if (!AUE->getSubExpr()->EvaluateAsRelocatable(Ctx, Value))
-      return false;
-
-    switch (AUE->getOpcode()) {
-    case AsmUnaryExpr::LNot:
-      if (!Value.isAbsolute())
-        return false;
-      Res = MCValue::get(!Value.getConstant());
-      break;
-    case AsmUnaryExpr::Minus:
-      /// -(a - b + const) ==> (b - a - const)
-      if (Value.getSymA() && !Value.getSymB())
-        return false;
-      Res = MCValue::get(Value.getSymB(), Value.getSymA(), 
-                         -Value.getConstant()); 
-      break;
-    case AsmUnaryExpr::Not:
-      if (!Value.isAbsolute())
-        return false;
-      Res = MCValue::get(~Value.getConstant()); 
-      break;
-    case AsmUnaryExpr::Plus:
-      Res = Value;
-      break;
-    }
-
-    return true;
-  }
-
-  case Binary: {
-    const AsmBinaryExpr *ABE = cast<AsmBinaryExpr>(this);
-    MCValue LHSValue, RHSValue;
-    
-    if (!ABE->getLHS()->EvaluateAsRelocatable(Ctx, LHSValue) ||
-        !ABE->getRHS()->EvaluateAsRelocatable(Ctx, RHSValue))
-      return false;
-
-    // We only support a few operations on non-constant expressions, handle
-    // those first.
-    if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) {
-      switch (ABE->getOpcode()) {
-      default:
-        return false;
-      case AsmBinaryExpr::Sub:
-        // Negate RHS and add.
-        return EvaluateSymbolicAdd(LHSValue,
-                                   RHSValue.getSymB(), RHSValue.getSymA(),
-                                   -RHSValue.getConstant(),
-                                   Res);
-
-      case AsmBinaryExpr::Add:
-        return EvaluateSymbolicAdd(LHSValue,
-                                   RHSValue.getSymA(), RHSValue.getSymB(),
-                                   RHSValue.getConstant(),
-                                   Res);
-      }
-    }
-
-    // FIXME: We need target hooks for the evaluation. It may be limited in
-    // width, and gas defines the result of comparisons differently from Apple
-    // as (the result is sign extended).
-    int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
-    int64_t Result = 0;
-    switch (ABE->getOpcode()) {
-    case AsmBinaryExpr::Add:  Result = LHS + RHS; break;
-    case AsmBinaryExpr::And:  Result = LHS & RHS; break;
-    case AsmBinaryExpr::Div:  Result = LHS / RHS; break;
-    case AsmBinaryExpr::EQ:   Result = LHS == RHS; break;
-    case AsmBinaryExpr::GT:   Result = LHS > RHS; break;
-    case AsmBinaryExpr::GTE:  Result = LHS >= RHS; break;
-    case AsmBinaryExpr::LAnd: Result = LHS && RHS; break;
-    case AsmBinaryExpr::LOr:  Result = LHS || RHS; break;
-    case AsmBinaryExpr::LT:   Result = LHS < RHS; break;
-    case AsmBinaryExpr::LTE:  Result = LHS <= RHS; break;
-    case AsmBinaryExpr::Mod:  Result = LHS % RHS; break;
-    case AsmBinaryExpr::Mul:  Result = LHS * RHS; break;
-    case AsmBinaryExpr::NE:   Result = LHS != RHS; break;
-    case AsmBinaryExpr::Or:   Result = LHS | RHS; break;
-    case AsmBinaryExpr::Shl:  Result = LHS << RHS; break;
-    case AsmBinaryExpr::Shr:  Result = LHS >> RHS; break;
-    case AsmBinaryExpr::Sub:  Result = LHS - RHS; break;
-    case AsmBinaryExpr::Xor:  Result = LHS ^ RHS; break;
-    }
-
-    Res = MCValue::get(Result);
-    return true;
-  }
-  }
-}
-

Removed: llvm/trunk/tools/llvm-mc/AsmExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmExpr.h?rev=80566&view=auto

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmExpr.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmExpr.h (removed)
@@ -1,179 +0,0 @@
-//===- AsmExpr.h - Assembly file expressions --------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef ASMEXPR_H
-#define ASMEXPR_H
-
-#include "llvm/Support/Casting.h"
-#include "llvm/Support/DataTypes.h"
-
-namespace llvm {
-class MCContext;
-class MCSymbol;
-class MCValue;
-
-/// AsmExpr - Base class for the full range of assembler expressions which are
-/// needed for parsing.  
-class AsmExpr {
-public:
-  enum AsmExprKind {
-    Binary,    ///< Binary expressions.
-    Constant,  ///< Constant expressions.
-    SymbolRef, ///< References to labels and assigned expressions.
-    Unary      ///< Unary expressions.
-  };
-  
-private:
-  AsmExprKind Kind;
-  
-protected:
-  AsmExpr(AsmExprKind _Kind) : Kind(_Kind) {}
-  
-public:
-  virtual ~AsmExpr();
-
-  AsmExprKind getKind() const { return Kind; }
-
-  /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
-  ///
-  /// @param Res - The absolute value, if evaluation succeeds.
-  /// @result - True on success.
-  bool EvaluateAsAbsolute(MCContext &Ctx, int64_t &Res) const;
-
-  /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
-  /// value, i.e. an expression of the fixed form (a - b + constant).
-  ///
-  /// @param Res - The relocatable value, if evaluation succeeds.
-  /// @result - True on success.
-  bool EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const;
-
-  static bool classof(const AsmExpr *) { return true; }
-};
-
-//// AsmConstantExpr - Represent a constant integer expression.
-class AsmConstantExpr : public AsmExpr {
-  int64_t Value;
-
-public:
-  AsmConstantExpr(int64_t _Value) 
-    : AsmExpr(AsmExpr::Constant), Value(_Value) {}
-  
-  int64_t getValue() const { return Value; }
-
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::Constant; 
-  }
-  static bool classof(const AsmConstantExpr *) { return true; }
-};
-
-/// AsmSymbolRefExpr - Represent a reference to a symbol from inside an
-/// expression.
-///
-/// A symbol reference in an expression may be a use of a label, a use of an
-/// assembler variable (defined constant), or constitute an implicit definition
-/// of the symbol as external.
-class AsmSymbolRefExpr : public AsmExpr {
-  MCSymbol *Symbol;
-
-public:
-  AsmSymbolRefExpr(MCSymbol *_Symbol) 
-    : AsmExpr(AsmExpr::SymbolRef), Symbol(_Symbol) {}
-  
-  MCSymbol *getSymbol() const { return Symbol; }
-
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::SymbolRef; 
-  }
-  static bool classof(const AsmSymbolRefExpr *) { return true; }
-};
-
-/// AsmUnaryExpr - Unary assembler expressions.
-class AsmUnaryExpr : public AsmExpr {
-public:
-  enum Opcode {
-    LNot,  ///< Logical negation.
-    Minus, ///< Unary minus.
-    Not,   ///< Bitwise negation.
-    Plus   ///< Unary plus.
-  };
-
-private:
-  Opcode Op;
-  AsmExpr *Expr;
-
-public:
-  AsmUnaryExpr(Opcode _Op, AsmExpr *_Expr)
-    : AsmExpr(AsmExpr::Unary), Op(_Op), Expr(_Expr) {}
-  ~AsmUnaryExpr() {
-    delete Expr;
-  }
-
-  Opcode getOpcode() const { return Op; }
-
-  AsmExpr *getSubExpr() const { return Expr; }
-
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::Unary; 
-  }
-  static bool classof(const AsmUnaryExpr *) { return true; }
-};
-
-/// AsmBinaryExpr - Binary assembler expressions.
-class AsmBinaryExpr : public AsmExpr {
-public:
-  enum Opcode {
-    Add,  ///< Addition.
-    And,  ///< Bitwise and.
-    Div,  ///< Division.
-    EQ,   ///< Equality comparison.
-    GT,   ///< Greater than comparison.
-    GTE,  ///< Greater than or equal comparison.
-    LAnd, ///< Logical and.
-    LOr,  ///< Logical or.
-    LT,   ///< Less than comparison.
-    LTE,  ///< Less than or equal comparison.
-    Mod,  ///< Modulus.
-    Mul,  ///< Multiplication.
-    NE,   ///< Inequality comparison.
-    Or,   ///< Bitwise or.
-    Shl,  ///< Bitwise shift left.
-    Shr,  ///< Bitwise shift right.
-    Sub,  ///< Subtraction.
-    Xor   ///< Bitwise exclusive or.
-  };
-
-private:
-  Opcode Op;
-  AsmExpr *LHS, *RHS;
-
-public:
-  AsmBinaryExpr(Opcode _Op, AsmExpr *_LHS, AsmExpr *_RHS)
-    : AsmExpr(AsmExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
-  ~AsmBinaryExpr() {
-    delete LHS;
-    delete RHS;
-  }
-
-  Opcode getOpcode() const { return Op; }
-
-  /// getLHS - Get the left-hand side expression of the binary operator.
-  AsmExpr *getLHS() const { return LHS; }
-
-  /// getRHS - Get the right-hand side expression of the binary operator.
-  AsmExpr *getRHS() const { return RHS; }
-
-  static bool classof(const AsmExpr *E) { 
-    return E->getKind() == AsmExpr::Binary; 
-  }
-  static bool classof(const AsmBinaryExpr *) { return true; }
-};
-
-} // end namespace llvm
-
-#endif

Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=80567&r1=80566&r2=80567&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Mon Aug 31 03:06:59 2009
@@ -13,10 +13,10 @@
 
 #include "AsmParser.h"
 
-#include "AsmExpr.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
@@ -173,7 +173,7 @@
 ///
 /// parenexpr ::= expr)
 ///
-bool AsmParser::ParseParenExpr(AsmExpr *&Res) {
+bool AsmParser::ParseParenExpr(MCExpr *&Res) {
   if (ParseExpression(Res)) return true;
   if (Lexer.isNot(AsmToken::RParen))
     return TokError("expected ')' in parentheses expression");
@@ -197,7 +197,7 @@
 ///  primaryexpr ::= symbol
 ///  primaryexpr ::= number
 ///  primaryexpr ::= ~,+,- primaryexpr
-bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
+bool AsmParser::ParsePrimaryExpr(MCExpr *&Res) {
   switch (Lexer.getKind()) {
   default:
     return TokError("unknown token in expression");
@@ -205,7 +205,7 @@
     Lexer.Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res))
       return true;
-    Res = new AsmUnaryExpr(AsmUnaryExpr::LNot, Res);
+    Res = new MCUnaryExpr(MCUnaryExpr::LNot, Res);
     return false;
   case AsmToken::String:
   case AsmToken::Identifier: {
@@ -213,12 +213,12 @@
     // handle things like LFOO+4.
     MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
     
-    Res = new AsmSymbolRefExpr(Sym);
+    Res = new MCSymbolRefExpr(Sym);
     Lexer.Lex(); // Eat identifier.
     return false;
   }
   case AsmToken::Integer:
-    Res = new AsmConstantExpr(Lexer.getTok().getIntVal());
+    Res = new MCConstantExpr(Lexer.getTok().getIntVal());
     Lexer.Lex(); // Eat token.
     return false;
   case AsmToken::LParen:
@@ -228,19 +228,19 @@
     Lexer.Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res))
       return true;
-    Res = new AsmUnaryExpr(AsmUnaryExpr::Minus, Res);
+    Res = new MCUnaryExpr(MCUnaryExpr::Minus, Res);
     return false;
   case AsmToken::Plus:
     Lexer.Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res))
       return true;
-    Res = new AsmUnaryExpr(AsmUnaryExpr::Plus, Res);
+    Res = new MCUnaryExpr(MCUnaryExpr::Plus, Res);
     return false;
   case AsmToken::Tilde:
     Lexer.Lex(); // Eat the operator.
     if (ParsePrimaryExpr(Res))
       return true;
-    Res = new AsmUnaryExpr(AsmUnaryExpr::Not, Res);
+    Res = new MCUnaryExpr(MCUnaryExpr::Not, Res);
     return false;
   }
 }
@@ -252,14 +252,14 @@
 ///  expr ::= expr *,/,%,<<,>> expr  -> highest.
 ///  expr ::= primaryexpr
 ///
-bool AsmParser::ParseExpression(AsmExpr *&Res) {
+bool AsmParser::ParseExpression(MCExpr *&Res) {
   Res = 0;
   return ParsePrimaryExpr(Res) ||
          ParseBinOpRHS(1, Res);
 }
 
 bool AsmParser::ParseAbsoluteExpression(int64_t &Res) {
-  AsmExpr *Expr;
+  MCExpr *Expr;
   
   SMLoc StartLoc = Lexer.getLoc();
   if (ParseExpression(Expr))
@@ -272,7 +272,7 @@
 }
 
 bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
-  AsmExpr *Expr;
+  MCExpr *Expr;
   
   SMLoc StartLoc = Lexer.getLoc();
   if (ParseExpression(Expr))
@@ -285,7 +285,7 @@
 }
 
 bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) {
-  AsmExpr *Expr;
+  MCExpr *Expr;
   
   SMLoc StartLoc = Lexer.getLoc();
   if (ParseParenExpr(Expr))
@@ -298,73 +298,73 @@
 }
 
 static unsigned getBinOpPrecedence(AsmToken::TokenKind K, 
-                                   AsmBinaryExpr::Opcode &Kind) {
+                                   MCBinaryExpr::Opcode &Kind) {
   switch (K) {
   default: return 0;    // not a binop.
 
     // Lowest Precedence: &&, ||
   case AsmToken::AmpAmp:
-    Kind = AsmBinaryExpr::LAnd;
+    Kind = MCBinaryExpr::LAnd;
     return 1;
   case AsmToken::PipePipe:
-    Kind = AsmBinaryExpr::LOr;
+    Kind = MCBinaryExpr::LOr;
     return 1;
 
     // Low Precedence: +, -, ==, !=, <>, <, <=, >, >=
   case AsmToken::Plus:
-    Kind = AsmBinaryExpr::Add;
+    Kind = MCBinaryExpr::Add;
     return 2;
   case AsmToken::Minus:
-    Kind = AsmBinaryExpr::Sub;
+    Kind = MCBinaryExpr::Sub;
     return 2;
   case AsmToken::EqualEqual:
-    Kind = AsmBinaryExpr::EQ;
+    Kind = MCBinaryExpr::EQ;
     return 2;
   case AsmToken::ExclaimEqual:
   case AsmToken::LessGreater:
-    Kind = AsmBinaryExpr::NE;
+    Kind = MCBinaryExpr::NE;
     return 2;
   case AsmToken::Less:
-    Kind = AsmBinaryExpr::LT;
+    Kind = MCBinaryExpr::LT;
     return 2;
   case AsmToken::LessEqual:
-    Kind = AsmBinaryExpr::LTE;
+    Kind = MCBinaryExpr::LTE;
     return 2;
   case AsmToken::Greater:
-    Kind = AsmBinaryExpr::GT;
+    Kind = MCBinaryExpr::GT;
     return 2;
   case AsmToken::GreaterEqual:
-    Kind = AsmBinaryExpr::GTE;
+    Kind = MCBinaryExpr::GTE;
     return 2;
 
     // Intermediate Precedence: |, &, ^
     //
     // FIXME: gas seems to support '!' as an infix operator?
   case AsmToken::Pipe:
-    Kind = AsmBinaryExpr::Or;
+    Kind = MCBinaryExpr::Or;
     return 3;
   case AsmToken::Caret:
-    Kind = AsmBinaryExpr::Xor;
+    Kind = MCBinaryExpr::Xor;
     return 3;
   case AsmToken::Amp:
-    Kind = AsmBinaryExpr::And;
+    Kind = MCBinaryExpr::And;
     return 3;
 
     // Highest Precedence: *, /, %, <<, >>
   case AsmToken::Star:
-    Kind = AsmBinaryExpr::Mul;
+    Kind = MCBinaryExpr::Mul;
     return 4;
   case AsmToken::Slash:
-    Kind = AsmBinaryExpr::Div;
+    Kind = MCBinaryExpr::Div;
     return 4;
   case AsmToken::Percent:
-    Kind = AsmBinaryExpr::Mod;
+    Kind = MCBinaryExpr::Mod;
     return 4;
   case AsmToken::LessLess:
-    Kind = AsmBinaryExpr::Shl;
+    Kind = MCBinaryExpr::Shl;
     return 4;
   case AsmToken::GreaterGreater:
-    Kind = AsmBinaryExpr::Shr;
+    Kind = MCBinaryExpr::Shr;
     return 4;
   }
 }
@@ -372,9 +372,9 @@
 
 /// ParseBinOpRHS - Parse all binary operators with precedence >= 'Precedence'.
 /// Res contains the LHS of the expression on input.
-bool AsmParser::ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res) {
+bool AsmParser::ParseBinOpRHS(unsigned Precedence, MCExpr *&Res) {
   while (1) {
-    AsmBinaryExpr::Opcode Kind = AsmBinaryExpr::Add;
+    MCBinaryExpr::Opcode Kind = MCBinaryExpr::Add;
     unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind);
     
     // If the next token is lower precedence than we are allowed to eat, return
@@ -385,19 +385,19 @@
     Lexer.Lex();
     
     // Eat the next primary expression.
-    AsmExpr *RHS;
+    MCExpr *RHS;
     if (ParsePrimaryExpr(RHS)) return true;
     
     // If BinOp binds less tightly with RHS than the operator after RHS, let
     // the pending operator take RHS as its LHS.
-    AsmBinaryExpr::Opcode Dummy;
+    MCBinaryExpr::Opcode Dummy;
     unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(), Dummy);
     if (TokPrec < NextTokPrec) {
       if (ParseBinOpRHS(Precedence+1, RHS)) return true;
     }
 
     // Merge LHS and RHS according to operator.
-    Res = new AsmBinaryExpr(Kind, Res, RHS);
+    Res = new MCBinaryExpr(Kind, Res, RHS);
   }
 }
 

Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=80567&r1=80566&r2=80567&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Mon Aug 31 03:06:59 2009
@@ -22,9 +22,9 @@
 #include "llvm/MC/MCStreamer.h"
 
 namespace llvm {
-class AsmExpr;
 class AsmCond;
 class MCContext;
+class MCExpr;
 class MCInst;
 class MCStreamer;
 class MCValue;
@@ -66,7 +66,7 @@
 
   virtual bool Error(SMLoc L, const Twine &Msg);
 
-  virtual bool ParseExpression(AsmExpr *&Res);
+  virtual bool ParseExpression(MCExpr *&Res);
 
   virtual bool ParseAbsoluteExpression(int64_t &Res);
 
@@ -104,9 +104,9 @@
   /// @see ParseRelocatableExpression, ParseParenExpr.
   bool ParseParenRelocatableExpression(MCValue &Res);
 
-  bool ParsePrimaryExpr(AsmExpr *&Res);
-  bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
-  bool ParseParenExpr(AsmExpr *&Res);
+  bool ParsePrimaryExpr(MCExpr *&Res);
+  bool ParseBinOpRHS(unsigned Precedence, MCExpr *&Res);
+  bool ParseParenExpr(MCExpr *&Res);
 
   /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
   /// and set \arg Res to the identifier contents.

Modified: llvm/trunk/tools/llvm-mc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/CMakeLists.txt?rev=80567&r1=80566&r2=80567&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-mc/CMakeLists.txt Mon Aug 31 03:06:59 2009
@@ -2,7 +2,6 @@
 
 add_llvm_tool(llvm-mc
   llvm-mc.cpp
-  AsmExpr.cpp
   AsmLexer.cpp
   AsmParser.cpp
   )





More information about the llvm-commits mailing list