[llvm] [LLVM][IR] Add location tracking to LLVM IR parser (PR #155797)
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 29 09:36:36 PDT 2025
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,Bertik23
<39457484+Bertik23 at users.noreply.github.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/155797 at github.com>
================
@@ -174,27 +165,75 @@ LLLexer::LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &Err,
CurPtr = CurBuf.begin();
}
+const char *LLLexer::getLabelTail(const char *Ptr) {
+ while (Ptr != CurBuf.end()) {
+ if (Ptr[0] == ':')
+ return Ptr + 1;
+ if (!isLabelChar(Ptr[0]))
+ return nullptr;
+ ++Ptr;
+ }
+ return nullptr;
+}
+
int LLLexer::getNextChar() {
- char CurChar = *CurPtr++;
- switch (CurChar) {
- default: return (unsigned char)CurChar;
- case 0:
- // A nul character in the stream is either the end of the current buffer or
- // a random nul in the file. Disambiguate that here.
- if (CurPtr-1 != CurBuf.end())
- return 0; // Just whitespace.
-
- // Otherwise, return end of file.
- --CurPtr; // Another call to lex will return EOF again.
+ if (CurPtr == CurBuf.end())
return EOF;
+ // Increment line number if this is the first character after a newline
+ if (CurPtr > CurBuf.begin() && *(CurPtr - 1) == '\n') {
----------------
mshockwave wrote:
Follow up to one of my previous comments: is it possible to re-use SourceMgr, either partially or fully, to get the line and column numbers? Parsing line and column numbers is not a trivial job as you may have noticed, and I really hope we don't need to reinvent the wheels.
https://github.com/llvm/llvm-project/pull/155797
More information about the llvm-commits
mailing list