From dafed5d7d82613ca153c1bee70addb17d6d20c3a Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Tue, 8 Mar 2016 00:37:07 +0000 Subject: [AsmParser] Expose an API to parse a string starting with a type. Without actually parsing a type it is difficult to perdict where the type definition ends. In other words, instead of expecting the user of the parser API to hand over only the relevant bits of the string being parsed, take the whole string, parse the type, and get back the number of characters that have been read. This will be used by the MIR testing infrastructure. llvm-svn: 262884 --- llvm/lib/AsmParser/Parser.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'llvm/lib/AsmParser/Parser.cpp') diff --git a/llvm/lib/AsmParser/Parser.cpp b/llvm/lib/AsmParser/Parser.cpp index 9b635982477..bee07ad9e0a 100644 --- a/llvm/lib/AsmParser/Parser.cpp +++ b/llvm/lib/AsmParser/Parser.cpp @@ -81,12 +81,29 @@ Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err, Type *llvm::parseType(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots) { + unsigned Read; + Type *Ty = parseTypeAtBeginning(Asm, Read, Err, M, Slots); + if (!Ty) + return nullptr; + if (Read != Asm.size()) { + SourceMgr SM; + std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Asm); + SM.AddNewSourceBuffer(std::move(Buf), SMLoc()); + Err = SM.GetMessage(SMLoc::getFromPointer(Asm.begin() + Read), + SourceMgr::DK_Error, "expected end of string"); + return nullptr; + } + return Ty; +} +Type *llvm::parseTypeAtBeginning(StringRef Asm, unsigned &Read, + SMDiagnostic &Err, const Module &M, + const SlotMapping *Slots) { SourceMgr SM; std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Asm); SM.AddNewSourceBuffer(std::move(Buf), SMLoc()); Type *Ty; if (LLParser(Asm, SM, Err, const_cast(&M)) - .parseStandaloneType(Ty, Slots)) + .parseTypeAtBeginning(Ty, Read, Slots)) return nullptr; return Ty; } -- cgit v1.2.3