diff options
author | Chris Lattner <sabre@nondot.org> | 2010-11-06 06:54:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-11-06 06:54:38 +0000 |
commit | 7603052d4928f550e59ebca8c225a77c3fa42cfa (patch) | |
tree | 6d50d839c96337a578b952f582d6c00e44edb2bd /llvm/utils | |
parent | 23064cb4e513753ee5b9bb2241a5ba94b2b8c187 (diff) | |
download | bcm5719-llvm-7603052d4928f550e59ebca8c225a77c3fa42cfa.tar.gz bcm5719-llvm-7603052d4928f550e59ebca8c225a77c3fa42cfa.zip |
decode and validate instruction alias result definitions.
llvm-svn: 118327
Diffstat (limited to 'llvm/utils')
-rw-r--r-- | llvm/utils/TableGen/CodeGenInstruction.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/CodeGenInstruction.cpp b/llvm/utils/TableGen/CodeGenInstruction.cpp index 3c58cc63995..f1ba6f7200f 100644 --- a/llvm/utils/TableGen/CodeGenInstruction.cpp +++ b/llvm/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"); + } } |