I am processing the LLVM instructions and right now I am at the 'call' instruction. For now I just want to print the argument type. For example in the following: %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] I need to get access to 'i32' and '8' separately. I do: CallInst *CI = dyn_cast<CallInst>(I); Value *v = CI->getOperand(1) I can get the type via v->getType() and that returns 'i32', which is good. But I also need to get the value '8'. I can get it via v->getValueID(), but in the documentation it says not to use that function. Any other ideas what is the proper way to access the value '8' ? thanks -- View this message in context: http://www.nabble.com/Printing-Function-Arguments-tp25638981p25638981.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
ivtm wrote:> I am processing the LLVM instructions and right now I am at the 'call' > instruction. > For now I just want to print the argument type. > > For example in the following: > > %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] > > I need to get access to 'i32' and '8' separately. > > I do: > > CallInst *CI = dyn_cast<CallInst>(I); > Value *v = CI->getOperand(1) > > I can get the type via v->getType() and that returns 'i32', which is good. > > But I also need to get the value '8'. > > I can get it via v->getValueID(), but in the documentation it says not to > use that function.Heh. No, getValueID() returns '8' as the "ConstantIntVal" enum, not the actual argument number.> Any other ideas what is the proper way to access the value '8' ?It's a ConstantInt, so cast it and retrieve the APInt then pull out the number. Here: unsigned val; if (ConstantInt *CI = dyn_cast<ConstantInt>(v)) { val = CI->getValue()->getSExtValue(); } Nick
Hi Nick, Thanks, that seemed to work. Nick Lewycky wrote:> > ivtm wrote: >> I am processing the LLVM instructions and right now I am at the 'call' >> instruction. >> For now I just want to print the argument type. >> >> For example in the following: >> >> %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] >> >> I need to get access to 'i32' and '8' separately. >> >> I do: >> >> CallInst *CI = dyn_cast<CallInst>(I); >> Value *v = CI->getOperand(1) >> >> I can get the type via v->getType() and that returns 'i32', which is >> good. >> >> But I also need to get the value '8'. >> >> I can get it via v->getValueID(), but in the documentation it says not to >> use that function. > > Heh. No, getValueID() returns '8' as the "ConstantIntVal" enum, not the > actual argument number. > >> Any other ideas what is the proper way to access the value '8' ? > > It's a ConstantInt, so cast it and retrieve the APInt then pull out the > number. Here: > > unsigned val; > if (ConstantInt *CI = dyn_cast<ConstantInt>(v)) { > val = CI->getValue()->getSExtValue(); > } > > Nick > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- View this message in context: http://www.nabble.com/Printing-Function-Arguments-tp25638981p25639806.html Sent from the LLVM - Dev mailing list archive at Nabble.com.