88
99#include " MCTargetDesc/PPCMCExpr.h"
1010#include " MCTargetDesc/PPCMCTargetDesc.h"
11- #include " PPCTargetStreamer.h"
1211#include " PPCInstrInfo.h"
12+ #include " PPCTargetStreamer.h"
1313#include " TargetInfo/PowerPCTargetInfo.h"
1414#include " llvm/ADT/STLExtras.h"
1515#include " llvm/ADT/Twine.h"
@@ -100,14 +100,10 @@ struct PPCOperand;
100100class PPCAsmParser : public MCTargetAsmParser {
101101 bool IsPPC64;
102102
103- bool UsesMemOp;
104-
105103 void Warning (SMLoc L, const Twine &Msg) { getParser ().Warning (L, Msg); }
106104
107105 bool isPPC64 () const { return IsPPC64; }
108106
109- bool usesMemOp () const { return UsesMemOp; }
110-
111107 MCRegister matchRegisterName (int64_t &IntVal);
112108
113109 bool parseRegister (MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) override ;
@@ -135,6 +131,8 @@ class PPCAsmParser : public MCTargetAsmParser {
135131
136132 void processInstruction (MCInst &Inst, const OperandVector &Ops);
137133
134+ bool hasMemOp (const OperandVector &Ops);
135+
138136 // / @name Auto-generated Match Functions
139137 // / {
140138
@@ -151,7 +149,6 @@ class PPCAsmParser : public MCTargetAsmParser {
151149 // Check for 64-bit vs. 32-bit pointer mode.
152150 const Triple &TheTriple = STI.getTargetTriple ();
153151 IsPPC64 = TheTriple.isPPC64 ();
154- UsesMemOp = false ;
155152 // Initialize the set of available features.
156153 setAvailableFeatures (ComputeAvailableFeatures (STI.getFeatureBits ()));
157154 }
@@ -190,6 +187,7 @@ struct PPCOperand : public MCParsedAsmOperand {
190187
191188 struct ImmOp {
192189 int64_t Val;
190+ bool IsMemOp;
193191 };
194192
195193 struct ExprOp {
@@ -250,6 +248,11 @@ struct PPCOperand : public MCParsedAsmOperand {
250248 // / isPPC64 - True if this operand is for an instruction in 64-bit mode.
251249 bool isPPC64 () const { return IsPPC64; }
252250
251+ // / isMemOp - True if this operand is a memory operand.
252+ bool isMemOp () const {
253+ return Kind == Immediate && Imm.IsMemOp ;
254+ }
255+
253256 int64_t getImm () const {
254257 assert (Kind == Immediate && " Invalid access!" );
255258 return Imm.Val ;
@@ -702,9 +705,10 @@ struct PPCOperand : public MCParsedAsmOperand {
702705 }
703706
704707 static std::unique_ptr<PPCOperand> CreateImm (int64_t Val, SMLoc S, SMLoc E,
705- bool IsPPC64) {
708+ bool IsPPC64, bool IsMemOp = false ) {
706709 auto Op = std::make_unique<PPCOperand>(Immediate);
707710 Op->Imm .Val = Val;
711+ Op->Imm .IsMemOp = IsMemOp;
708712 Op->StartLoc = S;
709713 Op->EndLoc = E;
710714 Op->IsPPC64 = IsPPC64;
@@ -1263,10 +1267,11 @@ bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
12631267 MCStreamer &Out, uint64_t &ErrorInfo,
12641268 bool MatchingInlineAsm) {
12651269 MCInst Inst;
1266- const PPCInstrInfo *TII = static_cast <const PPCInstrInfo*>(&MII);
1270+ const PPCInstrInfo *TII = static_cast <const PPCInstrInfo *>(&MII);
1271+
12671272 switch (MatchInstructionImpl (Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
12681273 case Match_Success:
1269- if (usesMemOp ( ) != TII->isMemOp (Inst.getOpcode ()))
1274+ if (hasMemOp (Operands ) != TII->isMemOp (Inst.getOpcode ()))
12701275 return Error (IDLoc, " invalid operand for instruction" );
12711276 // Post-process instructions (typically extended mnemonics)
12721277 processInstruction (Inst, Operands);
@@ -1603,7 +1608,6 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
16031608
16041609 // Otherwise, check for D-form memory operands
16051610 if (!TlsCall && parseOptionalToken (AsmToken::LParen)) {
1606- UsesMemOp = true ;
16071611 S = Parser.getTok ().getLoc ();
16081612
16091613 int64_t IntVal;
@@ -1626,7 +1630,7 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
16261630 E = Parser.getTok ().getLoc ();
16271631 if (parseToken (AsmToken::RParen, " missing ')'" ))
16281632 return true ;
1629- Operands.push_back (PPCOperand::CreateImm (IntVal, S, E, isPPC64 ()));
1633+ Operands.push_back (PPCOperand::CreateImm (IntVal, S, E, isPPC64 (), /* IsMemOp= */ true ));
16301634 }
16311635
16321636 return false ;
@@ -1635,7 +1639,6 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
16351639// / Parse an instruction mnemonic followed by its operands.
16361640bool PPCAsmParser::parseInstruction (ParseInstructionInfo &Info, StringRef Name,
16371641 SMLoc NameLoc, OperandVector &Operands) {
1638- UsesMemOp = false ;
16391642 // The first operand is the token for the instruction name.
16401643 // If the next character is a '+' or '-', we need to add it to the
16411644 // instruction name, to match what TableGen is doing.
@@ -1915,3 +1918,12 @@ PPCAsmParser::applyModifierToExpr(const MCExpr *E,
19151918 return nullptr ;
19161919 }
19171920}
1921+
1922+ bool PPCAsmParser::hasMemOp (const OperandVector &Operands) {
1923+ for (const auto &Operand : Operands) {
1924+ const PPCOperand &Op = static_cast <const PPCOperand &>(*Operand);
1925+ if (Op.isMemOp ())
1926+ return true ;
1927+ }
1928+ return false ;
1929+ }
0 commit comments