From f29c0b6880c217b65a6a1df18a54e308719e48b3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 14 Jan 2010 22:21:20 +0000 Subject: Split the TargetAsmParser "ParseInstruction" interface in half: the new ParseInstruction method just parses and returns a list of target operands. A new MatchInstruction interface is used to turn the operand list into an MCInst. This requires new/deleting all the operands, but it also gives targets the ability to use polymorphic operands if they want to. llvm-svn: 93469 --- llvm/tools/llvm-mc/AsmParser.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'llvm/tools/llvm-mc/AsmParser.cpp') diff --git a/llvm/tools/llvm-mc/AsmParser.cpp b/llvm/tools/llvm-mc/AsmParser.cpp index 4ef3a7fc355..bd0e0e259dc 100644 --- a/llvm/tools/llvm-mc/AsmParser.cpp +++ b/llvm/tools/llvm-mc/AsmParser.cpp @@ -18,6 +18,7 @@ #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCParsedAsmOperand.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" @@ -710,16 +711,34 @@ bool AsmParser::ParseStatement() { return false; } - MCInst Inst; - if (getTargetParser().ParseInstruction(IDVal, IDLoc, Inst)) + + SmallVector ParsedOperands; + if (getTargetParser().ParseInstruction(IDVal, IDLoc, ParsedOperands)) + // FIXME: Leaking ParsedOperands on failure. return true; if (Lexer.isNot(AsmToken::EndOfStatement)) + // FIXME: Leaking ParsedOperands on failure. return TokError("unexpected token in argument list"); // Eat the end of statement marker. Lexer.Lex(); + + MCInst Inst; + + bool MatchFail = getTargetParser().MatchInstruction(ParsedOperands, Inst); + + // Free any parsed operands. + for (unsigned i = 0, e = ParsedOperands.size(); i != e; ++i) + delete ParsedOperands[i]; + + if (MatchFail) { + // FIXME: We should give nicer diagnostics about the exact failure. + Error(IDLoc, "unrecognized instruction"); + return true; + } + // Instruction is good, process it. Out.EmitInstruction(Inst); -- cgit v1.2.3