mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-12 17:25:49 +00:00
Add MCAsmParser interface.
- This provides the AsmParser interface to the target specific assembly parsers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76453 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
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
|
#define LLVM_TARGET_TARGETPARSER_H
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class MCAsmParser;
|
||||||
|
class MCInst;
|
||||||
class Target;
|
class Target;
|
||||||
|
|
||||||
/// TargetAsmParser - Generic interface to target specific assembly parsers.
|
/// TargetAsmParser - Generic interface to target specific assembly parsers.
|
||||||
@@ -27,6 +29,21 @@ public:
|
|||||||
virtual ~TargetAsmParser();
|
virtual ~TargetAsmParser();
|
||||||
|
|
||||||
const Target &getTarget() const { return TheTarget; }
|
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
|
} // End llvm namespace
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
add_llvm_library(LLVMMC
|
add_llvm_library(LLVMMC
|
||||||
|
MCAsmParser.cpp
|
||||||
MCAsmStreamer.cpp
|
MCAsmStreamer.cpp
|
||||||
MCContext.cpp
|
MCContext.cpp
|
||||||
MCStreamer.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 "X86.h"
|
||||||
|
#include "llvm/MC/MCAsmParser.h"
|
||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
#include "llvm/Target/TargetAsmParser.h"
|
#include "llvm/Target/TargetAsmParser.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -17,6 +18,9 @@ namespace {
|
|||||||
class X86ATTAsmParser : public TargetAsmParser {
|
class X86ATTAsmParser : public TargetAsmParser {
|
||||||
public:
|
public:
|
||||||
explicit X86ATTAsmParser(const Target &);
|
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 {
|
namespace {
|
||||||
TargetAsmParser *createAsmParser(const Target &T) {
|
TargetAsmParser *createAsmParser(const Target &T) {
|
||||||
return new X86ATTAsmParser(T);
|
return new X86ATTAsmParser(T);
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "llvm/MC/MCSymbol.h"
|
#include "llvm/MC/MCSymbol.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
#include "llvm/Target/TargetAsmParser.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
void AsmParser::Warning(SMLoc L, const char *Msg) {
|
void AsmParser::Warning(SMLoc L, const char *Msg) {
|
||||||
@@ -548,7 +549,8 @@ bool AsmParser::ParseStatement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MCInst Inst;
|
MCInst Inst;
|
||||||
if (ParseX86InstOperands(IDVal, Inst))
|
if (ParseX86InstOperands(IDVal, Inst) &&
|
||||||
|
getTargetParser().ParseInstruction(*this, IDVal, Inst))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (Lexer.isNot(asmtok::EndOfStatement))
|
if (Lexer.isNot(asmtok::EndOfStatement))
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#define ASMPARSER_H
|
#define ASMPARSER_H
|
||||||
|
|
||||||
#include "AsmLexer.h"
|
#include "AsmLexer.h"
|
||||||
|
#include "llvm/MC/MCAsmParser.h"
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@@ -24,7 +25,7 @@ class MCInst;
|
|||||||
class MCStreamer;
|
class MCStreamer;
|
||||||
class MCValue;
|
class MCValue;
|
||||||
|
|
||||||
class AsmParser {
|
class AsmParser : MCAsmParser {
|
||||||
public:
|
public:
|
||||||
struct X86Operand;
|
struct X86Operand;
|
||||||
|
|
||||||
@@ -32,14 +33,19 @@ private:
|
|||||||
AsmLexer Lexer;
|
AsmLexer Lexer;
|
||||||
MCContext &Ctx;
|
MCContext &Ctx;
|
||||||
MCStreamer &Out;
|
MCStreamer &Out;
|
||||||
|
TargetAsmParser &TargetParser;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
|
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
||||||
: Lexer(SM), Ctx(ctx), Out(OutStr) {}
|
TargetAsmParser &_TargetParser)
|
||||||
|
: Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
|
||||||
~AsmParser() {}
|
~AsmParser() {}
|
||||||
|
|
||||||
bool Run();
|
bool Run();
|
||||||
|
|
||||||
|
public:
|
||||||
|
TargetAsmParser &getTargetParser() const { return TargetParser; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ParseStatement();
|
bool ParseStatement();
|
||||||
|
|
||||||
|
@@ -186,9 +186,10 @@ static int AssembleInput(const char *ProgName) {
|
|||||||
OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs()));
|
OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs()));
|
||||||
|
|
||||||
// FIXME: Target hook & command line option for initial section.
|
// 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();
|
return Parser.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user