Skip to content

Commit

Permalink
[M68k][NFC] Rename M68kOperand::Kind to KindTy (#112)
Browse files Browse the repository at this point in the history
Rename the M68kOperand::Type enumeration to KindTy to avoid ambiguity
with the Kind field when referencing enumeration values e.g.
`Kind::Value`.

This works around a compilation error under GCC 5, where GCC won't
lookup enum class values if you have a similarly named field
(see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60994).

The error in question is:
`M68kAsmParser.cpp:857:8: error: 'Kind' is not a class, namespace, or enumeration`

Differential Revision: https://reviews.llvm.org/D108723
  • Loading branch information
ricky26 authored Aug 25, 2021
1 parent e6c5dd4 commit a93e47b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ struct M68kMemOp {
class M68kOperand : public MCParsedAsmOperand {
typedef MCParsedAsmOperand Base;

enum class Kind {
enum class KindTy {
Invalid,
Token,
Imm,
MemOp,
};

Kind Kind;
KindTy Kind;
SMLoc Start, End;
union {
StringRef Token;
Expand All @@ -134,7 +134,7 @@ class M68kOperand : public MCParsedAsmOperand {
};

public:
M68kOperand(enum Kind Kind, SMLoc Start, SMLoc End)
M68kOperand(KindTy Kind, SMLoc Start, SMLoc End)
: Base(), Kind(Kind), Start(Start), End(End) {}

SMLoc getStartLoc() const override { return Start; }
Expand All @@ -143,7 +143,7 @@ class M68kOperand : public MCParsedAsmOperand {
void print(raw_ostream &OS) const override;

bool isMem() const override { return false; }
bool isMemOp() const { return Kind == Kind::MemOp; }
bool isMemOp() const { return Kind == KindTy::MemOp; }

static void addExpr(MCInst &Inst, const MCExpr *Expr);

Expand Down Expand Up @@ -248,7 +248,7 @@ void M68kOperand::addExpr(MCInst &Inst, const MCExpr *Expr) {

// Reg
bool M68kOperand::isReg() const {
return Kind == Kind::MemOp && MemOp.Op == M68kMemOp::Kind::Reg;
return Kind == KindTy::MemOp && MemOp.Op == M68kMemOp::Kind::Reg;
}

unsigned M68kOperand::getReg() const {
Expand All @@ -265,27 +265,27 @@ void M68kOperand::addRegOperands(MCInst &Inst, unsigned N) const {

std::unique_ptr<M68kOperand> M68kOperand::createMemOp(M68kMemOp MemOp,
SMLoc Start, SMLoc End) {
auto Op = std::make_unique<M68kOperand>(Kind::MemOp, Start, End);
auto Op = std::make_unique<M68kOperand>(KindTy::MemOp, Start, End);
Op->MemOp = MemOp;
return Op;
}

// Token
bool M68kOperand::isToken() const { return Kind == Kind::Token; }
bool M68kOperand::isToken() const { return Kind == KindTy::Token; }
StringRef M68kOperand::getToken() const {
assert(isToken());
return Token;
}

std::unique_ptr<M68kOperand> M68kOperand::createToken(StringRef Token,
SMLoc Start, SMLoc End) {
auto Op = std::make_unique<M68kOperand>(Kind::Token, Start, End);
auto Op = std::make_unique<M68kOperand>(KindTy::Token, Start, End);
Op->Token = Token;
return Op;
}

// Imm
bool M68kOperand::isImm() const { return Kind == Kind::Imm; }
bool M68kOperand::isImm() const { return Kind == KindTy::Imm; }
void M68kOperand::addImmOperands(MCInst &Inst, unsigned N) const {
assert(isImm() && "wrong oeprand kind");
assert((N == 1) && "can only handle one register operand");
Expand All @@ -295,7 +295,7 @@ void M68kOperand::addImmOperands(MCInst &Inst, unsigned N) const {

std::unique_ptr<M68kOperand> M68kOperand::createImm(const MCExpr *Expr,
SMLoc Start, SMLoc End) {
auto Op = std::make_unique<M68kOperand>(Kind::Imm, Start, End);
auto Op = std::make_unique<M68kOperand>(KindTy::Imm, Start, End);
Op->Expr = Expr;
return Op;
}
Expand Down Expand Up @@ -842,19 +842,19 @@ bool M68kAsmParser::MatchAndEmitInstruction(SMLoc Loc, unsigned &Opcode,

void M68kOperand::print(raw_ostream &OS) const {
switch (Kind) {
case Kind::Invalid:
case KindTy::Invalid:
OS << "invalid";
break;

case Kind::Token:
case KindTy::Token:
OS << "token '" << Token << "'";
break;

case Kind::Imm:
case KindTy::Imm:
OS << "immediate " << Imm;
break;

case Kind::MemOp:
case KindTy::MemOp:
MemOp.print(OS);
break;
}
Expand Down

0 comments on commit a93e47b

Please sign in to comment.