[llvm] r244093 - MIR Parser: Extract the IR constant parsing code into a new method. NFC.

Alex Lorenz arphaman at gmail.com
Wed Aug 5 11:44:01 PDT 2015


Author: arphaman
Date: Wed Aug  5 13:44:00 2015
New Revision: 244093

URL: http://llvm.org/viewvc/llvm-project?rev=244093&view=rev
Log:
MIR Parser: Extract the IR constant parsing code into a new method. NFC.

This commit extracts the code that parses the IR constant values into a new
method named 'parseIRConstant' in the 'MIParser' class. The new method will
be reused by the code that parses the typed integer immediate machine operands.

Modified:
    llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp

Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=244093&r1=244092&r2=244093&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Wed Aug  5 13:44:00 2015
@@ -99,6 +99,7 @@ public:
   bool parseSubRegisterIndex(unsigned &SubReg);
   bool parseRegisterOperand(MachineOperand &Dest, bool IsDef = false);
   bool parseImmediateOperand(MachineOperand &Dest);
+  bool parseIRConstant(StringRef::iterator Loc, const Constant *&C);
   bool parseFPImmediateOperand(MachineOperand &Dest);
   bool parseMBBReference(MachineBasicBlock *&MBB);
   bool parseMBBOperand(MachineOperand &Dest);
@@ -557,18 +558,24 @@ bool MIParser::parseImmediateOperand(Mac
   return false;
 }
 
-bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
-  auto Loc = Token.location();
-  lex();
-  if (Token.isNot(MIToken::FloatingPointLiteral))
-    return error("expected a floating point literal");
+bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) {
   auto Source = StringRef(Loc, Token.stringValue().end() - Loc).str();
   lex();
   SMDiagnostic Err;
-  const Constant *C =
-      parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent());
+  C = parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent());
   if (!C)
     return error(Loc + Err.getColumnNo(), Err.getMessage());
+  return false;
+}
+
+bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
+  auto Loc = Token.location();
+  lex();
+  if (Token.isNot(MIToken::FloatingPointLiteral))
+    return error("expected a floating point literal");
+  const Constant *C = nullptr;
+  if (parseIRConstant(Loc, C))
+    return true;
   Dest = MachineOperand::CreateFPImm(cast<ConstantFP>(C));
   return false;
 }




More information about the llvm-commits mailing list