mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
llvm-mc: Move AsmExpr into MC lib (as MCExpr).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80567 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
be577659d3
commit
28c251b54b
@ -1,4 +1,4 @@
|
|||||||
//===- AsmExpr.h - Assembly file expressions --------------------*- C++ -*-===//
|
//===- MCExpr.h - Assembly Level Expressions --------------------*- C++ -*-===//
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
@ -7,8 +7,8 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef ASMEXPR_H
|
#ifndef LLVM_MC_MCEXPR_H
|
||||||
#define ASMEXPR_H
|
#define LLVM_MC_MCEXPR_H
|
||||||
|
|
||||||
#include "llvm/Support/Casting.h"
|
#include "llvm/Support/Casting.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
@ -18,11 +18,11 @@ class MCContext;
|
|||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
class MCValue;
|
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.
|
/// needed for parsing.
|
||||||
class AsmExpr {
|
class MCExpr {
|
||||||
public:
|
public:
|
||||||
enum AsmExprKind {
|
enum ExprKind {
|
||||||
Binary, ///< Binary expressions.
|
Binary, ///< Binary expressions.
|
||||||
Constant, ///< Constant expressions.
|
Constant, ///< Constant expressions.
|
||||||
SymbolRef, ///< References to labels and assigned expressions.
|
SymbolRef, ///< References to labels and assigned expressions.
|
||||||
@ -30,15 +30,15 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsmExprKind Kind;
|
ExprKind Kind;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AsmExpr(AsmExprKind _Kind) : Kind(_Kind) {}
|
MCExpr(ExprKind _Kind) : Kind(_Kind) {}
|
||||||
|
|
||||||
public:
|
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.
|
/// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
|
||||||
///
|
///
|
||||||
@ -53,48 +53,48 @@ public:
|
|||||||
/// @result - True on success.
|
/// @result - True on success.
|
||||||
bool EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const;
|
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.
|
//// MCConstantExpr - Represent a constant integer expression.
|
||||||
class AsmConstantExpr : public AsmExpr {
|
class MCConstantExpr : public MCExpr {
|
||||||
int64_t Value;
|
int64_t Value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsmConstantExpr(int64_t _Value)
|
MCConstantExpr(int64_t _Value)
|
||||||
: AsmExpr(AsmExpr::Constant), Value(_Value) {}
|
: MCExpr(MCExpr::Constant), Value(_Value) {}
|
||||||
|
|
||||||
int64_t getValue() const { return Value; }
|
int64_t getValue() const { return Value; }
|
||||||
|
|
||||||
static bool classof(const AsmExpr *E) {
|
static bool classof(const MCExpr *E) {
|
||||||
return E->getKind() == AsmExpr::Constant;
|
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.
|
/// expression.
|
||||||
///
|
///
|
||||||
/// A symbol reference in an expression may be a use of a label, a use of an
|
/// 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
|
/// assembler variable (defined constant), or constitute an implicit definition
|
||||||
/// of the symbol as external.
|
/// of the symbol as external.
|
||||||
class AsmSymbolRefExpr : public AsmExpr {
|
class MCSymbolRefExpr : public MCExpr {
|
||||||
MCSymbol *Symbol;
|
MCSymbol *Symbol;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsmSymbolRefExpr(MCSymbol *_Symbol)
|
MCSymbolRefExpr(MCSymbol *_Symbol)
|
||||||
: AsmExpr(AsmExpr::SymbolRef), Symbol(_Symbol) {}
|
: MCExpr(MCExpr::SymbolRef), Symbol(_Symbol) {}
|
||||||
|
|
||||||
MCSymbol *getSymbol() const { return Symbol; }
|
MCSymbol *getSymbol() const { return Symbol; }
|
||||||
|
|
||||||
static bool classof(const AsmExpr *E) {
|
static bool classof(const MCExpr *E) {
|
||||||
return E->getKind() == AsmExpr::SymbolRef;
|
return E->getKind() == MCExpr::SymbolRef;
|
||||||
}
|
}
|
||||||
static bool classof(const AsmSymbolRefExpr *) { return true; }
|
static bool classof(const MCSymbolRefExpr *) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// AsmUnaryExpr - Unary assembler expressions.
|
/// MCUnaryExpr - Unary assembler expressions.
|
||||||
class AsmUnaryExpr : public AsmExpr {
|
class MCUnaryExpr : public MCExpr {
|
||||||
public:
|
public:
|
||||||
enum Opcode {
|
enum Opcode {
|
||||||
LNot, ///< Logical negation.
|
LNot, ///< Logical negation.
|
||||||
@ -105,27 +105,27 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Opcode Op;
|
Opcode Op;
|
||||||
AsmExpr *Expr;
|
MCExpr *Expr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsmUnaryExpr(Opcode _Op, AsmExpr *_Expr)
|
MCUnaryExpr(Opcode _Op, MCExpr *_Expr)
|
||||||
: AsmExpr(AsmExpr::Unary), Op(_Op), Expr(_Expr) {}
|
: MCExpr(MCExpr::Unary), Op(_Op), Expr(_Expr) {}
|
||||||
~AsmUnaryExpr() {
|
~MCUnaryExpr() {
|
||||||
delete Expr;
|
delete Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Opcode getOpcode() const { return Op; }
|
Opcode getOpcode() const { return Op; }
|
||||||
|
|
||||||
AsmExpr *getSubExpr() const { return Expr; }
|
MCExpr *getSubExpr() const { return Expr; }
|
||||||
|
|
||||||
static bool classof(const AsmExpr *E) {
|
static bool classof(const MCExpr *E) {
|
||||||
return E->getKind() == AsmExpr::Unary;
|
return E->getKind() == MCExpr::Unary;
|
||||||
}
|
}
|
||||||
static bool classof(const AsmUnaryExpr *) { return true; }
|
static bool classof(const MCUnaryExpr *) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// AsmBinaryExpr - Binary assembler expressions.
|
/// MCBinaryExpr - Binary assembler expressions.
|
||||||
class AsmBinaryExpr : public AsmExpr {
|
class MCBinaryExpr : public MCExpr {
|
||||||
public:
|
public:
|
||||||
enum Opcode {
|
enum Opcode {
|
||||||
Add, ///< Addition.
|
Add, ///< Addition.
|
||||||
@ -150,12 +150,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Opcode Op;
|
Opcode Op;
|
||||||
AsmExpr *LHS, *RHS;
|
MCExpr *LHS, *RHS;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsmBinaryExpr(Opcode _Op, AsmExpr *_LHS, AsmExpr *_RHS)
|
MCBinaryExpr(Opcode _Op, MCExpr *_LHS, MCExpr *_RHS)
|
||||||
: AsmExpr(AsmExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
|
: MCExpr(MCExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
|
||||||
~AsmBinaryExpr() {
|
~MCBinaryExpr() {
|
||||||
delete LHS;
|
delete LHS;
|
||||||
delete RHS;
|
delete RHS;
|
||||||
}
|
}
|
||||||
@ -163,15 +163,15 @@ public:
|
|||||||
Opcode getOpcode() const { return Op; }
|
Opcode getOpcode() const { return Op; }
|
||||||
|
|
||||||
/// getLHS - Get the left-hand side expression of the binary operator.
|
/// 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.
|
/// 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) {
|
static bool classof(const MCExpr *E) {
|
||||||
return E->getKind() == AsmExpr::Binary;
|
return E->getKind() == MCExpr::Binary;
|
||||||
}
|
}
|
||||||
static bool classof(const AsmBinaryExpr *) { return true; }
|
static bool classof(const MCBinaryExpr *) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
@ -8,6 +8,7 @@ add_llvm_library(LLVMMC
|
|||||||
MCAssembler.cpp
|
MCAssembler.cpp
|
||||||
MCCodeEmitter.cpp
|
MCCodeEmitter.cpp
|
||||||
MCContext.cpp
|
MCContext.cpp
|
||||||
|
MCExpr.cpp
|
||||||
MCInst.cpp
|
MCInst.cpp
|
||||||
MCMachOStreamer.cpp
|
MCMachOStreamer.cpp
|
||||||
MCNullStreamer.cpp
|
MCNullStreamer.cpp
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//===- AsmExpr.cpp - Assembly file expressions ----------------------------===//
|
//===- MCExpr.cpp - Assembly Level Expression Implementation --------------===//
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
@ -7,16 +7,16 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "AsmExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCSymbol.h"
|
#include "llvm/MC/MCSymbol.h"
|
||||||
#include "llvm/MC/MCValue.h"
|
#include "llvm/MC/MCValue.h"
|
||||||
using namespace llvm;
|
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;
|
MCValue Value;
|
||||||
|
|
||||||
if (!EvaluateAsRelocatable(Ctx, Value) || !Value.isAbsolute())
|
if (!EvaluateAsRelocatable(Ctx, Value) || !Value.isAbsolute())
|
||||||
@ -48,17 +48,17 @@ static bool EvaluateSymbolicAdd(const MCValue &LHS, const MCSymbol *RHS_A,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
|
bool MCExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
|
||||||
switch (getKind()) {
|
switch (getKind()) {
|
||||||
default:
|
default:
|
||||||
assert(0 && "Invalid assembly expression kind!");
|
assert(0 && "Invalid assembly expression kind!");
|
||||||
|
|
||||||
case Constant:
|
case Constant:
|
||||||
Res = MCValue::get(cast<AsmConstantExpr>(this)->getValue());
|
Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case SymbolRef: {
|
case SymbolRef: {
|
||||||
MCSymbol *Sym = cast<AsmSymbolRefExpr>(this)->getSymbol();
|
MCSymbol *Sym = cast<MCSymbolRefExpr>(this)->getSymbol();
|
||||||
if (const MCValue *Value = Ctx.GetSymbolValue(Sym))
|
if (const MCValue *Value = Ctx.GetSymbolValue(Sym))
|
||||||
Res = *Value;
|
Res = *Value;
|
||||||
else
|
else
|
||||||
@ -67,31 +67,31 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Unary: {
|
case Unary: {
|
||||||
const AsmUnaryExpr *AUE = cast<AsmUnaryExpr>(this);
|
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
|
||||||
MCValue Value;
|
MCValue Value;
|
||||||
|
|
||||||
if (!AUE->getSubExpr()->EvaluateAsRelocatable(Ctx, Value))
|
if (!AUE->getSubExpr()->EvaluateAsRelocatable(Ctx, Value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (AUE->getOpcode()) {
|
switch (AUE->getOpcode()) {
|
||||||
case AsmUnaryExpr::LNot:
|
case MCUnaryExpr::LNot:
|
||||||
if (!Value.isAbsolute())
|
if (!Value.isAbsolute())
|
||||||
return false;
|
return false;
|
||||||
Res = MCValue::get(!Value.getConstant());
|
Res = MCValue::get(!Value.getConstant());
|
||||||
break;
|
break;
|
||||||
case AsmUnaryExpr::Minus:
|
case MCUnaryExpr::Minus:
|
||||||
/// -(a - b + const) ==> (b - a - const)
|
/// -(a - b + const) ==> (b - a - const)
|
||||||
if (Value.getSymA() && !Value.getSymB())
|
if (Value.getSymA() && !Value.getSymB())
|
||||||
return false;
|
return false;
|
||||||
Res = MCValue::get(Value.getSymB(), Value.getSymA(),
|
Res = MCValue::get(Value.getSymB(), Value.getSymA(),
|
||||||
-Value.getConstant());
|
-Value.getConstant());
|
||||||
break;
|
break;
|
||||||
case AsmUnaryExpr::Not:
|
case MCUnaryExpr::Not:
|
||||||
if (!Value.isAbsolute())
|
if (!Value.isAbsolute())
|
||||||
return false;
|
return false;
|
||||||
Res = MCValue::get(~Value.getConstant());
|
Res = MCValue::get(~Value.getConstant());
|
||||||
break;
|
break;
|
||||||
case AsmUnaryExpr::Plus:
|
case MCUnaryExpr::Plus:
|
||||||
Res = Value;
|
Res = Value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Binary: {
|
case Binary: {
|
||||||
const AsmBinaryExpr *ABE = cast<AsmBinaryExpr>(this);
|
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
|
||||||
MCValue LHSValue, RHSValue;
|
MCValue LHSValue, RHSValue;
|
||||||
|
|
||||||
if (!ABE->getLHS()->EvaluateAsRelocatable(Ctx, LHSValue) ||
|
if (!ABE->getLHS()->EvaluateAsRelocatable(Ctx, LHSValue) ||
|
||||||
@ -113,14 +113,14 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
|
|||||||
switch (ABE->getOpcode()) {
|
switch (ABE->getOpcode()) {
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
case AsmBinaryExpr::Sub:
|
case MCBinaryExpr::Sub:
|
||||||
// Negate RHS and add.
|
// Negate RHS and add.
|
||||||
return EvaluateSymbolicAdd(LHSValue,
|
return EvaluateSymbolicAdd(LHSValue,
|
||||||
RHSValue.getSymB(), RHSValue.getSymA(),
|
RHSValue.getSymB(), RHSValue.getSymA(),
|
||||||
-RHSValue.getConstant(),
|
-RHSValue.getConstant(),
|
||||||
Res);
|
Res);
|
||||||
|
|
||||||
case AsmBinaryExpr::Add:
|
case MCBinaryExpr::Add:
|
||||||
return EvaluateSymbolicAdd(LHSValue,
|
return EvaluateSymbolicAdd(LHSValue,
|
||||||
RHSValue.getSymA(), RHSValue.getSymB(),
|
RHSValue.getSymA(), RHSValue.getSymB(),
|
||||||
RHSValue.getConstant(),
|
RHSValue.getConstant(),
|
||||||
@ -134,24 +134,24 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const {
|
|||||||
int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
|
int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
|
||||||
int64_t Result = 0;
|
int64_t Result = 0;
|
||||||
switch (ABE->getOpcode()) {
|
switch (ABE->getOpcode()) {
|
||||||
case AsmBinaryExpr::Add: Result = LHS + RHS; break;
|
case MCBinaryExpr::Add: Result = LHS + RHS; break;
|
||||||
case AsmBinaryExpr::And: Result = LHS & RHS; break;
|
case MCBinaryExpr::And: Result = LHS & RHS; break;
|
||||||
case AsmBinaryExpr::Div: Result = LHS / RHS; break;
|
case MCBinaryExpr::Div: Result = LHS / RHS; break;
|
||||||
case AsmBinaryExpr::EQ: Result = LHS == RHS; break;
|
case MCBinaryExpr::EQ: Result = LHS == RHS; break;
|
||||||
case AsmBinaryExpr::GT: Result = LHS > RHS; break;
|
case MCBinaryExpr::GT: Result = LHS > RHS; break;
|
||||||
case AsmBinaryExpr::GTE: Result = LHS >= RHS; break;
|
case MCBinaryExpr::GTE: Result = LHS >= RHS; break;
|
||||||
case AsmBinaryExpr::LAnd: Result = LHS && RHS; break;
|
case MCBinaryExpr::LAnd: Result = LHS && RHS; break;
|
||||||
case AsmBinaryExpr::LOr: Result = LHS || RHS; break;
|
case MCBinaryExpr::LOr: Result = LHS || RHS; break;
|
||||||
case AsmBinaryExpr::LT: Result = LHS < RHS; break;
|
case MCBinaryExpr::LT: Result = LHS < RHS; break;
|
||||||
case AsmBinaryExpr::LTE: Result = LHS <= RHS; break;
|
case MCBinaryExpr::LTE: Result = LHS <= RHS; break;
|
||||||
case AsmBinaryExpr::Mod: Result = LHS % RHS; break;
|
case MCBinaryExpr::Mod: Result = LHS % RHS; break;
|
||||||
case AsmBinaryExpr::Mul: Result = LHS * RHS; break;
|
case MCBinaryExpr::Mul: Result = LHS * RHS; break;
|
||||||
case AsmBinaryExpr::NE: Result = LHS != RHS; break;
|
case MCBinaryExpr::NE: Result = LHS != RHS; break;
|
||||||
case AsmBinaryExpr::Or: Result = LHS | RHS; break;
|
case MCBinaryExpr::Or: Result = LHS | RHS; break;
|
||||||
case AsmBinaryExpr::Shl: Result = LHS << RHS; break;
|
case MCBinaryExpr::Shl: Result = LHS << RHS; break;
|
||||||
case AsmBinaryExpr::Shr: Result = LHS >> RHS; break;
|
case MCBinaryExpr::Shr: Result = LHS >> RHS; break;
|
||||||
case AsmBinaryExpr::Sub: Result = LHS - RHS; break;
|
case MCBinaryExpr::Sub: Result = LHS - RHS; break;
|
||||||
case AsmBinaryExpr::Xor: Result = LHS ^ RHS; break;
|
case MCBinaryExpr::Xor: Result = LHS ^ RHS; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Res = MCValue::get(Result);
|
Res = MCValue::get(Result);
|
@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
#include "AsmParser.h"
|
#include "AsmParser.h"
|
||||||
|
|
||||||
#include "AsmExpr.h"
|
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/Twine.h"
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
#include "llvm/MC/MCSectionMachO.h"
|
#include "llvm/MC/MCSectionMachO.h"
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
@ -173,7 +173,7 @@ void AsmParser::EatToEndOfStatement() {
|
|||||||
///
|
///
|
||||||
/// parenexpr ::= expr)
|
/// parenexpr ::= expr)
|
||||||
///
|
///
|
||||||
bool AsmParser::ParseParenExpr(AsmExpr *&Res) {
|
bool AsmParser::ParseParenExpr(MCExpr *&Res) {
|
||||||
if (ParseExpression(Res)) return true;
|
if (ParseExpression(Res)) return true;
|
||||||
if (Lexer.isNot(AsmToken::RParen))
|
if (Lexer.isNot(AsmToken::RParen))
|
||||||
return TokError("expected ')' in parentheses expression");
|
return TokError("expected ')' in parentheses expression");
|
||||||
@ -197,7 +197,7 @@ MCSymbol *AsmParser::CreateSymbol(StringRef Name) {
|
|||||||
/// primaryexpr ::= symbol
|
/// primaryexpr ::= symbol
|
||||||
/// primaryexpr ::= number
|
/// primaryexpr ::= number
|
||||||
/// primaryexpr ::= ~,+,- primaryexpr
|
/// primaryexpr ::= ~,+,- primaryexpr
|
||||||
bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
bool AsmParser::ParsePrimaryExpr(MCExpr *&Res) {
|
||||||
switch (Lexer.getKind()) {
|
switch (Lexer.getKind()) {
|
||||||
default:
|
default:
|
||||||
return TokError("unknown token in expression");
|
return TokError("unknown token in expression");
|
||||||
@ -205,7 +205,7 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
|||||||
Lexer.Lex(); // Eat the operator.
|
Lexer.Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res))
|
if (ParsePrimaryExpr(Res))
|
||||||
return true;
|
return true;
|
||||||
Res = new AsmUnaryExpr(AsmUnaryExpr::LNot, Res);
|
Res = new MCUnaryExpr(MCUnaryExpr::LNot, Res);
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::String:
|
case AsmToken::String:
|
||||||
case AsmToken::Identifier: {
|
case AsmToken::Identifier: {
|
||||||
@ -213,12 +213,12 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
|||||||
// handle things like LFOO+4.
|
// handle things like LFOO+4.
|
||||||
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
|
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
|
||||||
|
|
||||||
Res = new AsmSymbolRefExpr(Sym);
|
Res = new MCSymbolRefExpr(Sym);
|
||||||
Lexer.Lex(); // Eat identifier.
|
Lexer.Lex(); // Eat identifier.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case AsmToken::Integer:
|
case AsmToken::Integer:
|
||||||
Res = new AsmConstantExpr(Lexer.getTok().getIntVal());
|
Res = new MCConstantExpr(Lexer.getTok().getIntVal());
|
||||||
Lexer.Lex(); // Eat token.
|
Lexer.Lex(); // Eat token.
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::LParen:
|
case AsmToken::LParen:
|
||||||
@ -228,19 +228,19 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
|||||||
Lexer.Lex(); // Eat the operator.
|
Lexer.Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res))
|
if (ParsePrimaryExpr(Res))
|
||||||
return true;
|
return true;
|
||||||
Res = new AsmUnaryExpr(AsmUnaryExpr::Minus, Res);
|
Res = new MCUnaryExpr(MCUnaryExpr::Minus, Res);
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::Plus:
|
case AsmToken::Plus:
|
||||||
Lexer.Lex(); // Eat the operator.
|
Lexer.Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res))
|
if (ParsePrimaryExpr(Res))
|
||||||
return true;
|
return true;
|
||||||
Res = new AsmUnaryExpr(AsmUnaryExpr::Plus, Res);
|
Res = new MCUnaryExpr(MCUnaryExpr::Plus, Res);
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::Tilde:
|
case AsmToken::Tilde:
|
||||||
Lexer.Lex(); // Eat the operator.
|
Lexer.Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res))
|
if (ParsePrimaryExpr(Res))
|
||||||
return true;
|
return true;
|
||||||
Res = new AsmUnaryExpr(AsmUnaryExpr::Not, Res);
|
Res = new MCUnaryExpr(MCUnaryExpr::Not, Res);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,14 +252,14 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
|||||||
/// expr ::= expr *,/,%,<<,>> expr -> highest.
|
/// expr ::= expr *,/,%,<<,>> expr -> highest.
|
||||||
/// expr ::= primaryexpr
|
/// expr ::= primaryexpr
|
||||||
///
|
///
|
||||||
bool AsmParser::ParseExpression(AsmExpr *&Res) {
|
bool AsmParser::ParseExpression(MCExpr *&Res) {
|
||||||
Res = 0;
|
Res = 0;
|
||||||
return ParsePrimaryExpr(Res) ||
|
return ParsePrimaryExpr(Res) ||
|
||||||
ParseBinOpRHS(1, Res);
|
ParseBinOpRHS(1, Res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmParser::ParseAbsoluteExpression(int64_t &Res) {
|
bool AsmParser::ParseAbsoluteExpression(int64_t &Res) {
|
||||||
AsmExpr *Expr;
|
MCExpr *Expr;
|
||||||
|
|
||||||
SMLoc StartLoc = Lexer.getLoc();
|
SMLoc StartLoc = Lexer.getLoc();
|
||||||
if (ParseExpression(Expr))
|
if (ParseExpression(Expr))
|
||||||
@ -272,7 +272,7 @@ bool AsmParser::ParseAbsoluteExpression(int64_t &Res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
|
bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
|
||||||
AsmExpr *Expr;
|
MCExpr *Expr;
|
||||||
|
|
||||||
SMLoc StartLoc = Lexer.getLoc();
|
SMLoc StartLoc = Lexer.getLoc();
|
||||||
if (ParseExpression(Expr))
|
if (ParseExpression(Expr))
|
||||||
@ -285,7 +285,7 @@ bool AsmParser::ParseRelocatableExpression(MCValue &Res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) {
|
bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) {
|
||||||
AsmExpr *Expr;
|
MCExpr *Expr;
|
||||||
|
|
||||||
SMLoc StartLoc = Lexer.getLoc();
|
SMLoc StartLoc = Lexer.getLoc();
|
||||||
if (ParseParenExpr(Expr))
|
if (ParseParenExpr(Expr))
|
||||||
@ -298,73 +298,73 @@ bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned getBinOpPrecedence(AsmToken::TokenKind K,
|
static unsigned getBinOpPrecedence(AsmToken::TokenKind K,
|
||||||
AsmBinaryExpr::Opcode &Kind) {
|
MCBinaryExpr::Opcode &Kind) {
|
||||||
switch (K) {
|
switch (K) {
|
||||||
default: return 0; // not a binop.
|
default: return 0; // not a binop.
|
||||||
|
|
||||||
// Lowest Precedence: &&, ||
|
// Lowest Precedence: &&, ||
|
||||||
case AsmToken::AmpAmp:
|
case AsmToken::AmpAmp:
|
||||||
Kind = AsmBinaryExpr::LAnd;
|
Kind = MCBinaryExpr::LAnd;
|
||||||
return 1;
|
return 1;
|
||||||
case AsmToken::PipePipe:
|
case AsmToken::PipePipe:
|
||||||
Kind = AsmBinaryExpr::LOr;
|
Kind = MCBinaryExpr::LOr;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Low Precedence: +, -, ==, !=, <>, <, <=, >, >=
|
// Low Precedence: +, -, ==, !=, <>, <, <=, >, >=
|
||||||
case AsmToken::Plus:
|
case AsmToken::Plus:
|
||||||
Kind = AsmBinaryExpr::Add;
|
Kind = MCBinaryExpr::Add;
|
||||||
return 2;
|
return 2;
|
||||||
case AsmToken::Minus:
|
case AsmToken::Minus:
|
||||||
Kind = AsmBinaryExpr::Sub;
|
Kind = MCBinaryExpr::Sub;
|
||||||
return 2;
|
return 2;
|
||||||
case AsmToken::EqualEqual:
|
case AsmToken::EqualEqual:
|
||||||
Kind = AsmBinaryExpr::EQ;
|
Kind = MCBinaryExpr::EQ;
|
||||||
return 2;
|
return 2;
|
||||||
case AsmToken::ExclaimEqual:
|
case AsmToken::ExclaimEqual:
|
||||||
case AsmToken::LessGreater:
|
case AsmToken::LessGreater:
|
||||||
Kind = AsmBinaryExpr::NE;
|
Kind = MCBinaryExpr::NE;
|
||||||
return 2;
|
return 2;
|
||||||
case AsmToken::Less:
|
case AsmToken::Less:
|
||||||
Kind = AsmBinaryExpr::LT;
|
Kind = MCBinaryExpr::LT;
|
||||||
return 2;
|
return 2;
|
||||||
case AsmToken::LessEqual:
|
case AsmToken::LessEqual:
|
||||||
Kind = AsmBinaryExpr::LTE;
|
Kind = MCBinaryExpr::LTE;
|
||||||
return 2;
|
return 2;
|
||||||
case AsmToken::Greater:
|
case AsmToken::Greater:
|
||||||
Kind = AsmBinaryExpr::GT;
|
Kind = MCBinaryExpr::GT;
|
||||||
return 2;
|
return 2;
|
||||||
case AsmToken::GreaterEqual:
|
case AsmToken::GreaterEqual:
|
||||||
Kind = AsmBinaryExpr::GTE;
|
Kind = MCBinaryExpr::GTE;
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
// Intermediate Precedence: |, &, ^
|
// Intermediate Precedence: |, &, ^
|
||||||
//
|
//
|
||||||
// FIXME: gas seems to support '!' as an infix operator?
|
// FIXME: gas seems to support '!' as an infix operator?
|
||||||
case AsmToken::Pipe:
|
case AsmToken::Pipe:
|
||||||
Kind = AsmBinaryExpr::Or;
|
Kind = MCBinaryExpr::Or;
|
||||||
return 3;
|
return 3;
|
||||||
case AsmToken::Caret:
|
case AsmToken::Caret:
|
||||||
Kind = AsmBinaryExpr::Xor;
|
Kind = MCBinaryExpr::Xor;
|
||||||
return 3;
|
return 3;
|
||||||
case AsmToken::Amp:
|
case AsmToken::Amp:
|
||||||
Kind = AsmBinaryExpr::And;
|
Kind = MCBinaryExpr::And;
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
// Highest Precedence: *, /, %, <<, >>
|
// Highest Precedence: *, /, %, <<, >>
|
||||||
case AsmToken::Star:
|
case AsmToken::Star:
|
||||||
Kind = AsmBinaryExpr::Mul;
|
Kind = MCBinaryExpr::Mul;
|
||||||
return 4;
|
return 4;
|
||||||
case AsmToken::Slash:
|
case AsmToken::Slash:
|
||||||
Kind = AsmBinaryExpr::Div;
|
Kind = MCBinaryExpr::Div;
|
||||||
return 4;
|
return 4;
|
||||||
case AsmToken::Percent:
|
case AsmToken::Percent:
|
||||||
Kind = AsmBinaryExpr::Mod;
|
Kind = MCBinaryExpr::Mod;
|
||||||
return 4;
|
return 4;
|
||||||
case AsmToken::LessLess:
|
case AsmToken::LessLess:
|
||||||
Kind = AsmBinaryExpr::Shl;
|
Kind = MCBinaryExpr::Shl;
|
||||||
return 4;
|
return 4;
|
||||||
case AsmToken::GreaterGreater:
|
case AsmToken::GreaterGreater:
|
||||||
Kind = AsmBinaryExpr::Shr;
|
Kind = MCBinaryExpr::Shr;
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,9 +372,9 @@ static unsigned getBinOpPrecedence(AsmToken::TokenKind K,
|
|||||||
|
|
||||||
/// ParseBinOpRHS - Parse all binary operators with precedence >= 'Precedence'.
|
/// ParseBinOpRHS - Parse all binary operators with precedence >= 'Precedence'.
|
||||||
/// Res contains the LHS of the expression on input.
|
/// 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) {
|
while (1) {
|
||||||
AsmBinaryExpr::Opcode Kind = AsmBinaryExpr::Add;
|
MCBinaryExpr::Opcode Kind = MCBinaryExpr::Add;
|
||||||
unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind);
|
unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind);
|
||||||
|
|
||||||
// If the next token is lower precedence than we are allowed to eat, return
|
// 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();
|
Lexer.Lex();
|
||||||
|
|
||||||
// Eat the next primary expression.
|
// Eat the next primary expression.
|
||||||
AsmExpr *RHS;
|
MCExpr *RHS;
|
||||||
if (ParsePrimaryExpr(RHS)) return true;
|
if (ParsePrimaryExpr(RHS)) return true;
|
||||||
|
|
||||||
// If BinOp binds less tightly with RHS than the operator after RHS, let
|
// If BinOp binds less tightly with RHS than the operator after RHS, let
|
||||||
// the pending operator take RHS as its LHS.
|
// the pending operator take RHS as its LHS.
|
||||||
AsmBinaryExpr::Opcode Dummy;
|
MCBinaryExpr::Opcode Dummy;
|
||||||
unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(), Dummy);
|
unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(), Dummy);
|
||||||
if (TokPrec < NextTokPrec) {
|
if (TokPrec < NextTokPrec) {
|
||||||
if (ParseBinOpRHS(Precedence+1, RHS)) return true;
|
if (ParseBinOpRHS(Precedence+1, RHS)) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge LHS and RHS according to operator.
|
// 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"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class AsmExpr;
|
|
||||||
class AsmCond;
|
class AsmCond;
|
||||||
class MCContext;
|
class MCContext;
|
||||||
|
class MCExpr;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
class MCStreamer;
|
class MCStreamer;
|
||||||
class MCValue;
|
class MCValue;
|
||||||
@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
virtual bool Error(SMLoc L, const Twine &Msg);
|
virtual bool Error(SMLoc L, const Twine &Msg);
|
||||||
|
|
||||||
virtual bool ParseExpression(AsmExpr *&Res);
|
virtual bool ParseExpression(MCExpr *&Res);
|
||||||
|
|
||||||
virtual bool ParseAbsoluteExpression(int64_t &Res);
|
virtual bool ParseAbsoluteExpression(int64_t &Res);
|
||||||
|
|
||||||
@ -104,9 +104,9 @@ private:
|
|||||||
/// @see ParseRelocatableExpression, ParseParenExpr.
|
/// @see ParseRelocatableExpression, ParseParenExpr.
|
||||||
bool ParseParenRelocatableExpression(MCValue &Res);
|
bool ParseParenRelocatableExpression(MCValue &Res);
|
||||||
|
|
||||||
bool ParsePrimaryExpr(AsmExpr *&Res);
|
bool ParsePrimaryExpr(MCExpr *&Res);
|
||||||
bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
|
bool ParseBinOpRHS(unsigned Precedence, MCExpr *&Res);
|
||||||
bool ParseParenExpr(AsmExpr *&Res);
|
bool ParseParenExpr(MCExpr *&Res);
|
||||||
|
|
||||||
/// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
|
/// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
|
||||||
/// and set \arg Res to the identifier contents.
|
/// 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
|
add_llvm_tool(llvm-mc
|
||||||
llvm-mc.cpp
|
llvm-mc.cpp
|
||||||
AsmExpr.cpp
|
|
||||||
AsmLexer.cpp
|
AsmLexer.cpp
|
||||||
AsmParser.cpp
|
AsmParser.cpp
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user