Skip to content

Commit

Permalink
llvm-mc: Move AsmExpr into MC lib (as MCExpr).
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80567 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ddunbar committed Aug 31, 2009
1 parent be57765 commit 28c251b
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 122 deletions.
92 changes: 46 additions & 46 deletions tools/llvm-mc/AsmExpr.h → include/llvm/MC/MCExpr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- AsmExpr.h - Assembly file expressions --------------------*- C++ -*-===//
//===- MCExpr.h - Assembly Level Expressions --------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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"
Expand All @@ -18,27 +18,27 @@ class MCContext;
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.
Unary ///< Unary expressions.
};

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.
///
Expand All @@ -53,48 +53,48 @@ class AsmExpr {
/// @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.
Expand All @@ -105,27 +105,27 @@ class AsmUnaryExpr : public AsmExpr {

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.
Expand All @@ -150,28 +150,28 @@ class AsmBinaryExpr : public AsmExpr {

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;
}

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
Expand Down
1 change: 1 addition & 0 deletions lib/MC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_llvm_library(LLVMMC
MCAssembler.cpp
MCCodeEmitter.cpp
MCContext.cpp
MCExpr.cpp
MCInst.cpp
MCMachOStreamer.cpp
MCNullStreamer.cpp
Expand Down
66 changes: 33 additions & 33 deletions tools/llvm-mc/AsmExpr.cpp → lib/MC/MCExpr.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- AsmExpr.cpp - Assembly file expressions ----------------------------===//
//===- MCExpr.cpp - Assembly Level Expression Implementation --------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -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())
Expand Down Expand Up @@ -48,17 +48,17 @@ static bool EvaluateSymbolicAdd(const MCValue &LHS, const MCSymbol *RHS_A,
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
Expand All @@ -67,31 +67,31 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
}

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;
}
Expand All @@ -100,7 +100,7 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
}

case Binary: {
const AsmBinaryExpr *ABE = cast<AsmBinaryExpr>(this);
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
MCValue LHSValue, RHSValue;

if (!ABE->getLHS()->EvaluateAsRelocatable(Ctx, LHSValue) ||
Expand All @@ -113,14 +113,14 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
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(),
Expand All @@ -134,24 +134,24 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
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);
Expand Down
Loading

0 comments on commit 28c251b

Please sign in to comment.