1 //===- AsmParser.cpp - Parser for Assembly Files --------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class implements the parser for assembly files.
12 //===----------------------------------------------------------------------===//
14 #include "AsmParser.h"
15 #include "llvm/Support/SourceMgr.h"
16 #include "llvm/Support/raw_ostream.h"
19 bool AsmParser::Error(SMLoc L, const char *Msg) {
20 Lexer.PrintMessage(L, Msg);
24 bool AsmParser::TokError(const char *Msg) {
25 Lexer.PrintMessage(Lexer.getLoc(), Msg);
30 bool AsmParser::Run() {
34 while (Lexer.isNot(asmtok::Eof))
43 /// ::= EndOfStatement
44 /// ::= Label* Identifier Operands* EndOfStatement
45 bool AsmParser::ParseStatement() {
46 switch (Lexer.getKind()) {
48 return TokError("unexpected token at start of statement");
49 case asmtok::EndOfStatement:
52 case asmtok::Identifier:
54 // TODO: Recurse on local labels etc.
57 // If we have an identifier, handle it as the key symbol.
58 //SMLoc IDLoc = Lexer.getLoc();
59 std::string IDVal = Lexer.getCurStrVal();
61 // Consume the identifier, see what is after it.
62 if (Lexer.Lex() == asmtok::Colon) {
63 // identifier ':' -> Label.
65 return ParseStatement();
68 // Otherwise, we have a normal instruction or directive.
70 outs() << "Found directive: " << IDVal << "\n";
72 outs() << "Found instruction: " << IDVal << "\n";
74 // Skip to end of line for now.
75 while (Lexer.isNot(asmtok::EndOfStatement) &&
76 Lexer.isNot(asmtok::Eof))
80 if (Lexer.is(asmtok::EndOfStatement))