+ | INVOKE TypesV ValueRef '(' ValueRefListE ')' TO ResolvedVal
+ EXCEPT ResolvedVal {
+ const PointerType *PMTy;
+ const MethodType *Ty;
+
+ if (!(PMTy = dyn_cast<PointerType>($2->get())) ||
+ !(Ty = dyn_cast<MethodType>(PMTy->getValueType()))) {
+ // Pull out the types of all of the arguments...
+ vector<const Type*> ParamTypes;
+ if ($5) {
+ for (vector<Value*>::iterator I = $5->begin(), E = $5->end(); I!=E; ++I)
+ ParamTypes.push_back((*I)->getType());
+ }
+
+ bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
+ if (isVarArg) ParamTypes.pop_back();
+
+ Ty = MethodType::get($2->get(), ParamTypes, isVarArg);
+ PMTy = PointerType::get(Ty);
+ }
+ delete $2;
+
+ Value *V = getVal(PMTy, $3); // Get the method we're calling...
+
+ BasicBlock *Normal = dyn_cast<BasicBlock>($8);
+ BasicBlock *Except = dyn_cast<BasicBlock>($10);
+
+ if (Normal == 0 || Except == 0)
+ ThrowException("Invoke instruction without label destinations!");
+
+ // Create the call node...
+ if (!$5) { // Has no arguments?
+ $$ = new InvokeInst(V, Normal, Except, vector<Value*>());
+ } else { // Has arguments?
+ // Loop through MethodType's arguments and ensure they are specified
+ // correctly!
+ //
+ MethodType::ParamTypes::const_iterator I = Ty->getParamTypes().begin();
+ MethodType::ParamTypes::const_iterator E = Ty->getParamTypes().end();
+ vector<Value*>::iterator ArgI = $5->begin(), ArgE = $5->end();
+
+ for (; ArgI != ArgE && I != E; ++ArgI, ++I)
+ if ((*ArgI)->getType() != *I)
+ ThrowException("Parameter " +(*ArgI)->getName()+ " is not of type '" +
+ (*I)->getName() + "'!");
+
+ if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
+ ThrowException("Invalid number of parameters detected!");
+
+ $$ = new InvokeInst(V, Normal, Except, *$5);
+ }
+ delete $5;
+ }
+
+