summaryrefslogtreecommitdiffstats
path: root/llvm/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
commitf92f9909c4e5943cc115b9662fb5540a2eb59984 (patch)
tree5b851cb38e1660ae42dd09d01c15910838c6de57 /llvm/tools/llvm-mc/AsmLexer.cpp
parenta33c5a922d76248d11fb4a5567561095664986de (diff)
downloadbcm5719-llvm-f92f9909c4e5943cc115b9662fb5540a2eb59984.tar.gz
bcm5719-llvm-f92f9909c4e5943cc115b9662fb5540a2eb59984.zip
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. llvm-svn: 81046
Diffstat (limited to 'llvm/tools/llvm-mc/AsmLexer.cpp')
-rw-r--r--llvm/tools/llvm-mc/AsmLexer.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/llvm/tools/llvm-mc/AsmLexer.cpp b/llvm/tools/llvm-mc/AsmLexer.cpp
index 4dafa0eae94..f6be8864aa1 100644
--- a/llvm/tools/llvm-mc/AsmLexer.cpp
+++ b/llvm/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':
OpenPOWER on IntegriCloud