#include "llvm/ADT/StringRef.h"
#include "llvm/System/DataTypes.h"
+#include "llvm/Support/SMLoc.h"
namespace llvm {
class MCAsmLexer;
class MCInst;
-class SMLoc;
class Target;
/// AsmToken - Target independent representation for an assembler token.
class MCAsmLexer {
/// The current token, stored in the base class for faster access.
AsmToken CurTok;
+
+ /// The location and description of the current error
+ SMLoc ErrLoc;
+ std::string Err;
MCAsmLexer(const MCAsmLexer &); // DO NOT IMPLEMENT
void operator=(const MCAsmLexer &); // DO NOT IMPLEMENT
MCAsmLexer();
virtual AsmToken LexToken() = 0;
-
+
+ void SetError(const SMLoc &errLoc, const std::string &err) {
+ ErrLoc = errLoc;
+ Err = err;
+ }
+
public:
virtual ~MCAsmLexer();
const AsmToken &getTok() {
return CurTok;
}
+
+ /// getErrLoc - Get the current error location
+ const SMLoc &getErrLoc() {
+ return ErrLoc;
+ }
+
+ /// getErr - Get the current error string
+ const std::string &getErr() {
+ return Err;
+ }
/// getKind - Get the kind of current token.
AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
/// ReturnError - Set the error to the specified string at the specified
/// location. This is defined to always return AsmToken::Error.
AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
- PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
+ SetError(SMLoc::getFromPointer(Loc), Msg);
+
return AsmToken(AsmToken::Error, StringRef(Loc, 0));
}
}
const AsmToken &AsmParser::Lex() {
- return Lexer.Lex();
+ const AsmToken &tok = Lexer.Lex();
+
+ if (tok.is(AsmToken::Error))
+ Lexer.PrintMessage(Lexer.getErrLoc(), Lexer.getErr(), "error");
+
+ return tok;
}
bool AsmParser::Run() {