[llvm-commits] [llvm] r73860 - in /llvm/trunk/tools/llvm-mc: AsmLexer.h AsmParser.cpp AsmParser.h
Chris Lattner
sabre at nondot.org
Sun Jun 21 13:54:55 PDT 2009
Author: lattner
Date: Sun Jun 21 15:54:55 2009
New Revision: 73860
URL: http://llvm.org/viewvc/llvm-project?rev=73860&view=rev
Log:
set up the top-level parsing loop.
Modified:
llvm/trunk/tools/llvm-mc/AsmLexer.h
llvm/trunk/tools/llvm-mc/AsmParser.cpp
llvm/trunk/tools/llvm-mc/AsmParser.h
Modified: llvm/trunk/tools/llvm-mc/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=73860&r1=73859&r2=73860&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.h Sun Jun 21 15:54:55 2009
@@ -73,6 +73,8 @@
}
asmtok::TokKind getKind() const { return CurKind; }
+ bool is(asmtok::TokKind K) const { return CurKind == K; }
+ bool isNot(asmtok::TokKind K) const { return CurKind != K; }
const std::string &getCurStrVal() const {
assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=73860&r1=73859&r2=73860&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Sun Jun 21 15:54:55 2009
@@ -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;
}
Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=73860&r1=73859&r2=73860&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Sun Jun 21 15:54:55 2009
@@ -27,6 +27,9 @@
bool Run();
+private:
+ bool ParseStatement();
+
};
} // end namespace llvm
More information about the llvm-commits
mailing list