summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mc/AsmParser.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-21 20:54:55 +0000
committerChris Lattner <sabre@nondot.org>2009-06-21 20:54:55 +0000
commit36e0212c163c931f11970192788f8b24d2489daa (patch)
tree023cf00478b41cb8c9d734fb3b1470e1df1728f8 /llvm/tools/llvm-mc/AsmParser.cpp
parentb01334533857e4dce90c1d531510ab0d2d31dd9b (diff)
downloadbcm5719-llvm-36e0212c163c931f11970192788f8b24d2489daa.tar.gz
bcm5719-llvm-36e0212c163c931f11970192788f8b24d2489daa.zip
set up the top-level parsing loop.
llvm-svn: 73860
Diffstat (limited to 'llvm/tools/llvm-mc/AsmParser.cpp')
-rw-r--r--llvm/tools/llvm-mc/AsmParser.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/llvm/tools/llvm-mc/AsmParser.cpp b/llvm/tools/llvm-mc/AsmParser.cpp
index abb0d35b086..9c0b4abb076 100644
--- a/llvm/tools/llvm-mc/AsmParser.cpp
+++ b/llvm/tools/llvm-mc/AsmParser.cpp
@@ -12,8 +12,62 @@
//===----------------------------------------------------------------------===//
#include "AsmParser.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
bool AsmParser::Run() {
+ // Prime the lexer.
+ Lexer.Lex();
+
+ while (Lexer.isNot(asmtok::Eof))
+ if (ParseStatement())
+ return true;
+
+ return false;
+}
+
+
+/// ParseStatement:
+/// ::= EndOfStatement
+/// ::= Label* Identifier Operands* EndOfStatement
+bool AsmParser::ParseStatement() {
+ switch (Lexer.getKind()) {
+ default:
+ Lexer.PrintError(Lexer.getLoc(), "unexpected token at start of statement");
+ return true;
+ case asmtok::EndOfStatement:
+ Lexer.Lex();
+ return false;
+ case asmtok::Identifier:
+ break;
+ // TODO: Recurse on local labels etc.
+ }
+
+ // If we have an identifier, handle it as the key symbol.
+ //SMLoc IDLoc = Lexer.getLoc();
+ std::string IDVal = Lexer.getCurStrVal();
+
+ // Consume the identifier, see what is after it.
+ if (Lexer.Lex() == asmtok::Colon) {
+ // identifier ':' -> Label.
+ Lexer.Lex();
+ return ParseStatement();
+ }
+
+ // Otherwise, we have a normal instruction or directive.
+ if (IDVal[0] == '.')
+ outs() << "Found directive: " << IDVal << "\n";
+ else
+ outs() << "Found instruction: " << IDVal << "\n";
+
+ // Skip to end of line for now.
+ while (Lexer.isNot(asmtok::EndOfStatement) &&
+ Lexer.isNot(asmtok::Eof))
+ Lexer.Lex();
+
+ // Eat EOL.
+ if (Lexer.is(asmtok::EndOfStatement))
+ Lexer.Lex();
return false;
}
OpenPOWER on IntegriCloud