mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
Add MCAsmParser interface.
- This provides the AsmParser interface to the target specific assembly parsers. llvm-svn: 76453
This commit is contained in:
parent
d94fbfccea
commit
fca75cd98e
33
include/llvm/MC/MCAsmParser.h
Normal file
33
include/llvm/MC/MCAsmParser.h
Normal file
@ -0,0 +1,33 @@
|
||||
//===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- 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_MCASMPARSER_H
|
||||
#define LLVM_MC_MCASMPARSER_H
|
||||
|
||||
namespace llvm {
|
||||
class MCAsmParser;
|
||||
class MCInst;
|
||||
class Target;
|
||||
class TargetAsmParser;
|
||||
|
||||
/// MCAsmParser - Generic assembler parser interface, for use by target specific
|
||||
/// assembly parsers.
|
||||
class MCAsmParser {
|
||||
MCAsmParser(const MCAsmParser &); // DO NOT IMPLEMENT
|
||||
void operator=(const MCAsmParser &); // DO NOT IMPLEMENT
|
||||
protected: // Can only create subclasses.
|
||||
MCAsmParser();
|
||||
|
||||
public:
|
||||
virtual ~MCAsmParser();
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
@ -11,6 +11,8 @@
|
||||
#define LLVM_TARGET_TARGETPARSER_H
|
||||
|
||||
namespace llvm {
|
||||
class MCAsmParser;
|
||||
class MCInst;
|
||||
class Target;
|
||||
|
||||
/// TargetAsmParser - Generic interface to target specific assembly parsers.
|
||||
@ -27,6 +29,21 @@ public:
|
||||
virtual ~TargetAsmParser();
|
||||
|
||||
const Target &getTarget() const { return TheTarget; }
|
||||
|
||||
/// ParseInstruction - Parse one assembly instruction.
|
||||
///
|
||||
/// The parser is positioned following the instruction name. The target
|
||||
/// specific instruction parser should parse the entire instruction and
|
||||
/// construct the appropriate MCInst, or emit an error. On success, the entire
|
||||
/// line should be parsed up to and including the end-of-statement token. On
|
||||
/// failure, the parser is not required to read to the end of the line.
|
||||
//
|
||||
/// \param AP - The current parser object.
|
||||
/// \param Name - The instruction name.
|
||||
/// \param Inst [out] - On success, the parsed instruction.
|
||||
/// \return True on failure.
|
||||
virtual bool ParseInstruction(MCAsmParser &AP, const char *Name,
|
||||
MCInst &Inst) = 0;
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
@ -1,4 +1,5 @@
|
||||
add_llvm_library(LLVMMC
|
||||
MCAsmParser.cpp
|
||||
MCAsmStreamer.cpp
|
||||
MCContext.cpp
|
||||
MCStreamer.cpp
|
||||
|
18
lib/MC/MCAsmParser.cpp
Normal file
18
lib/MC/MCAsmParser.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
//===-- MCAsmParser.cpp - Abstract Asm Parser Interface -------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/MC/MCAsmParser.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
MCAsmParser::MCAsmParser() {
|
||||
}
|
||||
|
||||
MCAsmParser::~MCAsmParser() {
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "X86.h"
|
||||
#include "llvm/MC/MCAsmParser.h"
|
||||
#include "llvm/Target/TargetRegistry.h"
|
||||
#include "llvm/Target/TargetAsmParser.h"
|
||||
using namespace llvm;
|
||||
@ -17,6 +18,9 @@ namespace {
|
||||
class X86ATTAsmParser : public TargetAsmParser {
|
||||
public:
|
||||
explicit X86ATTAsmParser(const Target &);
|
||||
|
||||
virtual bool ParseInstruction(MCAsmParser &AP, const char *Name,
|
||||
MCInst &Inst);
|
||||
};
|
||||
|
||||
}
|
||||
@ -26,6 +30,11 @@ X86ATTAsmParser::X86ATTAsmParser(const Target &T)
|
||||
{
|
||||
}
|
||||
|
||||
bool X86ATTAsmParser::ParseInstruction(MCAsmParser &AP, const char *Name,
|
||||
MCInst &Inst) {
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
TargetAsmParser *createAsmParser(const Target &T) {
|
||||
return new X86ATTAsmParser(T);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetAsmParser.h"
|
||||
using namespace llvm;
|
||||
|
||||
void AsmParser::Warning(SMLoc L, const char *Msg) {
|
||||
@ -548,7 +549,8 @@ bool AsmParser::ParseStatement() {
|
||||
}
|
||||
|
||||
MCInst Inst;
|
||||
if (ParseX86InstOperands(IDVal, Inst))
|
||||
if (ParseX86InstOperands(IDVal, Inst) &&
|
||||
getTargetParser().ParseInstruction(*this, IDVal, Inst))
|
||||
return true;
|
||||
|
||||
if (Lexer.isNot(asmtok::EndOfStatement))
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define ASMPARSER_H
|
||||
|
||||
#include "AsmLexer.h"
|
||||
#include "llvm/MC/MCAsmParser.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -24,7 +25,7 @@ class MCInst;
|
||||
class MCStreamer;
|
||||
class MCValue;
|
||||
|
||||
class AsmParser {
|
||||
class AsmParser : MCAsmParser {
|
||||
public:
|
||||
struct X86Operand;
|
||||
|
||||
@ -32,14 +33,19 @@ private:
|
||||
AsmLexer Lexer;
|
||||
MCContext &Ctx;
|
||||
MCStreamer &Out;
|
||||
TargetAsmParser &TargetParser;
|
||||
|
||||
public:
|
||||
AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
|
||||
: Lexer(SM), Ctx(ctx), Out(OutStr) {}
|
||||
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
||||
TargetAsmParser &_TargetParser)
|
||||
: Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
|
||||
~AsmParser() {}
|
||||
|
||||
bool Run();
|
||||
|
||||
public:
|
||||
TargetAsmParser &getTargetParser() const { return TargetParser; }
|
||||
|
||||
private:
|
||||
bool ParseStatement();
|
||||
|
||||
|
@ -186,9 +186,10 @@ static int AssembleInput(const char *ProgName) {
|
||||
OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs()));
|
||||
|
||||
// FIXME: Target hook & command line option for initial section.
|
||||
Str.get()->SwitchSection(Ctx.GetSection("__TEXT,__text,regular,pure_instructions"));
|
||||
Str.get()->SwitchSection(Ctx.GetSection("__TEXT,__text,"
|
||||
"regular,pure_instructions"));
|
||||
|
||||
AsmParser Parser(SrcMgr, Ctx, *Str.get());
|
||||
AsmParser Parser(SrcMgr, Ctx, *Str.get(), *TAP);
|
||||
return Parser.Run();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user