From 01855071e24e0e3e75306b82267d3ad0b13a0c15 Mon Sep 17 00:00:00 2001 From: Jim Grosbach Date: Mon, 11 Oct 2010 18:25:51 +0000 Subject: When figuring out which operands match which encoding fields in an instruction, try to match them by name first. If there is no by-name match, fall back to assuming they are in order (this was the previous behavior). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116211 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/CodeGenInstruction.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'utils/TableGen/CodeGenInstruction.cpp') diff --git a/utils/TableGen/CodeGenInstruction.cpp b/utils/TableGen/CodeGenInstruction.cpp index 01a1fe11f5..722ae53ed5 100644 --- a/utils/TableGen/CodeGenInstruction.cpp +++ b/utils/TableGen/CodeGenInstruction.cpp @@ -234,13 +234,26 @@ CodeGenInstruction::CodeGenInstruction(Record *R, const std::string &AsmStr) /// specified name, throw an exception. /// unsigned CodeGenInstruction::getOperandNamed(const std::string &Name) const { - assert(!Name.empty() && "Cannot search for operand with no name!"); - for (unsigned i = 0, e = OperandList.size(); i != e; ++i) - if (OperandList[i].Name == Name) return i; + unsigned OpIdx; + if (hasOperandNamed(Name, OpIdx)) return OpIdx; throw "Instruction '" + TheDef->getName() + "' does not have an operand named '$" + Name + "'!"; } +/// hasOperandNamed - Query whether the instruction has an operand of the +/// given name. If so, return true and set OpIdx to the index of the +/// operand. Otherwise, return false. +bool CodeGenInstruction::hasOperandNamed(const std::string &Name, + unsigned &OpIdx) const { + assert(!Name.empty() && "Cannot search for operand with no name!"); + for (unsigned i = 0, e = OperandList.size(); i != e; ++i) + if (OperandList[i].Name == Name) { + OpIdx = i; + return true; + } + return false; +} + std::pair CodeGenInstruction::ParseOperandName(const std::string &Op, bool AllowWholeOp) { -- cgit v1.2.3-70-g09d2