diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-08-05 18:44:00 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-08-05 18:44:00 +0000 |
commit | 7eaff4c7d6fb83650802efbfbb2492fe5ea752e5 (patch) | |
tree | f5bbc525dd84f7e5470de3936559b895bad86d6a /llvm/lib/CodeGen/MIRParser | |
parent | d45c2df4abf48b7088564113c9ba4a9acf5d7d2b (diff) | |
download | bcm5719-llvm-7eaff4c7d6fb83650802efbfbb2492fe5ea752e5.tar.gz bcm5719-llvm-7eaff4c7d6fb83650802efbfbb2492fe5ea752e5.zip |
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.
llvm-svn: 244093
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 0663b119e28..5bedd3e18f3 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -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; } |