mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-06 05:29:55 +00:00
add a new DirectiveMap stringmap, which allows more efficient dispatching
to directive handlers and allows for easier extensibility. I only switched a few over for now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82926 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e4172f48cc
commit
ebb89b4186
@ -32,6 +32,18 @@ using namespace llvm;
|
|||||||
// TargetLoweringObjectFile.
|
// TargetLoweringObjectFile.
|
||||||
typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy;
|
typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy;
|
||||||
|
|
||||||
|
AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
||||||
|
const MCAsmInfo &_MAI)
|
||||||
|
: Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), TargetParser(0),
|
||||||
|
SectionUniquingMap(0) {
|
||||||
|
// Debugging directives.
|
||||||
|
AddDirectiveHandler(".file", &AsmParser::ParseDirectiveFile);
|
||||||
|
AddDirectiveHandler(".line", &AsmParser::ParseDirectiveLine);
|
||||||
|
AddDirectiveHandler(".loc", &AsmParser::ParseDirectiveLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AsmParser::~AsmParser() {
|
AsmParser::~AsmParser() {
|
||||||
// If we have the MachO uniquing map, free it.
|
// If we have the MachO uniquing map, free it.
|
||||||
delete (MachOUniqueMapTy*)SectionUniquingMap;
|
delete (MachOUniqueMapTy*)SectionUniquingMap;
|
||||||
@ -672,14 +684,10 @@ bool AsmParser::ParseStatement() {
|
|||||||
if (IDVal == ".load")
|
if (IDVal == ".load")
|
||||||
return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false);
|
return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false);
|
||||||
|
|
||||||
// Debugging directives
|
// Look up the handler in the handler table,
|
||||||
|
bool(AsmParser::*Handler)(StringRef, SMLoc) = DirectiveMap[IDVal];
|
||||||
if (IDVal == ".file")
|
if (Handler)
|
||||||
return ParseDirectiveFile(IDLoc);
|
return (this->*Handler)(IDVal, IDLoc);
|
||||||
if (IDVal == ".line")
|
|
||||||
return ParseDirectiveLine(IDLoc);
|
|
||||||
if (IDVal == ".loc")
|
|
||||||
return ParseDirectiveLoc(IDLoc);
|
|
||||||
|
|
||||||
// Target hook for parsing target specific directives.
|
// Target hook for parsing target specific directives.
|
||||||
if (!getTargetParser().ParseDirective(ID))
|
if (!getTargetParser().ParseDirective(ID))
|
||||||
@ -1587,7 +1595,7 @@ bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
|
|||||||
|
|
||||||
/// ParseDirectiveFile
|
/// ParseDirectiveFile
|
||||||
/// ::= .file [number] string
|
/// ::= .file [number] string
|
||||||
bool AsmParser::ParseDirectiveFile(SMLoc DirectiveLoc) {
|
bool AsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) {
|
||||||
// FIXME: I'm not sure what this is.
|
// FIXME: I'm not sure what this is.
|
||||||
int64_t FileNumber = -1;
|
int64_t FileNumber = -1;
|
||||||
if (Lexer.is(AsmToken::Integer)) {
|
if (Lexer.is(AsmToken::Integer)) {
|
||||||
@ -1614,7 +1622,7 @@ bool AsmParser::ParseDirectiveFile(SMLoc DirectiveLoc) {
|
|||||||
|
|
||||||
/// ParseDirectiveLine
|
/// ParseDirectiveLine
|
||||||
/// ::= .line [number]
|
/// ::= .line [number]
|
||||||
bool AsmParser::ParseDirectiveLine(SMLoc DirectiveLoc) {
|
bool AsmParser::ParseDirectiveLine(StringRef, SMLoc DirectiveLoc) {
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
if (Lexer.isNot(AsmToken::Integer))
|
if (Lexer.isNot(AsmToken::Integer))
|
||||||
return TokError("unexpected token in '.line' directive");
|
return TokError("unexpected token in '.line' directive");
|
||||||
@ -1635,7 +1643,7 @@ bool AsmParser::ParseDirectiveLine(SMLoc DirectiveLoc) {
|
|||||||
|
|
||||||
/// ParseDirectiveLoc
|
/// ParseDirectiveLoc
|
||||||
/// ::= .loc number [number [number]]
|
/// ::= .loc number [number [number]]
|
||||||
bool AsmParser::ParseDirectiveLoc(SMLoc DirectiveLoc) {
|
bool AsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) {
|
||||||
if (Lexer.isNot(AsmToken::Integer))
|
if (Lexer.isNot(AsmToken::Integer))
|
||||||
return TokError("unexpected token in '.loc' directive");
|
return TokError("unexpected token in '.loc' directive");
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "llvm/MC/MCSectionMachO.h"
|
#include "llvm/MC/MCSectionMachO.h"
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class AsmCond;
|
class AsmCond;
|
||||||
@ -47,15 +48,23 @@ private:
|
|||||||
// is also used by TargetLoweringObjectFile.
|
// is also used by TargetLoweringObjectFile.
|
||||||
mutable void *SectionUniquingMap;
|
mutable void *SectionUniquingMap;
|
||||||
|
|
||||||
|
/// DirectiveMap - This is a table handlers for directives. Each handler is
|
||||||
|
/// invoked after the directive identifier is read and is responsible for
|
||||||
|
/// parsing and validating the rest of the directive. The handler is passed
|
||||||
|
/// in the directive name and the location of the directive keyword.
|
||||||
|
StringMap<bool(AsmParser::*)(StringRef, SMLoc)> DirectiveMap;
|
||||||
public:
|
public:
|
||||||
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
||||||
const MCAsmInfo &_MAI)
|
const MCAsmInfo &_MAI);
|
||||||
: Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), TargetParser(0),
|
|
||||||
SectionUniquingMap(0) {}
|
|
||||||
~AsmParser();
|
~AsmParser();
|
||||||
|
|
||||||
bool Run();
|
bool Run();
|
||||||
|
|
||||||
|
|
||||||
|
void AddDirectiveHandler(StringRef Directive,
|
||||||
|
bool (AsmParser::*Handler)(StringRef, SMLoc)) {
|
||||||
|
DirectiveMap[Directive] = Handler;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
||||||
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
|
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
|
||||||
@ -64,19 +73,14 @@ public:
|
|||||||
/// {
|
/// {
|
||||||
|
|
||||||
virtual MCAsmLexer &getLexer() { return Lexer; }
|
virtual MCAsmLexer &getLexer() { return Lexer; }
|
||||||
|
|
||||||
virtual MCContext &getContext() { return Ctx; }
|
virtual MCContext &getContext() { return Ctx; }
|
||||||
|
|
||||||
virtual MCStreamer &getStreamer() { return Out; }
|
virtual MCStreamer &getStreamer() { return Out; }
|
||||||
|
|
||||||
virtual void Warning(SMLoc L, const Twine &Meg);
|
virtual void Warning(SMLoc L, const Twine &Meg);
|
||||||
|
|
||||||
virtual bool Error(SMLoc L, const Twine &Msg);
|
virtual bool Error(SMLoc L, const Twine &Msg);
|
||||||
|
|
||||||
virtual bool ParseExpression(const MCExpr *&Res);
|
virtual bool ParseExpression(const MCExpr *&Res);
|
||||||
|
|
||||||
virtual bool ParseParenExpression(const MCExpr *&Res);
|
virtual bool ParseParenExpression(const MCExpr *&Res);
|
||||||
|
|
||||||
virtual bool ParseAbsoluteExpression(int64_t &Res);
|
virtual bool ParseAbsoluteExpression(int64_t &Res);
|
||||||
|
|
||||||
/// }
|
/// }
|
||||||
@ -145,9 +149,9 @@ private:
|
|||||||
bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
|
bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
|
||||||
bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
|
bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
|
||||||
|
|
||||||
bool ParseDirectiveFile(SMLoc DirectiveLoc); // ".file"
|
bool ParseDirectiveFile(StringRef, SMLoc DirectiveLoc); // ".file"
|
||||||
bool ParseDirectiveLine(SMLoc DirectiveLoc); // ".line"
|
bool ParseDirectiveLine(StringRef, SMLoc DirectiveLoc); // ".line"
|
||||||
bool ParseDirectiveLoc(SMLoc DirectiveLoc); // ".loc"
|
bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc); // ".loc"
|
||||||
|
|
||||||
/// ParseEscapedString - Parse the current token as a string which may include
|
/// ParseEscapedString - Parse the current token as a string which may include
|
||||||
/// escaped characters and return the string contents.
|
/// escaped characters and return the string contents.
|
||||||
|
Loading…
Reference in New Issue
Block a user