summaryrefslogtreecommitdiffstats
path: root/llvm/lib/AsmParser/Parser.cpp
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2016-03-08 00:37:07 +0000
committerQuentin Colombet <qcolombet@apple.com>2016-03-08 00:37:07 +0000
commitdafed5d7d82613ca153c1bee70addb17d6d20c3a (patch)
tree55eff0c029daa02615e5e18769ebe0bcf26f990c /llvm/lib/AsmParser/Parser.cpp
parentb1bd398ceb5bead0251ec0f40ba5db0177e4a2df (diff)
downloadbcm5719-llvm-dafed5d7d82613ca153c1bee70addb17d6d20c3a.tar.gz
bcm5719-llvm-dafed5d7d82613ca153c1bee70addb17d6d20c3a.zip
[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
Diffstat (limited to 'llvm/lib/AsmParser/Parser.cpp')
-rw-r--r--llvm/lib/AsmParser/Parser.cpp19
1 files changed, 18 insertions, 1 deletions
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<MemoryBuffer> 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<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
Type *Ty;
if (LLParser(Asm, SM, Err, const_cast<Module *>(&M))
- .parseStandaloneType(Ty, Slots))
+ .parseTypeAtBeginning(Ty, Read, Slots))
return nullptr;
return Ty;
}
OpenPOWER on IntegriCloud