MC: Add MCAsmParserExtension, a base class for all the target/object specific

classes which want to extend the basic asm parser.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108158 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2010-07-12 17:27:45 +00:00
parent dc4c7da5d4
commit 53131982d6
6 changed files with 97 additions and 3 deletions

View File

@ -63,7 +63,6 @@ public:
~AsmParser();
bool Run(bool NoInitialTextSection, bool NoFinalize = false);
void AddDirectiveHandler(StringRef Directive,
bool (AsmParser::*Handler)(StringRef, SMLoc)) {
@ -71,7 +70,7 @@ public:
}
public:
TargetAsmParser &getTargetParser() const { return *TargetParser; }
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
void setTargetParser(TargetAsmParser &P);
/// @name MCAsmParser Interface
/// {

View File

@ -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

View File

@ -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 @@ class MCParsedAsmOperand;
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.

View File

@ -47,6 +47,12 @@ AsmParser::AsmParser(const Target &T, SourceMgr &_SM, MCContext &_Ctx,
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");
}

View File

@ -3,5 +3,6 @@ add_llvm_library(LLVMMCParser
AsmParser.cpp
MCAsmLexer.cpp
MCAsmParser.cpp
MCAsmParserExtension.cpp
TargetAsmParser.cpp
)

View File

@ -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;
}