aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-mc/AsmLexer.cpp
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2009-09-04 21:45:34 +0000
committerKevin Enderby <enderby@apple.com>2009-09-04 21:45:34 +0000
commit9823ca971d5cb475401e59fde244caf5087c74a1 (patch)
tree96b87e75cf825093e41b7784be3f0042e50d587f /tools/llvm-mc/AsmLexer.cpp
parent68f195cc50a8b7722004c8f3ca3dcf624b524552 (diff)
Added the AsmToken::Hash enum constant to MCAsmLexer.h in preparation of
supporting other targets. Changed the code to pass MCAsmInfo to the parser and the lexer. Then changed the lexer to use CommentString from MCAsmInfo instead of a literal '#' character. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81046 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc/AsmLexer.cpp')
-rw-r--r--tools/llvm-mc/AsmLexer.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp
index 4dafa0eae9..f6be8864aa 100644
--- a/tools/llvm-mc/AsmLexer.cpp
+++ b/tools/llvm-mc/AsmLexer.cpp
@@ -15,12 +15,14 @@
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Config/config.h" // for strtoull.
+#include "llvm/MC/MCAsmInfo.h"
#include <cerrno>
#include <cstdio>
#include <cstdlib>
using namespace llvm;
-AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) {
+AsmLexer::AsmLexer(SourceMgr &SM, const MCAsmInfo &_MAI) : SrcMgr(SM),
+ MAI(_MAI) {
CurBuffer = 0;
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
CurPtr = CurBuf->getBufferStart();
@@ -230,12 +232,16 @@ AsmToken AsmLexer::LexQuote() {
StringRef AsmLexer::LexUntilEndOfStatement() {
TokStart = CurPtr;
- while (*CurPtr != '#' && // Start of line comment.
- *CurPtr != ';' && // End of statement marker.
+ while (*CurPtr != ';' && // End of statement marker.
*CurPtr != '\n' &&
*CurPtr != '\r' &&
- (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd()))
+ (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
+ // check for start of line comment.
+ for (const char *p = MAI.getCommentString(); *p != 0; ++p)
+ if (*CurPtr == *p)
+ break;
++CurPtr;
+ }
return StringRef(TokStart, CurPtr-TokStart);
}
@@ -244,6 +250,10 @@ AsmToken AsmLexer::LexToken() {
// This always consumes at least one character.
int CurChar = getNextChar();
+ for (const char *p = MAI.getCommentString(); *p != 0; ++p)
+ if (CurChar == *p)
+ return LexLineComment();
+
switch (CurChar) {
default:
// Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*
@@ -289,7 +299,7 @@ AsmToken AsmLexer::LexToken() {
return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
case '/': return LexSlash();
- case '#': return LexLineComment();
+ case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
case '"': return LexQuote();
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':