summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mc/AsmLexer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-21 07:19:10 +0000
committerChris Lattner <sabre@nondot.org>2009-06-21 07:19:10 +0000
commitc8dfbcbb311874ac851a8daa30f7e3e71669eb5c (patch)
tree44051031ddfeac1556336bf23f0bab51478f5346 /llvm/tools/llvm-mc/AsmLexer.cpp
parent7153bd8a2934b9f6e69c4f44f65770ad4c771eaa (diff)
downloadbcm5719-llvm-c8dfbcbb311874ac851a8daa30f7e3e71669eb5c.tar.gz
bcm5719-llvm-c8dfbcbb311874ac851a8daa30f7e3e71669eb5c.zip
some baby steps.
llvm-svn: 73848
Diffstat (limited to 'llvm/tools/llvm-mc/AsmLexer.cpp')
-rw-r--r--llvm/tools/llvm-mc/AsmLexer.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/llvm/tools/llvm-mc/AsmLexer.cpp b/llvm/tools/llvm-mc/AsmLexer.cpp
new file mode 100644
index 00000000000..da86465d7fe
--- /dev/null
+++ b/llvm/tools/llvm-mc/AsmLexer.cpp
@@ -0,0 +1,87 @@
+//===- AsmLexer.cpp - Lexer for Assembly Files ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This class implements the lexer for assembly files.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AsmLexer.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/MemoryBuffer.h"
+using namespace llvm;
+
+AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) {
+ CurBuffer = 0;
+ CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
+ CurPtr = CurBuf->getBufferStart();
+ TokStart = 0;
+}
+
+void AsmLexer::PrintError(const char *Loc, const std::string &Msg) const {
+ SrcMgr.PrintError(SMLoc::getFromPointer(Loc), Msg);
+}
+
+void AsmLexer::PrintError(SMLoc Loc, const std::string &Msg) const {
+ SrcMgr.PrintError(Loc, Msg);
+}
+
+int AsmLexer::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->getBufferEnd())
+ return 0; // Just whitespace.
+
+ // If this is the end of an included file, pop the parent file off the
+ // include stack.
+ SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer);
+ if (ParentIncludeLoc != SMLoc()) {
+ CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc);
+ CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
+ CurPtr = ParentIncludeLoc.getPointer();
+ return getNextChar();
+ }
+
+ // Otherwise, return end of file.
+ --CurPtr; // Another call to lex will return EOF again.
+ return EOF;
+ }
+ }
+}
+
+asmtok::TokKind AsmLexer::LexToken() {
+ TokStart = CurPtr;
+ // This always consumes at least one character.
+ int CurChar = getNextChar();
+
+ switch (CurChar) {
+ default:
+ // Handle letters: [a-zA-Z_]
+// if (isalpha(CurChar) || CurChar == '_' || CurChar == '#')
+// return LexIdentifier();
+
+ // Unknown character, emit an error.
+ return asmtok::Error;
+ case EOF: return asmtok::Eof;
+ case 0:
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ // Ignore whitespace.
+ return LexToken();
+ case ':': return asmtok::Colon;
+ case '+': return asmtok::Plus;
+ case '-': return asmtok::Minus;
+ }
+} \ No newline at end of file
OpenPOWER on IntegriCloud