mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-15 15:48:38 +00:00
llvm-mc: Move AsmExpr into MC lib (as MCExpr).
llvm-svn: 80567
This commit is contained in:
parent
acdb45e484
commit
b882c70ff2
@ -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 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.
|
||||
@ -30,15 +30,15 @@ public:
|
||||
};
|
||||
|
||||
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 @@ public:
|
||||
/// @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 @@ public:
|
||||
|
||||
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 @@ public:
|
||||
|
||||
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 @@ public:
|
||||
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
|
@ -8,6 +8,7 @@ add_llvm_library(LLVMMC
|
||||
MCAssembler.cpp
|
||||
MCCodeEmitter.cpp
|
||||
MCContext.cpp
|
||||
MCExpr.cpp
|
||||
MCInst.cpp
|
||||
MCMachOStreamer.cpp
|
||||
MCNullStreamer.cpp
|
||||
|
@ -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 @@ 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
|
||||
@ -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;
|
||||
}
|
||||
@ -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) ||
|
||||
@ -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(),
|
||||
@ -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);
|
@ -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 @@ void AsmParser::EatToEndOfStatement() {
|
||||
///
|
||||
/// 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 @@ MCSymbol *AsmParser::CreateSymbol(StringRef Name) {
|
||||
/// 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 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
||||
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 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
||||
// 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 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
||||
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 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
||||
/// 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::ParseAbsoluteExpression(int64_t &Res) {
|
||||
}
|
||||
|
||||
bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
|
||||
AsmExpr *Expr;
|
||||
MCExpr *Expr;
|
||||
|
||||
SMLoc StartLoc = Lexer.getLoc();
|
||||
if (ParseExpression(Expr))
|
||||
@ -285,7 +285,7 @@ bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
|
||||
}
|
||||
|
||||
bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) {
|
||||
AsmExpr *Expr;
|
||||
MCExpr *Expr;
|
||||
|
||||
SMLoc StartLoc = Lexer.getLoc();
|
||||
if (ParseParenExpr(Expr))
|
||||
@ -298,73 +298,73 @@ bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) {
|
||||
}
|
||||
|
||||
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 @@ static unsigned getBinOpPrecedence(AsmToken::TokenKind K,
|
||||
|
||||
/// 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 @@ bool AsmParser::ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 @@ public:
|
||||
|
||||
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 @@ private:
|
||||
/// @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.
|
||||
|
@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} support MC)
|
||||
|
||||
add_llvm_tool(llvm-mc
|
||||
llvm-mc.cpp
|
||||
AsmExpr.cpp
|
||||
AsmLexer.cpp
|
||||
AsmParser.cpp
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user