[llvm-commits] [llvm] r108158 - in /llvm/trunk: include/llvm/MC/MCParser/AsmParser.h include/llvm/MC/MCParser/MCAsmParserExtension.h include/llvm/Target/TargetAsmParser.h lib/MC/MCParser/AsmParser.cpp lib/MC/MCParser/CMakeLists.txt lib/MC/MCParser/MCAsmParserExtension.cpp
Daniel Dunbar
daniel at zuster.org
Mon Jul 12 10:27:45 PDT 2010
Author: ddunbar
Date: Mon Jul 12 12:27:45 2010
New Revision: 108158
URL: http://llvm.org/viewvc/llvm-project?rev=108158&view=rev
Log:
MC: Add MCAsmParserExtension, a base class for all the target/object specific
classes which want to extend the basic asm parser.
Added:
llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h
llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp
Modified:
llvm/trunk/include/llvm/MC/MCParser/AsmParser.h
llvm/trunk/include/llvm/Target/TargetAsmParser.h
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/lib/MC/MCParser/CMakeLists.txt
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=108158&r1=108157&r2=108158&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/AsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/AsmParser.h Mon Jul 12 12:27:45 2010
@@ -63,7 +63,6 @@
~AsmParser();
bool Run(bool NoInitialTextSection, bool NoFinalize = false);
-
void AddDirectiveHandler(StringRef Directive,
bool (AsmParser::*Handler)(StringRef, SMLoc)) {
@@ -71,7 +70,7 @@
}
public:
TargetAsmParser &getTargetParser() const { return *TargetParser; }
- void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
+ void setTargetParser(TargetAsmParser &P);
/// @name MCAsmParser Interface
/// {
Added: llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h?rev=108158&view=auto
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h (added)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h Mon Jul 12 12:27:45 2010
@@ -0,0 +1,65 @@
+//===-- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks -------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MC_MCASMPARSEREXTENSION_H
+#define LLVM_MC_MCASMPARSEREXTENSION_H
+
+#include "llvm/MC/MCParser/MCAsmParser.h"
+#include "llvm/Support/SMLoc.h"
+
+namespace llvm {
+
+/// \brief Generic interface for extending the MCAsmParser,
+/// which is implemented by target and object file assembly parser
+/// implementations.
+class MCAsmParserExtension {
+ MCAsmParserExtension(const MCAsmParserExtension &); // DO NOT IMPLEMENT
+ void operator=(const MCAsmParserExtension &); // DO NOT IMPLEMENT
+
+ MCAsmParser *Parser;
+
+protected:
+ MCAsmParserExtension();
+
+public:
+ virtual ~MCAsmParserExtension();
+
+ /// \brief Initialize the extension for parsing using the given \arg
+ /// Parser. The extension should use the AsmParser interfaces to register its
+ /// parsing routines.
+ virtual void Initialize(MCAsmParser &Parser);
+
+ /// @name MCAsmParser Proxy Interfaces
+ /// @{
+
+ MCContext &getContext() { return getParser().getContext(); }
+ MCAsmLexer &getLexer() { return getParser().getLexer(); }
+ MCAsmParser &getParser() { return *Parser; }
+ MCStreamer &getStreamer() { return getParser().getStreamer(); }
+ void Warning(SMLoc L, const Twine &Msg) {
+ return getParser().Warning(L, Msg);
+ }
+ bool Error(SMLoc L, const Twine &Msg) {
+ return getParser().Error(L, Msg);
+ }
+
+ const AsmToken &Lex() { return getParser().Lex(); }
+
+ const AsmToken &getTok() { return getParser().getTok(); }
+
+ bool TokError(const char *Msg) {
+ return getParser().TokError(Msg);
+ }
+
+ /// @}
+};
+
+} // End llvm namespace
+
+#endif
Modified: llvm/trunk/include/llvm/Target/TargetAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmParser.h?rev=108158&r1=108157&r2=108158&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmParser.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmParser.h Mon Jul 12 12:27:45 2010
@@ -10,6 +10,8 @@
#ifndef LLVM_TARGET_TARGETPARSER_H
#define LLVM_TARGET_TARGETPARSER_H
+#include "llvm/MC/MCParser/MCAsmParserExtension.h"
+
namespace llvm {
class MCInst;
class StringRef;
@@ -20,7 +22,7 @@
template <typename T> class SmallVectorImpl;
/// TargetAsmParser - Generic interface to target specific assembly parsers.
-class TargetAsmParser {
+class TargetAsmParser : public MCAsmParserExtension {
TargetAsmParser(const TargetAsmParser &); // DO NOT IMPLEMENT
void operator=(const TargetAsmParser &); // DO NOT IMPLEMENT
protected: // Can only create subclasses.
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=108158&r1=108157&r2=108158&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Mon Jul 12 12:27:45 2010
@@ -47,6 +47,12 @@
AsmParser::~AsmParser() {
}
+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");
}
Modified: llvm/trunk/lib/MC/MCParser/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/CMakeLists.txt?rev=108158&r1=108157&r2=108158&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/CMakeLists.txt (original)
+++ llvm/trunk/lib/MC/MCParser/CMakeLists.txt Mon Jul 12 12:27:45 2010
@@ -3,5 +3,6 @@
AsmParser.cpp
MCAsmLexer.cpp
MCAsmParser.cpp
+ MCAsmParserExtension.cpp
TargetAsmParser.cpp
)
Added: llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp?rev=108158&view=auto
==============================================================================
--- llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp (added)
+++ llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp Mon Jul 12 12:27:45 2010
@@ -0,0 +1,21 @@
+//===-- MCAsmParserExtension.cpp - Asm Parser Hooks -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/MC/MCParser/MCAsmParserExtension.h"
+using namespace llvm;
+
+MCAsmParserExtension::MCAsmParserExtension() {
+}
+
+MCAsmParserExtension::~MCAsmParserExtension() {
+}
+
+void MCAsmParserExtension::Initialize(MCAsmParser &Parser) {
+ this->Parser = &Parser;
+}
More information about the llvm-commits
mailing list