aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-11-06 06:54:38 +0000
committerChris Lattner <sabre@nondot.org>2010-11-06 06:54:38 +0000
commitd0f225cafc76ee2d4982c207c6afb25aaf176d12 (patch)
tree7a91704f2e60475e67530af538eca0726eb392b4 /utils
parent9cdf42858960b9903587c39d5341cf63b3e665db (diff)
downloadexternal_llvm-d0f225cafc76ee2d4982c207c6afb25aaf176d12.zip
external_llvm-d0f225cafc76ee2d4982c207c6afb25aaf176d12.tar.gz
external_llvm-d0f225cafc76ee2d4982c207c6afb25aaf176d12.tar.bz2
decode and validate instruction alias result definitions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118327 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/CodeGenInstruction.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/utils/TableGen/CodeGenInstruction.cpp b/utils/TableGen/CodeGenInstruction.cpp
index 3c58cc6..f1ba6f7 100644
--- a/utils/TableGen/CodeGenInstruction.cpp
+++ b/utils/TableGen/CodeGenInstruction.cpp
@@ -400,4 +400,37 @@ CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T)
throw TGError(R->getLoc(), "result of inst alias should be an instruction");
ResultInst = &T.getInstruction(DI->getDef());
+
+ // Check number of arguments in the result.
+ if (ResultInst->Operands.size() != Result->getNumArgs())
+ throw TGError(R->getLoc(), "result has " + utostr(Result->getNumArgs()) +
+ " arguments, but " + ResultInst->TheDef->getName() +
+ " instruction expects " + utostr(ResultInst->Operands.size())+
+ " operands!");
+
+ // Decode and validate the arguments of the result.
+ for (unsigned i = 0, e = Result->getNumArgs(); i != e; ++i) {
+ Init *Arg = Result->getArg(i);
+
+ // If the operand is a record, it must have a name, and the record type must
+ // match up with the instruction's argument type.
+ if (DefInit *ADI = dynamic_cast<DefInit*>(Arg)) {
+ if (Result->getArgName(i).empty())
+ throw TGError(R->getLoc(), "result argument #" + utostr(i) +
+ " must have a name!");
+
+ if (ADI->getDef() != ResultInst->Operands[i].Rec)
+ throw TGError(R->getLoc(), "result argument #" + utostr(i) +
+ " declared with class " + ADI->getDef()->getName() +
+ ", instruction operand is class " +
+ ResultInst->Operands[i].Rec->getName());
+
+ // Now that it is validated, add it.
+ ResultOperands.push_back(ResultOperand(Result->getArgName(i),
+ ADI->getDef()));
+ continue;
+ }
+
+ throw TGError(R->getLoc(), "result of inst alias has unknown operand type");
+ }
}