mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Modified MCAsmLexer to return error information upward
rather than printing it locally, reducing its dependence on SourceMgr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94041 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
73a1aa0966
commit
79036e421f
@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/System/DataTypes.h"
|
#include "llvm/System/DataTypes.h"
|
||||||
|
#include "llvm/Support/SMLoc.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCAsmLexer;
|
class MCAsmLexer;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
class SMLoc;
|
|
||||||
class Target;
|
class Target;
|
||||||
|
|
||||||
/// AsmToken - Target independent representation for an assembler token.
|
/// AsmToken - Target independent representation for an assembler token.
|
||||||
@ -103,6 +103,10 @@ public:
|
|||||||
class MCAsmLexer {
|
class MCAsmLexer {
|
||||||
/// The current token, stored in the base class for faster access.
|
/// The current token, stored in the base class for faster access.
|
||||||
AsmToken CurTok;
|
AsmToken CurTok;
|
||||||
|
|
||||||
|
/// The location and description of the current error
|
||||||
|
SMLoc ErrLoc;
|
||||||
|
std::string Err;
|
||||||
|
|
||||||
MCAsmLexer(const MCAsmLexer &); // DO NOT IMPLEMENT
|
MCAsmLexer(const MCAsmLexer &); // DO NOT IMPLEMENT
|
||||||
void operator=(const MCAsmLexer &); // DO NOT IMPLEMENT
|
void operator=(const MCAsmLexer &); // DO NOT IMPLEMENT
|
||||||
@ -110,7 +114,12 @@ protected: // Can only create subclasses.
|
|||||||
MCAsmLexer();
|
MCAsmLexer();
|
||||||
|
|
||||||
virtual AsmToken LexToken() = 0;
|
virtual AsmToken LexToken() = 0;
|
||||||
|
|
||||||
|
void SetError(const SMLoc &errLoc, const std::string &err) {
|
||||||
|
ErrLoc = errLoc;
|
||||||
|
Err = err;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~MCAsmLexer();
|
virtual ~MCAsmLexer();
|
||||||
|
|
||||||
@ -126,6 +135,16 @@ public:
|
|||||||
const AsmToken &getTok() {
|
const AsmToken &getTok() {
|
||||||
return CurTok;
|
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.
|
/// getKind - Get the kind of current token.
|
||||||
AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
|
AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
|
||||||
|
@ -44,7 +44,8 @@ void AsmLexer::PrintMessage(SMLoc Loc, const std::string &Msg,
|
|||||||
/// ReturnError - Set the error to the specified string at the specified
|
/// ReturnError - Set the error to the specified string at the specified
|
||||||
/// location. This is defined to always return AsmToken::Error.
|
/// location. This is defined to always return AsmToken::Error.
|
||||||
AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
|
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));
|
return AsmToken(AsmToken::Error, StringRef(Loc, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,12 @@ bool AsmParser::TokError(const char *Msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AsmToken &AsmParser::Lex() {
|
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() {
|
bool AsmParser::Run() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user