mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Provide generic MCAsmParser when constructing target specific parsers.
llvm-svn: 77362
This commit is contained in:
parent
5aba07663b
commit
d0d6b26e87
@ -28,6 +28,7 @@
|
||||
|
||||
namespace llvm {
|
||||
class FunctionPass;
|
||||
class MCAsmParser;
|
||||
class Module;
|
||||
class TargetAsmParser;
|
||||
class TargetMachine;
|
||||
@ -51,7 +52,8 @@ namespace llvm {
|
||||
typedef FunctionPass *(*AsmPrinterCtorTy)(formatted_raw_ostream &,
|
||||
TargetMachine &,
|
||||
bool);
|
||||
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &);
|
||||
typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &,
|
||||
MCAsmParser &);
|
||||
|
||||
friend struct TargetRegistry;
|
||||
|
||||
@ -123,10 +125,13 @@ namespace llvm {
|
||||
}
|
||||
|
||||
/// createAsmParser - Create a target specific assembly parser.
|
||||
TargetAsmParser *createAsmParser() const {
|
||||
///
|
||||
/// \arg Parser - The target independent parser implementation to use for
|
||||
/// parsing and lexing.
|
||||
TargetAsmParser *createAsmParser(MCAsmParser &Parser) const {
|
||||
if (!AsmParserCtorFn)
|
||||
return 0;
|
||||
return AsmParserCtorFn(*this);
|
||||
return AsmParserCtorFn(*this, Parser);
|
||||
}
|
||||
};
|
||||
|
||||
@ -344,12 +349,13 @@ namespace llvm {
|
||||
}
|
||||
};
|
||||
|
||||
/// RegisterAsmParser - Helper template for registering a target specific asm
|
||||
/// parser, for use in the target machine initialization function. Usage:
|
||||
/// RegisterAsmParser - Helper template for registering a target specific
|
||||
/// assembly parser, for use in the target machine initialization
|
||||
/// function. Usage:
|
||||
///
|
||||
/// extern "C" void LLVMInitializeFooAsmPrinter() {
|
||||
/// extern "C" void LLVMInitializeFooAsmParser() {
|
||||
/// extern Target TheFooTarget;
|
||||
/// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
|
||||
/// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
|
||||
/// }
|
||||
template<class AsmParserImpl>
|
||||
struct RegisterAsmParser {
|
||||
@ -358,8 +364,8 @@ namespace llvm {
|
||||
}
|
||||
|
||||
private:
|
||||
static TargetAsmParser *Allocator(const Target &T) {
|
||||
return new AsmParserImpl(T);
|
||||
static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P) {
|
||||
return new AsmParserImpl(T, P);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "X86.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/MC/MCAsmLexer.h"
|
||||
#include "llvm/MC/MCAsmParser.h"
|
||||
#include "llvm/Target/TargetRegistry.h"
|
||||
#include "llvm/Target/TargetAsmParser.h"
|
||||
@ -19,25 +20,26 @@ namespace {
|
||||
};
|
||||
|
||||
class X86ATTAsmParser : public TargetAsmParser {
|
||||
MCAsmParser &Parser;
|
||||
|
||||
private:
|
||||
bool ParseOperand(X86Operand &Op);
|
||||
|
||||
bool MatchInstruction(const StringRef &Name,
|
||||
llvm::SmallVector<X86Operand, 3> &Operands,
|
||||
MCInst &Inst);
|
||||
|
||||
MCAsmLexer &getLexer() const { return Parser.getLexer(); }
|
||||
|
||||
public:
|
||||
explicit X86ATTAsmParser(const Target &);
|
||||
X86ATTAsmParser(const Target &T, MCAsmParser &_Parser)
|
||||
: TargetAsmParser(T), Parser(_Parser) {}
|
||||
|
||||
virtual bool ParseInstruction(MCAsmParser &AP, const StringRef &Name,
|
||||
MCInst &Inst);
|
||||
};
|
||||
}
|
||||
|
||||
X86ATTAsmParser::X86ATTAsmParser(const Target &T)
|
||||
: TargetAsmParser(T)
|
||||
{
|
||||
}
|
||||
|
||||
bool X86ATTAsmParser::ParseOperand(X86Operand &Op) {
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class MCValue;
|
||||
class TargetAsmParser;
|
||||
class Twine;
|
||||
|
||||
class AsmParser : MCAsmParser {
|
||||
class AsmParser : public MCAsmParser {
|
||||
public:
|
||||
struct X86Operand;
|
||||
|
||||
@ -35,18 +35,18 @@ private:
|
||||
AsmLexer Lexer;
|
||||
MCContext &Ctx;
|
||||
MCStreamer &Out;
|
||||
TargetAsmParser &TargetParser;
|
||||
TargetAsmParser *TargetParser;
|
||||
|
||||
public:
|
||||
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
||||
TargetAsmParser &_TargetParser)
|
||||
: Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
|
||||
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
|
||||
: Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {}
|
||||
~AsmParser() {}
|
||||
|
||||
bool Run();
|
||||
|
||||
public:
|
||||
TargetAsmParser &getTargetParser() const { return TargetParser; }
|
||||
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
||||
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
|
||||
|
||||
virtual MCAsmLexer &getLexer() { return Lexer; }
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/System/Signals.h"
|
||||
#include "llvm/Target/TargetAsmParser.h"
|
||||
#include "llvm/Target/TargetRegistry.h"
|
||||
#include "llvm/Target/TargetSelect.h"
|
||||
#include "AsmParser.h"
|
||||
@ -140,7 +141,8 @@ static int AsLexInput(const char *ProgName) {
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int AssembleInput(const char *ProgName) {
|
||||
static TargetAsmParser *GetTargetAsmParser(const char *ProgName,
|
||||
MCAsmParser &Parser) {
|
||||
// Get the target specific parser.
|
||||
std::string Error;
|
||||
const Target *TheTarget =
|
||||
@ -151,23 +153,24 @@ static int AssembleInput(const char *ProgName) {
|
||||
if (TheTarget == 0) {
|
||||
errs() << ProgName << ": error: unable to get target for '" << TripleName
|
||||
<< "', see --version and --triple.\n";
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TargetAsmParser *TAP = TheTarget->createAsmParser();
|
||||
if (!TAP) {
|
||||
errs() << ProgName
|
||||
<< ": error: this target does not support assembly parsing.\n";
|
||||
return 1;
|
||||
}
|
||||
if (TargetAsmParser *TAP = TheTarget->createAsmParser(Parser))
|
||||
return TAP;
|
||||
|
||||
std::string ErrorMessage;
|
||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename,
|
||||
&ErrorMessage);
|
||||
errs() << ProgName
|
||||
<< ": error: this target does not support assembly parsing.\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int AssembleInput(const char *ProgName) {
|
||||
std::string Error;
|
||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, &Error);
|
||||
if (Buffer == 0) {
|
||||
errs() << ProgName << ": ";
|
||||
if (ErrorMessage.size())
|
||||
errs() << ErrorMessage << "\n";
|
||||
if (Error.size())
|
||||
errs() << Error << "\n";
|
||||
else
|
||||
errs() << "input file didn't read correctly.\n";
|
||||
return 1;
|
||||
@ -189,7 +192,10 @@ static int AssembleInput(const char *ProgName) {
|
||||
Str.get()->SwitchSection(Ctx.GetSection("__TEXT,__text,"
|
||||
"regular,pure_instructions"));
|
||||
|
||||
AsmParser Parser(SrcMgr, Ctx, *Str.get(), *TAP);
|
||||
AsmParser Parser(SrcMgr, Ctx, *Str.get());
|
||||
OwningPtr<TargetAsmParser> TAP(GetTargetAsmParser(ProgName, Parser));
|
||||
if (!TAP)
|
||||
return 1;
|
||||
return Parser.Run();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user