From 3fb77686c1d63cb3ef0322bed341c67e10d1d88b Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 6 Aug 2015 23:17:42 +0000 Subject: MIR Parser: Simplify the token's string value handling. This commit removes the 'StringOffset' and 'HasStringValue' fields from the MIToken struct and simplifies the 'stringValue' method which now returns the new 'StringValue' field. This commit also adopts a different way of initializing the lexed tokens - instead of constructing a new MIToken instance, the lexer resets the old token using the new 'reset' method and sets its attributes using the new 'setStringValue', 'setOwnedStringValue', and 'setIntegerValue' methods. Reviewers: Sean Silva Differential Revision: http://reviews.llvm.org/D11792 llvm-svn: 244295 --- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (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 f8a6200cc67..e577458f8fc 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -200,7 +200,7 @@ MIParser::MIParser(SourceMgr &SM, MachineFunction &MF, SMDiagnostic &Error, StringRef Source, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots) : SM(SM), MF(MF), Error(Error), Source(Source), CurrentSource(Source), - Token(MIToken::Error, StringRef()), PFS(PFS), IRSlots(IRSlots) {} + PFS(PFS), IRSlots(IRSlots) {} void MIParser::lex() { CurrentSource = lexMIToken( @@ -571,7 +571,7 @@ bool MIParser::parseImmediateOperand(MachineOperand &Dest) { } bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) { - auto Source = StringRef(Loc, Token.stringValue().end() - Loc).str(); + auto Source = StringRef(Loc, Token.range().end() - Loc).str(); lex(); SMDiagnostic Err; C = parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent()); @@ -681,8 +681,8 @@ bool MIParser::parseGlobalValue(GlobalValue *&GV) { const Module *M = MF.getFunction()->getParent(); GV = M->getNamedValue(Token.stringValue()); if (!GV) - return error(Twine("use of undefined global value '@") + - Token.rawStringValue() + "'"); + return error(Twine("use of undefined global value '") + Token.range() + + "'"); break; } case MIToken::GlobalValue: { @@ -851,8 +851,7 @@ bool MIParser::parseIRBlock(BasicBlock *&BB, const Function &F) { BB = dyn_cast_or_null( F.getValueSymbolTable().lookup(Token.stringValue())); if (!BB) - return error(Twine("use of undefined IR block '%ir-block.") + - Token.rawStringValue() + "'"); + return error(Twine("use of undefined IR block '") + Token.range() + "'"); break; } case MIToken::IRBlock: { @@ -1019,7 +1018,7 @@ bool MIParser::parseMachineOperandAndTargetFlags(MachineOperand &Dest) { bool MIParser::parseOperandsOffset(MachineOperand &Op) { if (Token.isNot(MIToken::plus) && Token.isNot(MIToken::minus)) return false; - StringRef Sign = Token.stringValue(); + StringRef Sign = Token.range(); bool IsNegative = Token.is(MIToken::minus); lex(); if (Token.isNot(MIToken::IntegerLiteral)) @@ -1039,8 +1038,7 @@ bool MIParser::parseIRValue(Value *&V) { case MIToken::NamedIRValue: { V = MF.getFunction()->getValueSymbolTable().lookup(Token.stringValue()); if (!V) - return error(Twine("use of undefined IR value '%ir.") + - Token.rawStringValue() + "'"); + return error(Twine("use of undefined IR value '") + Token.range() + "'"); break; } // TODO: Parse unnamed IR value references. -- cgit v1.2.3