mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
change the protocol TargetAsmPArser::MatchInstruction method to take an
MCStreamer to emit into instead of an MCInst to fill in. This allows the matcher extra flexibility and is more convenient. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115014 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
|
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCInst;
|
class MCStreamer;
|
||||||
class StringRef;
|
class StringRef;
|
||||||
class Target;
|
class Target;
|
||||||
class SMLoc;
|
class SMLoc;
|
||||||
@@ -70,16 +70,16 @@ public:
|
|||||||
/// \param DirectiveID - the identifier token of the directive.
|
/// \param DirectiveID - the identifier token of the directive.
|
||||||
virtual bool ParseDirective(AsmToken DirectiveID) = 0;
|
virtual bool ParseDirective(AsmToken DirectiveID) = 0;
|
||||||
|
|
||||||
/// MatchInstruction - Recognize a series of operands of a parsed instruction
|
/// MatchAndEmitInstruction - Recognize a series of operands of a parsed
|
||||||
/// as an actual MCInst. This returns false and fills in Inst on success and
|
/// instruction as an actual MCInst and emit it to the specified MCStreamer.
|
||||||
/// returns true on failure to match.
|
/// This returns false on success and returns true on failure to match.
|
||||||
///
|
///
|
||||||
/// On failure, the target parser is responsible for emitting a diagnostic
|
/// On failure, the target parser is responsible for emitting a diagnostic
|
||||||
/// explaining the match failure.
|
/// explaining the match failure.
|
||||||
virtual bool
|
virtual bool
|
||||||
MatchInstruction(SMLoc IDLoc,
|
MatchAndEmitInstruction(SMLoc IDLoc,
|
||||||
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
||||||
MCInst &Inst) = 0;
|
MCStreamer &Out) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
|
||||||
#include "llvm/MC/MCParser/AsmCond.h"
|
#include "llvm/MC/MCParser/AsmCond.h"
|
||||||
#include "llvm/MC/MCParser/AsmLexer.h"
|
#include "llvm/MC/MCParser/AsmLexer.h"
|
||||||
#include "llvm/MC/MCParser/MCAsmParser.h"
|
#include "llvm/MC/MCParser/MCAsmParser.h"
|
||||||
@@ -1047,14 +1046,9 @@ bool AsmParser::ParseStatement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If parsing succeeded, match the instruction.
|
// If parsing succeeded, match the instruction.
|
||||||
if (!HadError) {
|
if (!HadError)
|
||||||
MCInst Inst;
|
HadError = getTargetParser().MatchAndEmitInstruction(IDLoc, ParsedOperands,
|
||||||
if (!getTargetParser().MatchInstruction(IDLoc, ParsedOperands, Inst)) {
|
Out);
|
||||||
// Emit the instruction on success.
|
|
||||||
Out.EmitInstruction(Inst);
|
|
||||||
} else
|
|
||||||
HadError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free any parsed operands.
|
// Free any parsed operands.
|
||||||
for (unsigned i = 0, e = ParsedOperands.size(); i != e; ++i)
|
for (unsigned i = 0, e = ParsedOperands.size(); i != e; ++i)
|
||||||
|
@@ -80,16 +80,18 @@ private:
|
|||||||
|
|
||||||
bool ParseDirectiveSyntax(SMLoc L);
|
bool ParseDirectiveSyntax(SMLoc L);
|
||||||
|
|
||||||
bool MatchInstruction(SMLoc IDLoc,
|
bool MatchAndEmitInstruction(SMLoc IDLoc,
|
||||||
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
||||||
MCInst &Inst) {
|
MCStreamer &Out) {
|
||||||
|
MCInst Inst;
|
||||||
unsigned ErrorInfo;
|
unsigned ErrorInfo;
|
||||||
if (MatchInstructionImpl(Operands, Inst, ErrorInfo) == Match_Success)
|
if (MatchInstructionImpl(Operands, Inst, ErrorInfo) == Match_Success) {
|
||||||
|
Out.EmitInstruction(Inst);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: We should give nicer diagnostics about the exact failure.
|
// FIXME: We should give nicer diagnostics about the exact failure.
|
||||||
Error(IDLoc, "unrecognized instruction");
|
Error(IDLoc, "unrecognized instruction");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ class X86ATTAsmParser : public TargetAsmParser {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned Is64Bit : 1;
|
unsigned Is64Bit : 1;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MCAsmParser &getParser() const { return Parser; }
|
MCAsmParser &getParser() const { return Parser; }
|
||||||
|
|
||||||
@@ -51,9 +51,9 @@ private:
|
|||||||
|
|
||||||
bool ParseDirectiveWord(unsigned Size, SMLoc L);
|
bool ParseDirectiveWord(unsigned Size, SMLoc L);
|
||||||
|
|
||||||
bool MatchInstruction(SMLoc IDLoc,
|
bool MatchAndEmitInstruction(SMLoc IDLoc,
|
||||||
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
||||||
MCInst &Inst);
|
MCStreamer &Out);
|
||||||
|
|
||||||
/// @name Auto-generated Matcher Functions
|
/// @name Auto-generated Matcher Functions
|
||||||
/// {
|
/// {
|
||||||
@@ -66,7 +66,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
X86ATTAsmParser(const Target &T, MCAsmParser &_Parser, TargetMachine &TM)
|
X86ATTAsmParser(const Target &T, MCAsmParser &_Parser, TargetMachine &TM)
|
||||||
: TargetAsmParser(T), Parser(_Parser), TM(TM) {
|
: TargetAsmParser(T), Parser(_Parser), TM(TM) {
|
||||||
|
|
||||||
// Initialize the set of available features.
|
// Initialize the set of available features.
|
||||||
setAvailableFeatures(ComputeAvailableFeatures(
|
setAvailableFeatures(ComputeAvailableFeatures(
|
||||||
&TM.getSubtarget<X86Subtarget>()));
|
&TM.getSubtarget<X86Subtarget>()));
|
||||||
@@ -1108,17 +1108,19 @@ bool X86ATTAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
|
|||||||
|
|
||||||
|
|
||||||
bool X86ATTAsmParser::
|
bool X86ATTAsmParser::
|
||||||
MatchInstruction(SMLoc IDLoc,
|
MatchAndEmitInstruction(SMLoc IDLoc,
|
||||||
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
|
||||||
MCInst &Inst) {
|
MCStreamer &Out) {
|
||||||
assert(!Operands.empty() && "Unexpect empty operand list!");
|
assert(!Operands.empty() && "Unexpect empty operand list!");
|
||||||
|
|
||||||
bool WasOriginallyInvalidOperand = false;
|
bool WasOriginallyInvalidOperand = false;
|
||||||
unsigned OrigErrorInfo;
|
unsigned OrigErrorInfo;
|
||||||
|
MCInst Inst;
|
||||||
|
|
||||||
// First, try a direct match.
|
// First, try a direct match.
|
||||||
switch (MatchInstructionImpl(Operands, Inst, OrigErrorInfo)) {
|
switch (MatchInstructionImpl(Operands, Inst, OrigErrorInfo)) {
|
||||||
case Match_Success:
|
case Match_Success:
|
||||||
|
Out.EmitInstruction(Inst);
|
||||||
return false;
|
return false;
|
||||||
case Match_MissingFeature:
|
case Match_MissingFeature:
|
||||||
Error(IDLoc, "instruction requires a CPU feature not currently enabled");
|
Error(IDLoc, "instruction requires a CPU feature not currently enabled");
|
||||||
@@ -1165,8 +1167,10 @@ MatchInstruction(SMLoc IDLoc,
|
|||||||
unsigned NumSuccessfulMatches =
|
unsigned NumSuccessfulMatches =
|
||||||
(MatchB == Match_Success) + (MatchW == Match_Success) +
|
(MatchB == Match_Success) + (MatchW == Match_Success) +
|
||||||
(MatchL == Match_Success) + (MatchQ == Match_Success);
|
(MatchL == Match_Success) + (MatchQ == Match_Success);
|
||||||
if (NumSuccessfulMatches == 1)
|
if (NumSuccessfulMatches == 1) {
|
||||||
|
Out.EmitInstruction(Inst);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, the match failed, try to produce a decent error message.
|
// Otherwise, the match failed, try to produce a decent error message.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user