[AArch64] Move initializations of AArch64NamedImmMapper out of void AArch64Operand::print(...)

class AArch64NamedImmMapper is to become dependent of SubTargetFeatures, while class AArch64Operand don't have access to the latter. 

So, AArch64NamedImmMapper constructor invocations are refactored away from methods of AArch64Operand.

Reviewers: jmolloy

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D8579


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233297 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vladimir Sukharev 2015-03-26 17:29:53 +00:00
parent a9228aa73b
commit 05641295c3

View File

@ -204,6 +204,8 @@ private:
struct BarrierOp {
unsigned Val; // Not the enum since not all values have names.
const char *Data;
unsigned Length;
};
struct SysRegOp {
@ -220,6 +222,8 @@ private:
struct PrefetchOp {
unsigned Val;
const char *Data;
unsigned Length;
};
struct ShiftExtendOp {
@ -347,6 +351,11 @@ public:
return Barrier.Val;
}
StringRef getBarrierName() const {
assert(Kind == k_Barrier && "Invalid access!");
return StringRef(Barrier.Data, Barrier.Length);
}
unsigned getReg() const override {
assert(Kind == k_Register && "Invalid access!");
return Reg.RegNum;
@ -382,6 +391,11 @@ public:
return Prefetch.Val;
}
StringRef getPrefetchName() const {
assert(Kind == k_Prefetch && "Invalid access!");
return StringRef(Prefetch.Data, Prefetch.Length);
}
AArch64_AM::ShiftExtendType getShiftExtendType() const {
assert(Kind == k_ShiftExtend && "Invalid access!");
return ShiftExtend.Type;
@ -1595,10 +1609,14 @@ public:
return Op;
}
static std::unique_ptr<AArch64Operand> CreateBarrier(unsigned Val, SMLoc S,
static std::unique_ptr<AArch64Operand> CreateBarrier(unsigned Val,
StringRef Str,
SMLoc S,
MCContext &Ctx) {
auto Op = make_unique<AArch64Operand>(k_Barrier, Ctx);
Op->Barrier.Val = Val;
Op->Barrier.Data = Str.data();
Op->Barrier.Length = Str.size();
Op->StartLoc = S;
Op->EndLoc = S;
return Op;
@ -1629,10 +1647,14 @@ public:
return Op;
}
static std::unique_ptr<AArch64Operand> CreatePrefetch(unsigned Val, SMLoc S,
static std::unique_ptr<AArch64Operand> CreatePrefetch(unsigned Val,
StringRef Str,
SMLoc S,
MCContext &Ctx) {
auto Op = make_unique<AArch64Operand>(k_Prefetch, Ctx);
Op->Prefetch.Val = Val;
Op->Barrier.Data = Str.data();
Op->Barrier.Length = Str.size();
Op->StartLoc = S;
Op->EndLoc = S;
return Op;
@ -1660,9 +1682,8 @@ void AArch64Operand::print(raw_ostream &OS) const {
<< AArch64_AM::getFPImmFloat(getFPImm()) << ") >";
break;
case k_Barrier: {
bool Valid;
StringRef Name = AArch64DB::DBarrierMapper().toString(getBarrier(), Valid);
if (Valid)
StringRef Name = getBarrierName();
if (!Name.empty())
OS << "<barrier " << Name << ">";
else
OS << "<barrier invalid #" << getBarrier() << ">";
@ -1705,9 +1726,8 @@ void AArch64Operand::print(raw_ostream &OS) const {
OS << "c" << getSysCR();
break;
case k_Prefetch: {
bool Valid;
StringRef Name = AArch64PRFM::PRFMMapper().toString(getPrefetch(), Valid);
if (Valid)
StringRef Name = getPrefetchName();
if (!Name.empty())
OS << "<prfop " << Name << ">";
else
OS << "<prfop invalid #" << getPrefetch() << ">";
@ -1950,7 +1970,11 @@ AArch64AsmParser::tryParsePrefetch(OperandVector &Operands) {
return MatchOperand_ParseFail;
}
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, S, getContext()));
bool Valid;
auto Mapper = AArch64PRFM::PRFMMapper();
StringRef Name = Mapper.toString(MCE->getValue(), Valid);
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, Name,
S, getContext()));
return MatchOperand_Success;
}
@ -1960,14 +1984,16 @@ AArch64AsmParser::tryParsePrefetch(OperandVector &Operands) {
}
bool Valid;
unsigned prfop = AArch64PRFM::PRFMMapper().fromString(Tok.getString(), Valid);
auto Mapper = AArch64PRFM::PRFMMapper();
unsigned prfop = Mapper.fromString(Tok.getString(), Valid);
if (!Valid) {
TokError("pre-fetch hint expected");
return MatchOperand_ParseFail;
}
Parser.Lex(); // Eat identifier token.
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, S, getContext()));
Operands.push_back(AArch64Operand::CreatePrefetch(prfop, Tok.getString(),
S, getContext()));
return MatchOperand_Success;
}
@ -2569,8 +2595,11 @@ AArch64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
Error(ExprLoc, "barrier operand out of range");
return MatchOperand_ParseFail;
}
Operands.push_back(
AArch64Operand::CreateBarrier(MCE->getValue(), ExprLoc, getContext()));
bool Valid;
auto Mapper = AArch64DB::DBarrierMapper();
StringRef Name = Mapper.toString(MCE->getValue(), Valid);
Operands.push_back( AArch64Operand::CreateBarrier(MCE->getValue(), Name,
ExprLoc, getContext()));
return MatchOperand_Success;
}
@ -2580,7 +2609,8 @@ AArch64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
}
bool Valid;
unsigned Opt = AArch64DB::DBarrierMapper().fromString(Tok.getString(), Valid);
auto Mapper = AArch64DB::DBarrierMapper();
unsigned Opt = Mapper.fromString(Tok.getString(), Valid);
if (!Valid) {
TokError("invalid barrier option name");
return MatchOperand_ParseFail;
@ -2592,8 +2622,8 @@ AArch64AsmParser::tryParseBarrierOperand(OperandVector &Operands) {
return MatchOperand_ParseFail;
}
Operands.push_back(
AArch64Operand::CreateBarrier(Opt, getLoc(), getContext()));
Operands.push_back( AArch64Operand::CreateBarrier(Opt, Tok.getString(),
getLoc(), getContext()));
Parser.Lex(); // Consume the option
return MatchOperand_Success;
@ -2618,8 +2648,8 @@ AArch64AsmParser::tryParseSysReg(OperandVector &Operands) {
assert(IsKnown == (MSRReg != -1U) &&
"register should be -1 if and only if it's unknown");
uint32_t PStateField =
AArch64PState::PStateMapper().fromString(Tok.getString(), IsKnown);
auto PStateMapper = AArch64PState::PStateMapper();
uint32_t PStateField = PStateMapper.fromString(Tok.getString(), IsKnown);
assert(IsKnown == (PStateField != -1U) &&
"register should be -1 if and only if it's unknown");