aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/AsmParser/LLLexer.cpp
diff options
context:
space:
mode:
authorRahul Joshi <rjoshi@nvidia.com>2024-11-05 13:28:22 -0800
committerGitHub <noreply@github.com>2024-11-05 13:28:22 -0800
commitb8ac87f34a6f4405bf8d91339a10f188db30aa3b (patch)
treee0ec29182cdc649992b7f5a800d3d73887c744fe /llvm/lib/AsmParser/LLLexer.cpp
parent97982a8c605fac7c86d02e641a6cd7898b3ca343 (diff)
downloadllvm-b8ac87f34a6f4405bf8d91339a10f188db30aa3b.zip
llvm-b8ac87f34a6f4405bf8d91339a10f188db30aa3b.tar.gz
llvm-b8ac87f34a6f4405bf8d91339a10f188db30aa3b.tar.bz2
[LLVM][AsmParser] Add support for C style comments (#111554)
Add support for C style comments in LLVM assembly. --------- Co-authored-by: Nikita Popov <github@npopov.com>
Diffstat (limited to 'llvm/lib/AsmParser/LLLexer.cpp')
-rw-r--r--llvm/lib/AsmParser/LLLexer.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 56abd03..1b8e033 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -200,7 +200,6 @@ lltok::Kind LLLexer::LexToken() {
// Handle letters: [a-zA-Z_]
if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar == '_')
return LexIdentifier();
-
return lltok::Error;
case EOF: return lltok::Eof;
case 0:
@@ -251,6 +250,12 @@ lltok::Kind LLLexer::LexToken() {
case ',': return lltok::comma;
case '*': return lltok::star;
case '|': return lltok::bar;
+ case '/':
+ if (getNextChar() != '*')
+ return lltok::Error;
+ if (SkipCComment())
+ return lltok::Error;
+ continue;
}
}
}
@@ -262,6 +267,28 @@ void LLLexer::SkipLineComment() {
}
}
+/// This skips C-style /**/ comments. Returns true if there
+/// was an error.
+bool LLLexer::SkipCComment() {
+ while (true) {
+ int CurChar = getNextChar();
+ switch (CurChar) {
+ case EOF:
+ LexError("unterminated comment");
+ return true;
+ case '*':
+ // End of the comment?
+ CurChar = getNextChar();
+ if (CurChar == '/')
+ return false;
+ if (CurChar == EOF) {
+ LexError("unterminated comment");
+ return true;
+ }
+ }
+ }
+}
+
/// Lex all tokens that start with an @ character.
/// GlobalVar @\"[^\"]*\"
/// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*