aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-mc/AsmParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-mc/AsmParser.cpp')
-rw-r--r--tools/llvm-mc/AsmParser.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp
index abb0d35b08..9c0b4abb07 100644
--- a/tools/llvm-mc/AsmParser.cpp
+++ b/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;
}