diff options
| author | Mahesh Ravishankar <ravishankarm@google.com> | 2019-09-23 12:52:28 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-09-23 12:53:06 -0700 |
| commit | 98d1d3fc437f5d2b9b3dc99ab79ee734c8127072 (patch) | |
| tree | 49dd26de85b9177361d4cfb262aa59a093ef3a7d /mlir/lib/Parser | |
| parent | 5583252173682098a4dfa0fff0fc225b7e2f1034 (diff) | |
| download | bcm5719-llvm-98d1d3fc437f5d2b9b3dc99ab79ee734c8127072.tar.gz bcm5719-llvm-98d1d3fc437f5d2b9b3dc99ab79ee734c8127072.zip | |
Simplify the way spirv::StructTypes are parsed.
The existing logic to parse spirv::StructTypes is very brittle. This
change simplifies the parsing logic a lot. The simplification also
allows for memberdecorations to be separated by commas instead of
spaces (which was an artifact of the existing parsing logic). The
change also needs a modification to mlir::parseType to return the
number of chars parsed. Adding a new parseType method to do so.
Also allow specification of spirv::StructType with no members.
PiperOrigin-RevId: 270739672
Diffstat (limited to 'mlir/lib/Parser')
| -rw-r--r-- | mlir/lib/Parser/Parser.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index d298acc8bad..cb0d329e343 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -4229,7 +4229,8 @@ OwningModuleRef mlir::parseSourceString(StringRef moduleStr, return parseSourceFile(sourceMgr, context); } -Type mlir::parseType(llvm::StringRef typeStr, MLIRContext *context) { +Type mlir::parseType(llvm::StringRef typeStr, MLIRContext *context, + size_t &numRead) { SourceMgr sourceMgr; auto memBuffer = MemoryBuffer::getMemBuffer(typeStr, /*BufferName=*/"<mlir_type_buffer>", @@ -4238,18 +4239,18 @@ Type mlir::parseType(llvm::StringRef typeStr, MLIRContext *context) { SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, context); ParserState state(sourceMgr, context); Parser parser(state); + auto start = parser.getToken().getLoc(); auto ty = parser.parseType(); if (!ty) return Type(); auto end = parser.getToken().getLoc(); - auto read = end.getPointer() - start.getPointer(); - // Make sure that the parsing of type consumes the entire string - if (static_cast<size_t>(read) < typeStr.size()) { - parser.emitError("unexpected additional tokens: '") - << typeStr.substr(read) << "' after parsing type: " << ty; - return Type(); - } + numRead = static_cast<size_t>(end.getPointer() - start.getPointer()); return ty; } + +Type mlir::parseType(llvm::StringRef typeStr, MLIRContext *context) { + size_t numRead = 0; + return parseType(typeStr, context, numRead); +} |

