From 5458663492078f2bf1fee1aabe1a8aaf87ff9f0e Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Sun, 31 Jan 2010 02:28:18 +0000 Subject: [PATCH] Moved InstallLexer() from the X86-specific AsmLexer to the TargetAsmLexer class so that clients can actually use the TargetAsmLexer they get from a Target. llvm-svn: 94940 --- include/llvm/Target/TargetAsmLexer.h | 10 ++++++++++ lib/Target/TargetAsmLexer.cpp | 2 +- lib/Target/X86/AsmParser/X86AsmLexer.cpp | 11 +++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/llvm/Target/TargetAsmLexer.h b/include/llvm/Target/TargetAsmLexer.h index daba1ba88b9..9fcf449a86c 100644 --- a/include/llvm/Target/TargetAsmLexer.h +++ b/include/llvm/Target/TargetAsmLexer.h @@ -38,12 +38,22 @@ protected: // Can only create subclasses. /// TheTarget - The Target that this machine was created for. const Target &TheTarget; + MCAsmLexer *Lexer; public: virtual ~TargetAsmLexer(); const Target &getTarget() const { return TheTarget; } + /// InstallLexer - Set the lexer to get tokens from lower-level lexer \arg L. + void InstallLexer(MCAsmLexer &L) { + Lexer = &L; + } + + MCAsmLexer *getLexer() { + return Lexer; + } + /// Lex - Consume the next token from the input stream and return it. const AsmToken &Lex() { return CurTok = LexToken(); diff --git a/lib/Target/TargetAsmLexer.cpp b/lib/Target/TargetAsmLexer.cpp index 0ae6c14b6bd..d4893ff2521 100644 --- a/lib/Target/TargetAsmLexer.cpp +++ b/lib/Target/TargetAsmLexer.cpp @@ -10,5 +10,5 @@ #include "llvm/Target/TargetAsmLexer.h" using namespace llvm; -TargetAsmLexer::TargetAsmLexer(const Target &T) : TheTarget(T) {} +TargetAsmLexer::TargetAsmLexer(const Target &T) : TheTarget(T), Lexer(NULL) {} TargetAsmLexer::~TargetAsmLexer() {} diff --git a/lib/Target/X86/AsmParser/X86AsmLexer.cpp b/lib/Target/X86/AsmParser/X86AsmLexer.cpp index 3998b085883..71972176c02 100644 --- a/lib/Target/X86/AsmParser/X86AsmLexer.cpp +++ b/lib/Target/X86/AsmParser/X86AsmLexer.cpp @@ -22,13 +22,12 @@ namespace { class X86AsmLexer : public TargetAsmLexer { const MCAsmInfo &AsmInfo; - MCAsmLexer *Lexer; bool tentativeIsValid; AsmToken tentativeToken; const AsmToken &lexTentative() { - tentativeToken = Lexer->Lex(); + tentativeToken = getLexer()->Lex(); tentativeIsValid = true; return tentativeToken; } @@ -39,7 +38,7 @@ class X86AsmLexer : public TargetAsmLexer { return tentativeToken; } else { - return Lexer->Lex(); + return getLexer()->Lex(); } } @@ -64,11 +63,7 @@ protected: } public: X86AsmLexer(const Target &T, const MCAsmInfo &MAI) - : TargetAsmLexer(T), AsmInfo(MAI), Lexer(NULL), tentativeIsValid(false) { - } - - void InstallLexer(MCAsmLexer &L) { - Lexer = &L; + : TargetAsmLexer(T), AsmInfo(MAI), tentativeIsValid(false) { } };