2013-05-07 00:15:19 +08:00
|
|
|
//===-- SystemZAsmParser.cpp - Parse SystemZ assembly instructions --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MCTargetDesc/SystemZMCTargetDesc.h"
|
2013-07-24 15:33:14 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-05-14 17:47:26 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2013-05-07 00:15:19 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/MC/MCTargetAsmParser.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Return true if Expr is in the range [MinValue, MaxValue].
|
|
|
|
static bool inRange(const MCExpr *Expr, int64_t MinValue, int64_t MaxValue) {
|
2014-03-06 19:22:58 +08:00
|
|
|
if (auto *CE = dyn_cast<MCConstantExpr>(Expr)) {
|
2013-05-07 00:15:19 +08:00
|
|
|
int64_t Value = CE->getValue();
|
|
|
|
return Value >= MinValue && Value <= MaxValue;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2013-07-02 22:56:45 +08:00
|
|
|
enum RegisterKind {
|
|
|
|
GR32Reg,
|
2013-09-30 18:45:16 +08:00
|
|
|
GRH32Reg,
|
2013-07-02 22:56:45 +08:00
|
|
|
GR64Reg,
|
|
|
|
GR128Reg,
|
|
|
|
ADDR32Reg,
|
|
|
|
ADDR64Reg,
|
|
|
|
FP32Reg,
|
|
|
|
FP64Reg,
|
2015-05-06 03:23:40 +08:00
|
|
|
FP128Reg,
|
|
|
|
VR32Reg,
|
|
|
|
VR64Reg,
|
|
|
|
VR128Reg
|
2013-07-02 22:56:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum MemoryKind {
|
|
|
|
BDMem,
|
|
|
|
BDXMem,
|
2015-05-06 03:23:40 +08:00
|
|
|
BDLMem,
|
|
|
|
BDVMem
|
2013-07-02 22:56:45 +08:00
|
|
|
};
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
class SystemZOperand : public MCParsedAsmOperand {
|
|
|
|
public:
|
|
|
|
private:
|
|
|
|
enum OperandKind {
|
2013-05-24 22:26:46 +08:00
|
|
|
KindInvalid,
|
2013-05-07 00:15:19 +08:00
|
|
|
KindToken,
|
|
|
|
KindReg,
|
|
|
|
KindAccessReg,
|
|
|
|
KindImm,
|
2015-02-18 17:11:36 +08:00
|
|
|
KindImmTLS,
|
2013-05-07 00:15:19 +08:00
|
|
|
KindMem
|
|
|
|
};
|
|
|
|
|
|
|
|
OperandKind Kind;
|
|
|
|
SMLoc StartLoc, EndLoc;
|
|
|
|
|
|
|
|
// A string of length Length, starting at Data.
|
|
|
|
struct TokenOp {
|
|
|
|
const char *Data;
|
|
|
|
unsigned Length;
|
|
|
|
};
|
|
|
|
|
2013-05-24 22:14:38 +08:00
|
|
|
// LLVM register Num, which has kind Kind. In some ways it might be
|
|
|
|
// easier for this class to have a register bank (general, floating-point
|
|
|
|
// or access) and a raw register number (0-15). This would postpone the
|
|
|
|
// interpretation of the operand to the add*() methods and avoid the need
|
|
|
|
// for context-dependent parsing. However, we do things the current way
|
|
|
|
// because of the virtual getReg() method, which needs to distinguish
|
|
|
|
// between (say) %r0 used as a single register and %r0 used as a pair.
|
|
|
|
// Context-dependent parsing can also give us slightly better error
|
|
|
|
// messages when invalid pairs like %r1 are used.
|
2013-05-07 00:15:19 +08:00
|
|
|
struct RegOp {
|
|
|
|
RegisterKind Kind;
|
|
|
|
unsigned Num;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Base + Disp + Index, where Base and Index are LLVM registers or 0.
|
2015-05-05 01:40:53 +08:00
|
|
|
// MemKind says what type of memory this is and RegKind says what type
|
|
|
|
// the base register has (ADDR32Reg or ADDR64Reg). Length is the operand
|
|
|
|
// length for D(L,B)-style operands, otherwise it is null.
|
2013-05-07 00:15:19 +08:00
|
|
|
struct MemOp {
|
2015-05-06 03:23:40 +08:00
|
|
|
unsigned Base : 12;
|
|
|
|
unsigned Index : 12;
|
|
|
|
unsigned MemKind : 4;
|
|
|
|
unsigned RegKind : 4;
|
2013-05-07 00:15:19 +08:00
|
|
|
const MCExpr *Disp;
|
2013-07-02 22:56:45 +08:00
|
|
|
const MCExpr *Length;
|
2013-05-07 00:15:19 +08:00
|
|
|
};
|
|
|
|
|
2015-02-18 17:11:36 +08:00
|
|
|
// Imm is an immediate operand, and Sym is an optional TLS symbol
|
|
|
|
// for use with a __tls_get_offset marker relocation.
|
|
|
|
struct ImmTLSOp {
|
|
|
|
const MCExpr *Imm;
|
|
|
|
const MCExpr *Sym;
|
|
|
|
};
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
union {
|
|
|
|
TokenOp Token;
|
|
|
|
RegOp Reg;
|
|
|
|
unsigned AccessReg;
|
|
|
|
const MCExpr *Imm;
|
2015-02-18 17:11:36 +08:00
|
|
|
ImmTLSOp ImmTLS;
|
2013-05-07 00:15:19 +08:00
|
|
|
MemOp Mem;
|
|
|
|
};
|
|
|
|
|
|
|
|
void addExpr(MCInst &Inst, const MCExpr *Expr) const {
|
|
|
|
// Add as immediates when possible. Null MCExpr = 0.
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!Expr)
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(0));
|
2014-03-06 19:22:58 +08:00
|
|
|
else if (auto *CE = dyn_cast<MCConstantExpr>(Expr))
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(CE->getValue()));
|
2013-05-07 00:15:19 +08:00
|
|
|
else
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createExpr(Expr));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-06-09 00:18:35 +08:00
|
|
|
SystemZOperand(OperandKind kind, SMLoc startLoc, SMLoc endLoc)
|
|
|
|
: Kind(kind), StartLoc(startLoc), EndLoc(endLoc) {}
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
// Create particular kinds of operand.
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<SystemZOperand> createInvalid(SMLoc StartLoc,
|
|
|
|
SMLoc EndLoc) {
|
|
|
|
return make_unique<SystemZOperand>(KindInvalid, StartLoc, EndLoc);
|
2013-05-24 22:26:46 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<SystemZOperand> createToken(StringRef Str, SMLoc Loc) {
|
|
|
|
auto Op = make_unique<SystemZOperand>(KindToken, Loc, Loc);
|
2013-05-07 00:15:19 +08:00
|
|
|
Op->Token.Data = Str.data();
|
|
|
|
Op->Token.Length = Str.size();
|
|
|
|
return Op;
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<SystemZOperand>
|
|
|
|
createReg(RegisterKind Kind, unsigned Num, SMLoc StartLoc, SMLoc EndLoc) {
|
|
|
|
auto Op = make_unique<SystemZOperand>(KindReg, StartLoc, EndLoc);
|
2013-05-07 00:15:19 +08:00
|
|
|
Op->Reg.Kind = Kind;
|
|
|
|
Op->Reg.Num = Num;
|
|
|
|
return Op;
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<SystemZOperand>
|
|
|
|
createAccessReg(unsigned Num, SMLoc StartLoc, SMLoc EndLoc) {
|
|
|
|
auto Op = make_unique<SystemZOperand>(KindAccessReg, StartLoc, EndLoc);
|
2013-05-07 00:15:19 +08:00
|
|
|
Op->AccessReg = Num;
|
|
|
|
return Op;
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<SystemZOperand>
|
|
|
|
createImm(const MCExpr *Expr, SMLoc StartLoc, SMLoc EndLoc) {
|
|
|
|
auto Op = make_unique<SystemZOperand>(KindImm, StartLoc, EndLoc);
|
2013-05-07 00:15:19 +08:00
|
|
|
Op->Imm = Expr;
|
|
|
|
return Op;
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
static std::unique_ptr<SystemZOperand>
|
2015-05-05 01:40:53 +08:00
|
|
|
createMem(MemoryKind MemKind, RegisterKind RegKind, unsigned Base,
|
|
|
|
const MCExpr *Disp, unsigned Index, const MCExpr *Length,
|
|
|
|
SMLoc StartLoc, SMLoc EndLoc) {
|
2014-06-09 00:18:35 +08:00
|
|
|
auto Op = make_unique<SystemZOperand>(KindMem, StartLoc, EndLoc);
|
2015-05-05 01:40:53 +08:00
|
|
|
Op->Mem.MemKind = MemKind;
|
2013-05-07 00:15:19 +08:00
|
|
|
Op->Mem.RegKind = RegKind;
|
|
|
|
Op->Mem.Base = Base;
|
|
|
|
Op->Mem.Index = Index;
|
|
|
|
Op->Mem.Disp = Disp;
|
2013-07-02 22:56:45 +08:00
|
|
|
Op->Mem.Length = Length;
|
2013-05-07 00:15:19 +08:00
|
|
|
return Op;
|
|
|
|
}
|
2015-02-18 17:11:36 +08:00
|
|
|
static std::unique_ptr<SystemZOperand>
|
|
|
|
createImmTLS(const MCExpr *Imm, const MCExpr *Sym,
|
|
|
|
SMLoc StartLoc, SMLoc EndLoc) {
|
|
|
|
auto Op = make_unique<SystemZOperand>(KindImmTLS, StartLoc, EndLoc);
|
|
|
|
Op->ImmTLS.Imm = Imm;
|
|
|
|
Op->ImmTLS.Sym = Sym;
|
|
|
|
return Op;
|
|
|
|
}
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Token operands
|
2014-03-06 20:03:36 +08:00
|
|
|
bool isToken() const override {
|
2013-05-07 00:15:19 +08:00
|
|
|
return Kind == KindToken;
|
|
|
|
}
|
|
|
|
StringRef getToken() const {
|
|
|
|
assert(Kind == KindToken && "Not a token");
|
|
|
|
return StringRef(Token.Data, Token.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register operands.
|
2014-03-06 20:03:36 +08:00
|
|
|
bool isReg() const override {
|
2013-05-07 00:15:19 +08:00
|
|
|
return Kind == KindReg;
|
|
|
|
}
|
|
|
|
bool isReg(RegisterKind RegKind) const {
|
|
|
|
return Kind == KindReg && Reg.Kind == RegKind;
|
|
|
|
}
|
2014-03-06 20:03:36 +08:00
|
|
|
unsigned getReg() const override {
|
2013-05-07 00:15:19 +08:00
|
|
|
assert(Kind == KindReg && "Not a register");
|
|
|
|
return Reg.Num;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Access register operands. Access registers aren't exposed to LLVM
|
|
|
|
// as registers.
|
|
|
|
bool isAccessReg() const {
|
|
|
|
return Kind == KindAccessReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Immediate operands.
|
2014-03-06 20:03:36 +08:00
|
|
|
bool isImm() const override {
|
2013-05-07 00:15:19 +08:00
|
|
|
return Kind == KindImm;
|
|
|
|
}
|
|
|
|
bool isImm(int64_t MinValue, int64_t MaxValue) const {
|
|
|
|
return Kind == KindImm && inRange(Imm, MinValue, MaxValue);
|
|
|
|
}
|
|
|
|
const MCExpr *getImm() const {
|
|
|
|
assert(Kind == KindImm && "Not an immediate");
|
|
|
|
return Imm;
|
|
|
|
}
|
|
|
|
|
2015-02-18 17:11:36 +08:00
|
|
|
// Immediate operands with optional TLS symbol.
|
|
|
|
bool isImmTLS() const {
|
|
|
|
return Kind == KindImmTLS;
|
|
|
|
}
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
// Memory operands.
|
2014-03-06 20:03:36 +08:00
|
|
|
bool isMem() const override {
|
2013-05-07 00:15:19 +08:00
|
|
|
return Kind == KindMem;
|
|
|
|
}
|
2015-05-05 01:40:53 +08:00
|
|
|
bool isMem(MemoryKind MemKind) const {
|
2013-05-07 00:15:19 +08:00
|
|
|
return (Kind == KindMem &&
|
2015-05-05 01:40:53 +08:00
|
|
|
(Mem.MemKind == MemKind ||
|
|
|
|
// A BDMem can be treated as a BDXMem in which the index
|
|
|
|
// register field is 0.
|
|
|
|
(Mem.MemKind == BDMem && MemKind == BDXMem)));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2015-05-05 01:40:53 +08:00
|
|
|
bool isMem(MemoryKind MemKind, RegisterKind RegKind) const {
|
|
|
|
return isMem(MemKind) && Mem.RegKind == RegKind;
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2015-05-05 01:40:53 +08:00
|
|
|
bool isMemDisp12(MemoryKind MemKind, RegisterKind RegKind) const {
|
|
|
|
return isMem(MemKind, RegKind) && inRange(Mem.Disp, 0, 0xfff);
|
|
|
|
}
|
|
|
|
bool isMemDisp20(MemoryKind MemKind, RegisterKind RegKind) const {
|
|
|
|
return isMem(MemKind, RegKind) && inRange(Mem.Disp, -524288, 524287);
|
2013-07-02 22:56:45 +08:00
|
|
|
}
|
|
|
|
bool isMemDisp12Len8(RegisterKind RegKind) const {
|
2015-05-05 01:40:53 +08:00
|
|
|
return isMemDisp12(BDLMem, RegKind) && inRange(Mem.Length, 1, 0x100);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2015-05-06 03:23:40 +08:00
|
|
|
void addBDVAddrOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 3 && "Invalid number of operands");
|
|
|
|
assert(isMem(BDVMem) && "Invalid operand type");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(Mem.Base));
|
2015-05-06 03:23:40 +08:00
|
|
|
addExpr(Inst, Mem.Disp);
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(Mem.Index));
|
2015-05-06 03:23:40 +08:00
|
|
|
}
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Override MCParsedAsmOperand.
|
2014-03-06 20:03:36 +08:00
|
|
|
SMLoc getStartLoc() const override { return StartLoc; }
|
|
|
|
SMLoc getEndLoc() const override { return EndLoc; }
|
|
|
|
void print(raw_ostream &OS) const override;
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Used by the TableGen code to add particular types of operand
|
|
|
|
// to an instruction.
|
|
|
|
void addRegOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(getReg()));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
void addAccessRegOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands");
|
|
|
|
assert(Kind == KindAccessReg && "Invalid operand type");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createImm(AccessReg));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
void addImmOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 1 && "Invalid number of operands");
|
|
|
|
addExpr(Inst, getImm());
|
|
|
|
}
|
|
|
|
void addBDAddrOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 2 && "Invalid number of operands");
|
2015-05-05 01:40:53 +08:00
|
|
|
assert(isMem(BDMem) && "Invalid operand type");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(Mem.Base));
|
2013-05-07 00:15:19 +08:00
|
|
|
addExpr(Inst, Mem.Disp);
|
|
|
|
}
|
|
|
|
void addBDXAddrOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 3 && "Invalid number of operands");
|
2015-05-05 01:40:53 +08:00
|
|
|
assert(isMem(BDXMem) && "Invalid operand type");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(Mem.Base));
|
2013-05-07 00:15:19 +08:00
|
|
|
addExpr(Inst, Mem.Disp);
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(Mem.Index));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2013-07-02 22:56:45 +08:00
|
|
|
void addBDLAddrOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 3 && "Invalid number of operands");
|
2015-05-05 01:40:53 +08:00
|
|
|
assert(isMem(BDLMem) && "Invalid operand type");
|
2015-05-14 02:37:00 +08:00
|
|
|
Inst.addOperand(MCOperand::createReg(Mem.Base));
|
2013-07-02 22:56:45 +08:00
|
|
|
addExpr(Inst, Mem.Disp);
|
|
|
|
addExpr(Inst, Mem.Length);
|
|
|
|
}
|
2015-02-18 17:11:36 +08:00
|
|
|
void addImmTLSOperands(MCInst &Inst, unsigned N) const {
|
|
|
|
assert(N == 2 && "Invalid number of operands");
|
|
|
|
assert(Kind == KindImmTLS && "Invalid operand type");
|
|
|
|
addExpr(Inst, ImmTLS.Imm);
|
|
|
|
if (ImmTLS.Sym)
|
|
|
|
addExpr(Inst, ImmTLS.Sym);
|
|
|
|
}
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Used by the TableGen code to check for particular operand types.
|
|
|
|
bool isGR32() const { return isReg(GR32Reg); }
|
2013-09-30 18:45:16 +08:00
|
|
|
bool isGRH32() const { return isReg(GRH32Reg); }
|
2013-10-01 19:26:28 +08:00
|
|
|
bool isGRX32() const { return false; }
|
2013-05-07 00:15:19 +08:00
|
|
|
bool isGR64() const { return isReg(GR64Reg); }
|
|
|
|
bool isGR128() const { return isReg(GR128Reg); }
|
|
|
|
bool isADDR32() const { return isReg(ADDR32Reg); }
|
|
|
|
bool isADDR64() const { return isReg(ADDR64Reg); }
|
|
|
|
bool isADDR128() const { return false; }
|
|
|
|
bool isFP32() const { return isReg(FP32Reg); }
|
|
|
|
bool isFP64() const { return isReg(FP64Reg); }
|
|
|
|
bool isFP128() const { return isReg(FP128Reg); }
|
2015-05-06 03:23:40 +08:00
|
|
|
bool isVR32() const { return isReg(VR32Reg); }
|
|
|
|
bool isVR64() const { return isReg(VR64Reg); }
|
|
|
|
bool isVF128() const { return false; }
|
|
|
|
bool isVR128() const { return isReg(VR128Reg); }
|
2015-05-05 01:40:53 +08:00
|
|
|
bool isBDAddr32Disp12() const { return isMemDisp12(BDMem, ADDR32Reg); }
|
|
|
|
bool isBDAddr32Disp20() const { return isMemDisp20(BDMem, ADDR32Reg); }
|
|
|
|
bool isBDAddr64Disp12() const { return isMemDisp12(BDMem, ADDR64Reg); }
|
|
|
|
bool isBDAddr64Disp20() const { return isMemDisp20(BDMem, ADDR64Reg); }
|
|
|
|
bool isBDXAddr64Disp12() const { return isMemDisp12(BDXMem, ADDR64Reg); }
|
|
|
|
bool isBDXAddr64Disp20() const { return isMemDisp20(BDXMem, ADDR64Reg); }
|
2013-07-02 22:56:45 +08:00
|
|
|
bool isBDLAddr64Disp12Len8() const { return isMemDisp12Len8(ADDR64Reg); }
|
2015-05-06 03:23:40 +08:00
|
|
|
bool isBDVAddr64Disp12() const { return isMemDisp12(BDVMem, ADDR64Reg); }
|
|
|
|
bool isU1Imm() const { return isImm(0, 1); }
|
|
|
|
bool isU2Imm() const { return isImm(0, 3); }
|
|
|
|
bool isU3Imm() const { return isImm(0, 7); }
|
2013-05-07 00:15:19 +08:00
|
|
|
bool isU4Imm() const { return isImm(0, 15); }
|
|
|
|
bool isU6Imm() const { return isImm(0, 63); }
|
|
|
|
bool isU8Imm() const { return isImm(0, 255); }
|
|
|
|
bool isS8Imm() const { return isImm(-128, 127); }
|
2015-05-06 03:23:40 +08:00
|
|
|
bool isU12Imm() const { return isImm(0, 4095); }
|
2013-05-07 00:15:19 +08:00
|
|
|
bool isU16Imm() const { return isImm(0, 65535); }
|
|
|
|
bool isS16Imm() const { return isImm(-32768, 32767); }
|
|
|
|
bool isU32Imm() const { return isImm(0, (1LL << 32) - 1); }
|
|
|
|
bool isS32Imm() const { return isImm(-(1LL << 31), (1LL << 31) - 1); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class SystemZAsmParser : public MCTargetAsmParser {
|
|
|
|
#define GET_ASSEMBLER_HEADER
|
|
|
|
#include "SystemZGenAsmMatcher.inc"
|
|
|
|
|
|
|
|
private:
|
|
|
|
MCSubtargetInfo &STI;
|
|
|
|
MCAsmParser &Parser;
|
2013-05-24 22:14:38 +08:00
|
|
|
enum RegisterGroup {
|
|
|
|
RegGR,
|
|
|
|
RegFP,
|
2015-05-06 03:23:40 +08:00
|
|
|
RegV,
|
2013-05-24 22:14:38 +08:00
|
|
|
RegAccess
|
|
|
|
};
|
2013-05-07 00:15:19 +08:00
|
|
|
struct Register {
|
2013-05-24 22:14:38 +08:00
|
|
|
RegisterGroup Group;
|
|
|
|
unsigned Num;
|
2013-05-07 00:15:19 +08:00
|
|
|
SMLoc StartLoc, EndLoc;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool parseRegister(Register &Reg);
|
|
|
|
|
2013-05-24 22:26:46 +08:00
|
|
|
bool parseRegister(Register &Reg, RegisterGroup Group, const unsigned *Regs,
|
|
|
|
bool IsAddress = false);
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseRegister(OperandVector &Operands,
|
|
|
|
RegisterGroup Group, const unsigned *Regs,
|
|
|
|
RegisterKind Kind);
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2013-05-24 22:26:46 +08:00
|
|
|
bool parseAddress(unsigned &Base, const MCExpr *&Disp,
|
2015-05-06 03:23:40 +08:00
|
|
|
unsigned &Index, bool &IsVector, const MCExpr *&Length,
|
2013-07-02 22:56:45 +08:00
|
|
|
const unsigned *Regs, RegisterKind RegKind);
|
2013-05-24 22:26:46 +08:00
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseAddress(OperandVector &Operands,
|
2015-05-05 01:40:53 +08:00
|
|
|
MemoryKind MemKind, const unsigned *Regs,
|
|
|
|
RegisterKind RegKind);
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2015-02-18 17:11:36 +08:00
|
|
|
OperandMatchResultTy parsePCRel(OperandVector &Operands, int64_t MinVal,
|
|
|
|
int64_t MaxVal, bool AllowTLS);
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
bool parseOperand(OperandVector &Operands, StringRef Mnemonic);
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
public:
|
2013-09-12 18:28:05 +08:00
|
|
|
SystemZAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
|
2014-04-23 19:16:03 +08:00
|
|
|
const MCInstrInfo &MII,
|
|
|
|
const MCTargetOptions &Options)
|
2013-09-12 18:28:05 +08:00
|
|
|
: MCTargetAsmParser(), STI(sti), Parser(parser) {
|
2013-05-07 00:15:19 +08:00
|
|
|
MCAsmParserExtension::Initialize(Parser);
|
|
|
|
|
|
|
|
// Initialize the set of available features.
|
|
|
|
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override MCTargetAsmParser.
|
2014-03-06 20:03:36 +08:00
|
|
|
bool ParseDirective(AsmToken DirectiveID) override;
|
|
|
|
bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
|
2014-06-09 00:18:35 +08:00
|
|
|
bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
|
|
|
|
SMLoc NameLoc, OperandVector &Operands) override;
|
2014-03-06 20:03:36 +08:00
|
|
|
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandVector &Operands, MCStreamer &Out,
|
2014-08-18 19:49:42 +08:00
|
|
|
uint64_t &ErrorInfo,
|
2014-03-06 20:03:36 +08:00
|
|
|
bool MatchingInlineAsm) override;
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Used by the TableGen code to parse particular operand types.
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseGR32(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegGR, SystemZMC::GR32Regs, GR32Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseGRH32(OperandVector &Operands) {
|
2013-09-30 18:45:16 +08:00
|
|
|
return parseRegister(Operands, RegGR, SystemZMC::GRH32Regs, GRH32Reg);
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseGRX32(OperandVector &Operands) {
|
2013-10-01 19:26:28 +08:00
|
|
|
llvm_unreachable("GRX32 should only be used for pseudo instructions");
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseGR64(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegGR, SystemZMC::GR64Regs, GR64Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseGR128(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegGR, SystemZMC::GR128Regs, GR128Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseADDR32(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegGR, SystemZMC::GR32Regs, ADDR32Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseADDR64(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegGR, SystemZMC::GR64Regs, ADDR64Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseADDR128(OperandVector &Operands) {
|
2013-05-07 00:15:19 +08:00
|
|
|
llvm_unreachable("Shouldn't be used as an operand");
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseFP32(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegFP, SystemZMC::FP32Regs, FP32Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseFP64(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegFP, SystemZMC::FP64Regs, FP64Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseFP128(OperandVector &Operands) {
|
2013-07-02 22:56:45 +08:00
|
|
|
return parseRegister(Operands, RegFP, SystemZMC::FP128Regs, FP128Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2015-05-06 03:23:40 +08:00
|
|
|
OperandMatchResultTy parseVR32(OperandVector &Operands) {
|
|
|
|
return parseRegister(Operands, RegV, SystemZMC::VR32Regs, VR32Reg);
|
|
|
|
}
|
|
|
|
OperandMatchResultTy parseVR64(OperandVector &Operands) {
|
|
|
|
return parseRegister(Operands, RegV, SystemZMC::VR64Regs, VR64Reg);
|
|
|
|
}
|
|
|
|
OperandMatchResultTy parseVF128(OperandVector &Operands) {
|
|
|
|
llvm_unreachable("Shouldn't be used as an operand");
|
|
|
|
}
|
|
|
|
OperandMatchResultTy parseVR128(OperandVector &Operands) {
|
|
|
|
return parseRegister(Operands, RegV, SystemZMC::VR128Regs, VR128Reg);
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseBDAddr32(OperandVector &Operands) {
|
2015-05-05 01:40:53 +08:00
|
|
|
return parseAddress(Operands, BDMem, SystemZMC::GR32Regs, ADDR32Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseBDAddr64(OperandVector &Operands) {
|
2015-05-05 01:40:53 +08:00
|
|
|
return parseAddress(Operands, BDMem, SystemZMC::GR64Regs, ADDR64Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseBDXAddr64(OperandVector &Operands) {
|
2015-05-05 01:40:53 +08:00
|
|
|
return parseAddress(Operands, BDXMem, SystemZMC::GR64Regs, ADDR64Reg);
|
2013-07-02 22:56:45 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseBDLAddr64(OperandVector &Operands) {
|
2015-05-05 01:40:53 +08:00
|
|
|
return parseAddress(Operands, BDLMem, SystemZMC::GR64Regs, ADDR64Reg);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2015-05-06 03:23:40 +08:00
|
|
|
OperandMatchResultTy parseBDVAddr64(OperandVector &Operands) {
|
|
|
|
return parseAddress(Operands, BDVMem, SystemZMC::GR64Regs, ADDR64Reg);
|
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parseAccessReg(OperandVector &Operands);
|
|
|
|
OperandMatchResultTy parsePCRel16(OperandVector &Operands) {
|
2015-02-18 17:11:36 +08:00
|
|
|
return parsePCRel(Operands, -(1LL << 16), (1LL << 16) - 1, false);
|
2013-05-14 17:47:26 +08:00
|
|
|
}
|
2014-06-09 00:18:35 +08:00
|
|
|
OperandMatchResultTy parsePCRel32(OperandVector &Operands) {
|
2015-02-18 17:11:36 +08:00
|
|
|
return parsePCRel(Operands, -(1LL << 32), (1LL << 32) - 1, false);
|
|
|
|
}
|
|
|
|
OperandMatchResultTy parsePCRelTLS16(OperandVector &Operands) {
|
|
|
|
return parsePCRel(Operands, -(1LL << 16), (1LL << 16) - 1, true);
|
|
|
|
}
|
|
|
|
OperandMatchResultTy parsePCRelTLS32(OperandVector &Operands) {
|
|
|
|
return parsePCRel(Operands, -(1LL << 32), (1LL << 32) - 1, true);
|
2013-05-14 17:47:26 +08:00
|
|
|
}
|
2013-05-07 00:15:19 +08:00
|
|
|
};
|
2014-03-06 18:38:30 +08:00
|
|
|
} // end anonymous namespace
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
#define GET_REGISTER_MATCHER
|
|
|
|
#define GET_SUBTARGET_FEATURE_NAME
|
|
|
|
#define GET_MATCHER_IMPLEMENTATION
|
|
|
|
#include "SystemZGenAsmMatcher.inc"
|
|
|
|
|
|
|
|
void SystemZOperand::print(raw_ostream &OS) const {
|
|
|
|
llvm_unreachable("Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse one register of the form %<prefix><number>.
|
|
|
|
bool SystemZAsmParser::parseRegister(Register &Reg) {
|
|
|
|
Reg.StartLoc = Parser.getTok().getLoc();
|
|
|
|
|
|
|
|
// Eat the % prefix.
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Percent))
|
2013-05-24 22:26:46 +08:00
|
|
|
return Error(Parser.getTok().getLoc(), "register expected");
|
2013-05-07 00:15:19 +08:00
|
|
|
Parser.Lex();
|
|
|
|
|
|
|
|
// Expect a register name.
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier))
|
2013-05-24 22:26:46 +08:00
|
|
|
return Error(Reg.StartLoc, "invalid register");
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2013-05-24 22:14:38 +08:00
|
|
|
// Check that there's a prefix.
|
2013-05-07 00:15:19 +08:00
|
|
|
StringRef Name = Parser.getTok().getString();
|
|
|
|
if (Name.size() < 2)
|
2013-05-24 22:26:46 +08:00
|
|
|
return Error(Reg.StartLoc, "invalid register");
|
2013-05-24 22:14:38 +08:00
|
|
|
char Prefix = Name[0];
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Treat the rest of the register name as a register number.
|
2013-05-24 22:14:38 +08:00
|
|
|
if (Name.substr(1).getAsInteger(10, Reg.Num))
|
2013-05-24 22:26:46 +08:00
|
|
|
return Error(Reg.StartLoc, "invalid register");
|
2013-05-24 22:14:38 +08:00
|
|
|
|
|
|
|
// Look for valid combinations of prefix and number.
|
|
|
|
if (Prefix == 'r' && Reg.Num < 16)
|
|
|
|
Reg.Group = RegGR;
|
|
|
|
else if (Prefix == 'f' && Reg.Num < 16)
|
|
|
|
Reg.Group = RegFP;
|
2015-05-06 03:23:40 +08:00
|
|
|
else if (Prefix == 'v' && Reg.Num < 32)
|
|
|
|
Reg.Group = RegV;
|
2013-05-24 22:14:38 +08:00
|
|
|
else if (Prefix == 'a' && Reg.Num < 16)
|
|
|
|
Reg.Group = RegAccess;
|
|
|
|
else
|
2013-05-24 22:26:46 +08:00
|
|
|
return Error(Reg.StartLoc, "invalid register");
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
Reg.EndLoc = Parser.getTok().getLoc();
|
|
|
|
Parser.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-24 22:14:38 +08:00
|
|
|
// Parse a register of group Group. If Regs is nonnull, use it to map
|
|
|
|
// the raw register number to LLVM numbering, with zero entries indicating
|
|
|
|
// an invalid register. IsAddress says whether the register appears in an
|
|
|
|
// address context.
|
2013-05-24 22:26:46 +08:00
|
|
|
bool SystemZAsmParser::parseRegister(Register &Reg, RegisterGroup Group,
|
|
|
|
const unsigned *Regs, bool IsAddress) {
|
|
|
|
if (parseRegister(Reg))
|
|
|
|
return true;
|
|
|
|
if (Reg.Group != Group)
|
|
|
|
return Error(Reg.StartLoc, "invalid operand for instruction");
|
|
|
|
if (Regs && Regs[Reg.Num] == 0)
|
|
|
|
return Error(Reg.StartLoc, "invalid register pair");
|
|
|
|
if (Reg.Num == 0 && IsAddress)
|
|
|
|
return Error(Reg.StartLoc, "%r0 used in an address");
|
2013-05-24 22:14:38 +08:00
|
|
|
if (Regs)
|
|
|
|
Reg.Num = Regs[Reg.Num];
|
2013-05-24 22:26:46 +08:00
|
|
|
return false;
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
2013-05-24 22:14:38 +08:00
|
|
|
// Parse a register and add it to Operands. The other arguments are as above.
|
2013-05-07 00:15:19 +08:00
|
|
|
SystemZAsmParser::OperandMatchResultTy
|
2014-06-09 00:18:35 +08:00
|
|
|
SystemZAsmParser::parseRegister(OperandVector &Operands, RegisterGroup Group,
|
|
|
|
const unsigned *Regs, RegisterKind Kind) {
|
2013-05-24 22:26:46 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::Percent))
|
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
Register Reg;
|
2013-07-02 22:56:45 +08:00
|
|
|
bool IsAddress = (Kind == ADDR32Reg || Kind == ADDR64Reg);
|
2013-05-24 22:26:46 +08:00
|
|
|
if (parseRegister(Reg, Group, Regs, IsAddress))
|
|
|
|
return MatchOperand_ParseFail;
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2013-05-24 22:26:46 +08:00
|
|
|
Operands.push_back(SystemZOperand::createReg(Kind, Reg.Num,
|
|
|
|
Reg.StartLoc, Reg.EndLoc));
|
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2013-07-02 22:56:45 +08:00
|
|
|
// Parse a memory operand into Base, Disp, Index and Length.
|
|
|
|
// Regs maps asm register numbers to LLVM register numbers and RegKind
|
|
|
|
// says what kind of address register we're using (ADDR32Reg or ADDR64Reg).
|
2013-05-24 22:26:46 +08:00
|
|
|
bool SystemZAsmParser::parseAddress(unsigned &Base, const MCExpr *&Disp,
|
2015-05-06 03:23:40 +08:00
|
|
|
unsigned &Index, bool &IsVector,
|
|
|
|
const MCExpr *&Length, const unsigned *Regs,
|
2013-07-02 22:56:45 +08:00
|
|
|
RegisterKind RegKind) {
|
2013-05-07 00:15:19 +08:00
|
|
|
// Parse the displacement, which must always be present.
|
|
|
|
if (getParser().parseExpression(Disp))
|
2013-05-24 22:26:46 +08:00
|
|
|
return true;
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Parse the optional base and index.
|
2013-05-24 22:26:46 +08:00
|
|
|
Index = 0;
|
|
|
|
Base = 0;
|
2015-05-06 03:23:40 +08:00
|
|
|
IsVector = false;
|
2014-04-25 13:30:21 +08:00
|
|
|
Length = nullptr;
|
2013-05-07 00:15:19 +08:00
|
|
|
if (getLexer().is(AsmToken::LParen)) {
|
|
|
|
Parser.Lex();
|
|
|
|
|
2013-07-02 22:56:45 +08:00
|
|
|
if (getLexer().is(AsmToken::Percent)) {
|
|
|
|
// Parse the first register and decide whether it's a base or an index.
|
|
|
|
Register Reg;
|
2015-05-06 03:23:40 +08:00
|
|
|
if (parseRegister(Reg))
|
2013-07-02 22:56:45 +08:00
|
|
|
return true;
|
2015-05-06 03:23:40 +08:00
|
|
|
if (Reg.Group == RegV) {
|
|
|
|
// A vector index register. The base register is optional.
|
|
|
|
IsVector = true;
|
|
|
|
Index = SystemZMC::VR128Regs[Reg.Num];
|
|
|
|
} else if (Reg.Group == RegGR) {
|
|
|
|
if (Reg.Num == 0)
|
|
|
|
return Error(Reg.StartLoc, "%r0 used in an address");
|
|
|
|
// If the are two registers, the first one is the index and the
|
|
|
|
// second is the base.
|
|
|
|
if (getLexer().is(AsmToken::Comma))
|
|
|
|
Index = Regs[Reg.Num];
|
|
|
|
else
|
|
|
|
Base = Regs[Reg.Num];
|
|
|
|
} else
|
|
|
|
return Error(Reg.StartLoc, "invalid address register");
|
2013-07-02 22:56:45 +08:00
|
|
|
} else {
|
|
|
|
// Parse the length.
|
|
|
|
if (getParser().parseExpression(Length))
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2013-07-02 22:56:45 +08:00
|
|
|
// Check whether there's a second register. It's the base if so.
|
2013-05-07 00:15:19 +08:00
|
|
|
if (getLexer().is(AsmToken::Comma)) {
|
|
|
|
Parser.Lex();
|
2013-07-02 22:56:45 +08:00
|
|
|
Register Reg;
|
2013-05-24 22:26:46 +08:00
|
|
|
if (parseRegister(Reg, RegGR, Regs, RegKind))
|
|
|
|
return true;
|
2013-07-02 22:56:45 +08:00
|
|
|
Base = Reg.Num;
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Consume the closing bracket.
|
|
|
|
if (getLexer().isNot(AsmToken::RParen))
|
2013-05-24 22:26:46 +08:00
|
|
|
return Error(Parser.getTok().getLoc(), "unexpected token in address");
|
2013-05-07 00:15:19 +08:00
|
|
|
Parser.Lex();
|
|
|
|
}
|
2013-05-24 22:26:46 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse a memory operand and add it to Operands. The other arguments
|
|
|
|
// are as above.
|
|
|
|
SystemZAsmParser::OperandMatchResultTy
|
2015-05-05 01:40:53 +08:00
|
|
|
SystemZAsmParser::parseAddress(OperandVector &Operands, MemoryKind MemKind,
|
|
|
|
const unsigned *Regs, RegisterKind RegKind) {
|
2013-05-24 22:26:46 +08:00
|
|
|
SMLoc StartLoc = Parser.getTok().getLoc();
|
|
|
|
unsigned Base, Index;
|
2015-05-06 03:23:40 +08:00
|
|
|
bool IsVector;
|
2013-05-24 22:26:46 +08:00
|
|
|
const MCExpr *Disp;
|
2013-07-02 22:56:45 +08:00
|
|
|
const MCExpr *Length;
|
2015-05-06 03:23:40 +08:00
|
|
|
if (parseAddress(Base, Disp, Index, IsVector, Length, Regs, RegKind))
|
2013-05-24 22:26:46 +08:00
|
|
|
return MatchOperand_ParseFail;
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2015-05-06 03:23:40 +08:00
|
|
|
if (IsVector && MemKind != BDVMem) {
|
|
|
|
Error(StartLoc, "invalid use of vector addressing");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2013-07-02 22:56:45 +08:00
|
|
|
|
2015-05-06 03:23:40 +08:00
|
|
|
if (!IsVector && MemKind == BDVMem) {
|
|
|
|
Error(StartLoc, "vector index required in address");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2013-07-02 22:56:45 +08:00
|
|
|
|
2015-05-06 03:23:40 +08:00
|
|
|
if (Index && MemKind != BDXMem && MemKind != BDVMem) {
|
|
|
|
Error(StartLoc, "invalid use of indexed addressing");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Length && MemKind != BDLMem) {
|
|
|
|
Error(StartLoc, "invalid use of length addressing");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Length && MemKind == BDLMem) {
|
|
|
|
Error(StartLoc, "missing length in address");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2013-07-02 22:56:45 +08:00
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
SMLoc EndLoc =
|
|
|
|
SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
|
2015-05-05 01:40:53 +08:00
|
|
|
Operands.push_back(SystemZOperand::createMem(MemKind, RegKind, Base, Disp,
|
|
|
|
Index, Length, StartLoc,
|
|
|
|
EndLoc));
|
2013-05-07 00:15:19 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZAsmParser::ParseDirective(AsmToken DirectiveID) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
|
|
|
|
SMLoc &EndLoc) {
|
|
|
|
Register Reg;
|
|
|
|
if (parseRegister(Reg))
|
2013-05-24 22:26:46 +08:00
|
|
|
return true;
|
2013-05-24 22:14:38 +08:00
|
|
|
if (Reg.Group == RegGR)
|
|
|
|
RegNo = SystemZMC::GR64Regs[Reg.Num];
|
|
|
|
else if (Reg.Group == RegFP)
|
|
|
|
RegNo = SystemZMC::FP64Regs[Reg.Num];
|
2015-05-06 03:23:40 +08:00
|
|
|
else if (Reg.Group == RegV)
|
|
|
|
RegNo = SystemZMC::VR128Regs[Reg.Num];
|
2013-05-24 22:14:38 +08:00
|
|
|
else
|
|
|
|
// FIXME: Access registers aren't modelled as LLVM registers yet.
|
|
|
|
return Error(Reg.StartLoc, "invalid operand for instruction");
|
2013-05-07 00:15:19 +08:00
|
|
|
StartLoc = Reg.StartLoc;
|
|
|
|
EndLoc = Reg.EndLoc;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
bool SystemZAsmParser::ParseInstruction(ParseInstructionInfo &Info,
|
|
|
|
StringRef Name, SMLoc NameLoc,
|
|
|
|
OperandVector &Operands) {
|
2013-05-07 00:15:19 +08:00
|
|
|
Operands.push_back(SystemZOperand::createToken(Name, NameLoc));
|
|
|
|
|
|
|
|
// Read the remaining operands.
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
|
|
|
// Read the first operand.
|
|
|
|
if (parseOperand(Operands, Name)) {
|
|
|
|
Parser.eatToEndOfStatement();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read any subsequent operands.
|
|
|
|
while (getLexer().is(AsmToken::Comma)) {
|
|
|
|
Parser.Lex();
|
|
|
|
if (parseOperand(Operands, Name)) {
|
|
|
|
Parser.eatToEndOfStatement();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
|
|
|
SMLoc Loc = getLexer().getLoc();
|
|
|
|
Parser.eatToEndOfStatement();
|
|
|
|
return Error(Loc, "unexpected token in argument list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consume the EndOfStatement.
|
|
|
|
Parser.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
bool SystemZAsmParser::parseOperand(OperandVector &Operands,
|
|
|
|
StringRef Mnemonic) {
|
2013-05-07 00:15:19 +08:00
|
|
|
// Check if the current operand has a custom associated parser, if so, try to
|
|
|
|
// custom parse the operand, or fallback to the general approach.
|
|
|
|
OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
|
|
|
|
if (ResTy == MatchOperand_Success)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If there wasn't a custom match, try the generic matcher below. Otherwise,
|
|
|
|
// there was a match, but an error occurred, in which case, just return that
|
|
|
|
// the operand parsing failed.
|
|
|
|
if (ResTy == MatchOperand_ParseFail)
|
|
|
|
return true;
|
|
|
|
|
2013-05-24 22:26:46 +08:00
|
|
|
// Check for a register. All real register operands should have used
|
|
|
|
// a context-dependent parse routine, which gives the required register
|
|
|
|
// class. The code is here to mop up other cases, like those where
|
|
|
|
// the instruction isn't recognized.
|
|
|
|
if (Parser.getTok().is(AsmToken::Percent)) {
|
|
|
|
Register Reg;
|
|
|
|
if (parseRegister(Reg))
|
|
|
|
return true;
|
|
|
|
Operands.push_back(SystemZOperand::createInvalid(Reg.StartLoc, Reg.EndLoc));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The only other type of operand is an immediate or address. As above,
|
|
|
|
// real address operands should have used a context-dependent parse routine,
|
|
|
|
// so we treat any plain expression as an immediate.
|
2013-05-07 00:15:19 +08:00
|
|
|
SMLoc StartLoc = Parser.getTok().getLoc();
|
2013-05-24 22:26:46 +08:00
|
|
|
unsigned Base, Index;
|
2015-05-06 03:23:40 +08:00
|
|
|
bool IsVector;
|
2013-07-02 22:56:45 +08:00
|
|
|
const MCExpr *Expr, *Length;
|
2015-05-06 03:23:40 +08:00
|
|
|
if (parseAddress(Base, Expr, Index, IsVector, Length, SystemZMC::GR64Regs,
|
|
|
|
ADDR64Reg))
|
2013-05-07 00:15:19 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
SMLoc EndLoc =
|
|
|
|
SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
|
2013-07-02 22:56:45 +08:00
|
|
|
if (Base || Index || Length)
|
2013-05-24 22:26:46 +08:00
|
|
|
Operands.push_back(SystemZOperand::createInvalid(StartLoc, EndLoc));
|
|
|
|
else
|
|
|
|
Operands.push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc));
|
2013-05-07 00:15:19 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
bool SystemZAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
|
|
|
OperandVector &Operands,
|
|
|
|
MCStreamer &Out,
|
2014-08-18 19:49:42 +08:00
|
|
|
uint64_t &ErrorInfo,
|
2014-06-09 00:18:35 +08:00
|
|
|
bool MatchingInlineAsm) {
|
2013-05-07 00:15:19 +08:00
|
|
|
MCInst Inst;
|
|
|
|
unsigned MatchResult;
|
|
|
|
|
|
|
|
MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
|
|
|
|
MatchingInlineAsm);
|
|
|
|
switch (MatchResult) {
|
|
|
|
case Match_Success:
|
|
|
|
Inst.setLoc(IDLoc);
|
2014-01-29 07:12:42 +08:00
|
|
|
Out.EmitInstruction(Inst, STI);
|
2013-05-07 00:15:19 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case Match_MissingFeature: {
|
|
|
|
assert(ErrorInfo && "Unknown missing feature!");
|
|
|
|
// Special case the error message for the very common case where only
|
|
|
|
// a single subtarget feature is missing
|
|
|
|
std::string Msg = "instruction requires:";
|
2014-08-18 19:49:42 +08:00
|
|
|
uint64_t Mask = 1;
|
2013-05-07 00:15:19 +08:00
|
|
|
for (unsigned I = 0; I < sizeof(ErrorInfo) * 8 - 1; ++I) {
|
|
|
|
if (ErrorInfo & Mask) {
|
|
|
|
Msg += " ";
|
|
|
|
Msg += getSubtargetFeatureName(ErrorInfo & Mask);
|
|
|
|
}
|
|
|
|
Mask <<= 1;
|
|
|
|
}
|
|
|
|
return Error(IDLoc, Msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Match_InvalidOperand: {
|
|
|
|
SMLoc ErrorLoc = IDLoc;
|
2014-08-18 19:49:42 +08:00
|
|
|
if (ErrorInfo != ~0ULL) {
|
2013-05-07 00:15:19 +08:00
|
|
|
if (ErrorInfo >= Operands.size())
|
|
|
|
return Error(IDLoc, "too few operands for instruction");
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
ErrorLoc = ((SystemZOperand &)*Operands[ErrorInfo]).getStartLoc();
|
2013-05-07 00:15:19 +08:00
|
|
|
if (ErrorLoc == SMLoc())
|
|
|
|
ErrorLoc = IDLoc;
|
|
|
|
}
|
|
|
|
return Error(ErrorLoc, "invalid operand for instruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
case Match_MnemonicFail:
|
|
|
|
return Error(IDLoc, "invalid instruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Unexpected match type");
|
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
SystemZAsmParser::OperandMatchResultTy
|
|
|
|
SystemZAsmParser::parseAccessReg(OperandVector &Operands) {
|
2013-05-24 22:26:46 +08:00
|
|
|
if (Parser.getTok().isNot(AsmToken::Percent))
|
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
Register Reg;
|
2014-04-25 13:30:21 +08:00
|
|
|
if (parseRegister(Reg, RegAccess, nullptr))
|
2013-05-24 22:26:46 +08:00
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
|
|
|
|
Operands.push_back(SystemZOperand::createAccessReg(Reg.Num,
|
|
|
|
Reg.StartLoc,
|
|
|
|
Reg.EndLoc));
|
|
|
|
return MatchOperand_Success;
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
2014-06-09 00:18:35 +08:00
|
|
|
SystemZAsmParser::OperandMatchResultTy
|
|
|
|
SystemZAsmParser::parsePCRel(OperandVector &Operands, int64_t MinVal,
|
2015-02-18 17:11:36 +08:00
|
|
|
int64_t MaxVal, bool AllowTLS) {
|
2013-05-14 17:47:26 +08:00
|
|
|
MCContext &Ctx = getContext();
|
|
|
|
MCStreamer &Out = getStreamer();
|
|
|
|
const MCExpr *Expr;
|
|
|
|
SMLoc StartLoc = Parser.getTok().getLoc();
|
|
|
|
if (getParser().parseExpression(Expr))
|
|
|
|
return MatchOperand_NoMatch;
|
|
|
|
|
|
|
|
// For consistency with the GNU assembler, treat immediates as offsets
|
|
|
|
// from ".".
|
2014-03-06 19:22:58 +08:00
|
|
|
if (auto *CE = dyn_cast<MCConstantExpr>(Expr)) {
|
2013-05-14 17:47:26 +08:00
|
|
|
int64_t Value = CE->getValue();
|
|
|
|
if ((Value & 1) || Value < MinVal || Value > MaxVal) {
|
|
|
|
Error(StartLoc, "offset out of range");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *Sym = Ctx.createTempSymbol();
|
2013-05-14 17:47:26 +08:00
|
|
|
Out.EmitLabel(Sym);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *Base = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None,
|
2013-05-14 17:47:26 +08:00
|
|
|
Ctx);
|
2015-05-30 09:25:56 +08:00
|
|
|
Expr = Value == 0 ? Base : MCBinaryExpr::createAdd(Base, Expr, Ctx);
|
2013-05-14 17:47:26 +08:00
|
|
|
}
|
|
|
|
|
2015-02-18 17:11:36 +08:00
|
|
|
// Optionally match :tls_gdcall: or :tls_ldcall: followed by a TLS symbol.
|
|
|
|
const MCExpr *Sym = nullptr;
|
|
|
|
if (AllowTLS && getLexer().is(AsmToken::Colon)) {
|
|
|
|
Parser.Lex();
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
Error(Parser.getTok().getLoc(), "unexpected token");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
|
|
|
|
StringRef Name = Parser.getTok().getString();
|
|
|
|
if (Name == "tls_gdcall")
|
|
|
|
Kind = MCSymbolRefExpr::VK_TLSGD;
|
|
|
|
else if (Name == "tls_ldcall")
|
|
|
|
Kind = MCSymbolRefExpr::VK_TLSLDM;
|
|
|
|
else {
|
|
|
|
Error(Parser.getTok().getLoc(), "unknown TLS tag");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
Parser.Lex();
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Colon)) {
|
|
|
|
Error(Parser.getTok().getLoc(), "unexpected token");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
Parser.Lex();
|
|
|
|
|
|
|
|
if (Parser.getTok().isNot(AsmToken::Identifier)) {
|
|
|
|
Error(Parser.getTok().getLoc(), "unexpected token");
|
|
|
|
return MatchOperand_ParseFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef Identifier = Parser.getTok().getString();
|
2015-05-30 09:25:56 +08:00
|
|
|
Sym = MCSymbolRefExpr::create(Ctx.getOrCreateSymbol(Identifier),
|
2015-02-18 17:11:36 +08:00
|
|
|
Kind, Ctx);
|
|
|
|
Parser.Lex();
|
|
|
|
}
|
|
|
|
|
2013-05-14 17:47:26 +08:00
|
|
|
SMLoc EndLoc =
|
|
|
|
SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
|
2015-02-18 17:11:36 +08:00
|
|
|
|
|
|
|
if (AllowTLS)
|
|
|
|
Operands.push_back(SystemZOperand::createImmTLS(Expr, Sym,
|
|
|
|
StartLoc, EndLoc));
|
|
|
|
else
|
|
|
|
Operands.push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc));
|
|
|
|
|
2013-05-14 17:47:26 +08:00
|
|
|
return MatchOperand_Success;
|
|
|
|
}
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeSystemZAsmParser() {
|
|
|
|
RegisterMCAsmParser<SystemZAsmParser> X(TheSystemZTarget);
|
|
|
|
}
|