From ad156fb6af9f58c35357405b0ecd83a60185ed84 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 31 Jul 2015 20:49:21 +0000 Subject: MIR Serialization: Serialize the floating point immediate machine operands. Reviewers: Duncan P. N. Exon Smith llvm-svn: 243780 --- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'llvm/lib/CodeGen/MIRParser/MIParser.cpp') diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index c71eeb99fca..da2a01366fd 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -14,6 +14,7 @@ #include "MIParser.h" #include "MILexer.h" #include "llvm/ADT/StringMap.h" +#include "llvm/AsmParser/Parser.h" #include "llvm/AsmParser/SlotMapping.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" @@ -113,6 +114,7 @@ public: bool parseSubRegisterIndex(unsigned &SubReg); bool parseRegisterOperand(MachineOperand &Dest, bool IsDef = false); bool parseImmediateOperand(MachineOperand &Dest); + bool parseFPImmediateOperand(MachineOperand &Dest); bool parseMBBReference(MachineBasicBlock *&MBB); bool parseMBBOperand(MachineOperand &Dest); bool parseStackObjectOperand(MachineOperand &Dest); @@ -528,6 +530,22 @@ 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"); + auto Source = StringRef(Loc, Token.stringValue().end() - Loc).str(); + lex(); + SMDiagnostic Err; + const Constant *C = + parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent()); + if (!C) + return error(Loc + Err.getColumnNo(), Err.getMessage()); + Dest = MachineOperand::CreateFPImm(cast(C)); + return false; +} + bool MIParser::getUnsigned(unsigned &Result) { assert(Token.hasIntegerValue() && "Expected a token with an integer value"); const uint64_t Limit = uint64_t(std::numeric_limits::max()) + 1; @@ -860,6 +878,13 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) { return parseRegisterOperand(Dest); case MIToken::IntegerLiteral: return parseImmediateOperand(Dest); + case MIToken::kw_half: + case MIToken::kw_float: + case MIToken::kw_double: + case MIToken::kw_x86_fp80: + case MIToken::kw_fp128: + case MIToken::kw_ppc_fp128: + return parseFPImmediateOperand(Dest); case MIToken::MachineBasicBlock: return parseMBBOperand(Dest); case MIToken::StackObject: -- cgit v1.2.3