diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-14 22:21:20 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-14 22:21:20 +0000 |
commit | 9898671a74d3fc924347e679c45edaa685b3fe6e (patch) | |
tree | 76d99c3c2c48dca2e8c078c6bb32a062c28536fe /tools | |
parent | 74a265686dd3e816c0f580c77d07fbb9e8bf3ddd (diff) | |
download | external_llvm-9898671a74d3fc924347e679c45edaa685b3fe6e.zip external_llvm-9898671a74d3fc924347e679c45edaa685b3fe6e.tar.gz external_llvm-9898671a74d3fc924347e679c45edaa685b3fe6e.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-mc/AsmLexer.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.cpp | 23 |
2 files changed, 22 insertions, 3 deletions
diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp index 99055c6..ba0d247 100644 --- a/tools/llvm-mc/AsmLexer.cpp +++ b/tools/llvm-mc/AsmLexer.cpp @@ -44,7 +44,7 @@ void AsmLexer::PrintMessage(SMLoc Loc, const std::string &Msg, /// ReturnError - Set the error to the specified string at the specified /// location. This is defined to always return AsmToken::Error. AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) { - SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error"); + PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error"); return AsmToken(AsmToken::Error, StringRef(Loc, 0)); } diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index 4ef3a7f..bd0e0e2 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/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<MCParsedAsmOperand*, 8> 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); |