forked from OSchip/llvm-project
MC/AsmParser: Lift Run() and TargetParser to base class.
Also, add constructor function for creating AsmParser instances. llvm-svn: 108604
This commit is contained in:
parent
6e3b5fa91c
commit
01e3607d70
|
@ -46,7 +46,6 @@ private:
|
|||
SourceMgr &SrcMgr;
|
||||
MCAsmParserExtension *GenericParser;
|
||||
MCAsmParserExtension *PlatformParser;
|
||||
TargetAsmParser *TargetParser;
|
||||
|
||||
/// This is the current buffer index we're lexing from as managed by the
|
||||
/// SourceMgr object.
|
||||
|
@ -65,7 +64,7 @@ public:
|
|||
const MCAsmInfo &MAI);
|
||||
~AsmParser();
|
||||
|
||||
bool Run(bool NoInitialTextSection, bool NoFinalize = false);
|
||||
virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false);
|
||||
|
||||
void AddDirectiveHandler(MCAsmParserExtension *Object,
|
||||
StringRef Directive,
|
||||
|
@ -74,9 +73,6 @@ public:
|
|||
}
|
||||
|
||||
public:
|
||||
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
||||
void setTargetParser(TargetAsmParser &P);
|
||||
|
||||
/// @name MCAsmParser Interface
|
||||
/// {
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
namespace llvm {
|
||||
class AsmToken;
|
||||
class MCAsmInfo;
|
||||
class MCAsmLexer;
|
||||
class MCAsmParserExtension;
|
||||
class MCContext;
|
||||
|
@ -22,6 +23,8 @@ class MCStreamer;
|
|||
class SMLoc;
|
||||
class SourceMgr;
|
||||
class StringRef;
|
||||
class Target;
|
||||
class TargetAsmParser;
|
||||
class Twine;
|
||||
|
||||
/// MCAsmParser - Generic assembler parser interface, for use by target specific
|
||||
|
@ -33,6 +36,9 @@ public:
|
|||
private:
|
||||
MCAsmParser(const MCAsmParser &); // DO NOT IMPLEMENT
|
||||
void operator=(const MCAsmParser &); // DO NOT IMPLEMENT
|
||||
|
||||
TargetAsmParser *TargetParser;
|
||||
|
||||
protected: // Can only create subclasses.
|
||||
MCAsmParser();
|
||||
|
||||
|
@ -52,6 +58,12 @@ public:
|
|||
/// getStreamer - Return the output streamer for the assembler.
|
||||
virtual MCStreamer &getStreamer() = 0;
|
||||
|
||||
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
||||
void setTargetParser(TargetAsmParser &P);
|
||||
|
||||
/// Run - Run the parser on the input source buffer.
|
||||
virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
|
||||
|
||||
/// Warning - Emit a warning at the location \arg L, with the message \arg
|
||||
/// Msg.
|
||||
virtual void Warning(SMLoc L, const Twine &Msg) = 0;
|
||||
|
@ -102,6 +114,10 @@ public:
|
|||
virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
|
||||
};
|
||||
|
||||
/// \brief Create an MCAsmParser instance.
|
||||
MCAsmParser *createMCAsmParser(const Target &, SourceMgr &, MCContext &,
|
||||
MCStreamer &, const MCAsmInfo &);
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
||||
|
|
|
@ -69,7 +69,7 @@ AsmParser::AsmParser(const Target &T, SourceMgr &_SM, MCContext &_Ctx,
|
|||
MCStreamer &_Out, const MCAsmInfo &_MAI)
|
||||
: Lexer(_MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM),
|
||||
GenericParser(new GenericAsmParser), PlatformParser(0),
|
||||
TargetParser(0), CurBuffer(0) {
|
||||
CurBuffer(0) {
|
||||
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
|
||||
|
||||
// Initialize the generic parser.
|
||||
|
@ -93,12 +93,6 @@ AsmParser::~AsmParser() {
|
|||
delete GenericParser;
|
||||
}
|
||||
|
||||
void AsmParser::setTargetParser(TargetAsmParser &P) {
|
||||
assert(!TargetParser && "Target parser is already initialized!");
|
||||
TargetParser = &P;
|
||||
TargetParser->Initialize(*this);
|
||||
}
|
||||
|
||||
void AsmParser::Warning(SMLoc L, const Twine &Msg) {
|
||||
PrintMessage(L, Msg.str(), "warning");
|
||||
}
|
||||
|
@ -1487,3 +1481,10 @@ bool GenericAsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// \brief Create an MCAsmParser instance.
|
||||
MCAsmParser *llvm::createMCAsmParser(const Target &T, SourceMgr &SM,
|
||||
MCContext &C, MCStreamer &Out,
|
||||
const MCAsmInfo &MAI) {
|
||||
return new AsmParser(T, SM, C, Out, MAI);
|
||||
}
|
||||
|
|
|
@ -12,14 +12,21 @@
|
|||
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
||||
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Target/TargetAsmParser.h"
|
||||
using namespace llvm;
|
||||
|
||||
MCAsmParser::MCAsmParser() {
|
||||
MCAsmParser::MCAsmParser() : TargetParser(0) {
|
||||
}
|
||||
|
||||
MCAsmParser::~MCAsmParser() {
|
||||
}
|
||||
|
||||
void MCAsmParser::setTargetParser(TargetAsmParser &P) {
|
||||
assert(!TargetParser && "Target parser is already initialized!");
|
||||
TargetParser = &P;
|
||||
TargetParser->Initialize(*this);
|
||||
}
|
||||
|
||||
const AsmToken &MCAsmParser::getTok() {
|
||||
return getLexer().getTok();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue