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::Run() {
23 while (Lexer.isNot(asmtok::Eof))
32 /// ::= EndOfStatement
33 /// ::= Label* Identifier Operands* EndOfStatement
34 bool AsmParser::ParseStatement() {
35 switch (Lexer.getKind()) {
37 Lexer.PrintError(Lexer.getLoc(), "unexpected token at start of statement");
39 case asmtok::EndOfStatement:
42 case asmtok::Identifier:
44 // TODO: Recurse on local labels etc.
47 // If we have an identifier, handle it as the key symbol.
48 //SMLoc IDLoc = Lexer.getLoc();
49 std::string IDVal = Lexer.getCurStrVal();
51 // Consume the identifier, see what is after it.
52 if (Lexer.Lex() == asmtok::Colon) {
53 // identifier ':' -> Label.
55 return ParseStatement();
58 // Otherwise, we have a normal instruction or directive.
60 outs() << "Found directive: " << IDVal << "\n";
62 outs() << "Found instruction: " << IDVal << "\n";
64 // Skip to end of line for now.
65 while (Lexer.isNot(asmtok::EndOfStatement) &&
66 Lexer.isNot(asmtok::Eof))
70 if (Lexer.is(asmtok::EndOfStatement))