[llvm-commits] [llvm] r108604 - in /llvm/trunk: include/llvm/MC/MCParser/AsmParser.h include/llvm/MC/MCParser/MCAsmParser.h lib/MC/MCParser/AsmParser.cpp lib/MC/MCParser/MCAsmParser.cpp
Daniel Dunbar
daniel at zuster.org
Fri Jul 16 19:26:10 PDT 2010
Author: ddunbar
Date: Fri Jul 16 21:26:10 2010
New Revision: 108604
URL: http://llvm.org/viewvc/llvm-project?rev=108604&view=rev
Log:
MC/AsmParser: Lift Run() and TargetParser to base class.
Also, add constructor function for creating AsmParser instances.
Modified:
llvm/trunk/include/llvm/MC/MCParser/AsmParser.h
llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp
Modified: llvm/trunk/include/llvm/MC/MCParser/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/AsmParser.h?rev=108604&r1=108603&r2=108604&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/AsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/AsmParser.h Fri Jul 16 21:26:10 2010
@@ -46,7 +46,6 @@
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 @@
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:
- TargetAsmParser &getTargetParser() const { return *TargetParser; }
- void setTargetParser(TargetAsmParser &P);
-
/// @name MCAsmParser Interface
/// {
Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h?rev=108604&r1=108603&r2=108604&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h Fri Jul 16 21:26:10 2010
@@ -14,6 +14,7 @@
namespace llvm {
class AsmToken;
+class MCAsmInfo;
class MCAsmLexer;
class MCAsmParserExtension;
class MCContext;
@@ -22,6 +23,8 @@
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 @@
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 @@
/// 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 @@
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
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=108604&r1=108603&r2=108604&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Jul 16 21:26:10 2010
@@ -69,7 +69,7 @@
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 @@
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 @@
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);
+}
Modified: llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp?rev=108604&r1=108603&r2=108604&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp Fri Jul 16 21:26:10 2010
@@ -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();
}
More information about the llvm-commits
mailing list