MIR Parser: Extract the IR constant parsing code into a new method. NFC.
authorAlex Lorenz <arphaman@gmail.com>
Wed, 5 Aug 2015 18:44:00 +0000 (18:44 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Wed, 5 Aug 2015 18:44:00 +0000 (18:44 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244093 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MIRParser/MIParser.cpp

index 0663b119e284933e71ad83220fc80a27037dd11d..5bedd3e18f3c7f45947c1c98f98ff9f69c1e439c 100644 (file)
@@ -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(MachineOperand &Dest) {
   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;
 }