amitjai
2012-Sep-20 18:52 UTC
[LLVMdev] How To Get The Name of the type the popinter is pointing to
I want to know the type of pointer . for example if we have int *p, struct node *w char *q then i want int for p,char for q , struct node for w. any help would be appreciated. -- View this message in context: http://llvm.1065342.n5.nabble.com/How-To-Get-The-Name-of-the-type-the-popinter-is-pointing-to-tp49121.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Óscar Fuentes
2012-Sep-21 02:12 UTC
[LLVMdev] How To Get The Name of the type the popinter is pointing to
amitjai <amitjaiswal.knit at gmail.com> writes:> I want to know the type of pointer . > for example > > > if we have > > int *p, > struct node *w > > char *q > > then i want int for p,char for q , struct node for w.Is your question related to Clang? If yes, you'll better ask on Clang's mailing list ( cfe-dev, see http://clang.llvm.org/ ) If your question is about LLVM, let's suppose `v' is a pointer to a llvm::Value instance or one of its derivatives, then llvm::outs() << *v << '\n'; will print on the console a reprentation of the Value, including its Type, while llvm::outs() << *v->getType() << '\n'; will print a representation of its Type. HTH.
Óscar Fuentes
2012-Sep-21 02:12 UTC
[LLVMdev] How To Get The Name of the type the popinter is pointing to
[resending message. somehow the address of llvmdev was corrupted when it reached some intermediate server] amitjai <amitjaiswal.knit at gmail.com> writes:> I want to know the type of pointer . > for example > > > if we have > > int *p, > struct node *w > > char *q > > then i want int for p,char for q , struct node for w.Is your question related to Clang? If yes, you'll better ask on Clang's mailing list ( cfe-dev, see http://clang.llvm.org/ ) If your question is about LLVM, let's suppose `v' is a pointer to a llvm::Value instance or one of its derivatives, then llvm::outs() << *v << '\n'; will print on the console a reprentation of the Value, including its Type, while llvm::outs() << *v->getType() << '\n'; will print a representation of its Type. HTH.
amitjai
2012-Sep-21 03:11 UTC
[LLVMdev] How To Get The Name of the type the popinter is pointing to
i am using llvm , i did this if ( AllocaInst *allocInst dyn_cast<AllocaInst>(&*bbit)){ PointerType *p = allocInst->getType(); if ( p->getElementType()->isPointerTy()){ StringRef name allocInst->getName(); Type *type allocInst->getOperand(0)->getType();; errs() << type->getName() << " " << name << "\n"; } } but i am getting the output in the following format i32 line i32 temp i32 p i32 filename i32 arrays i32 label i32 fp i32 head i32 b here line is char* ,temp is char* , p is int pointer,fp is file pointer ,head is pointer to list node structure and so on but why i am getting i32 for all the pointers . please help me out. -- View this message in context: http://llvm.1065342.n5.nabble.com/How-To-Get-The-Name-of-the-type-the-popinter-is-pointing-to-tp49121p49157.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Vinay M
2012-Sep-21 04:08 UTC
[LLVMdev] How To Get The Name of the type the popinter is pointing to
amitjai wrote> i am using llvm , > i did this > > if ( AllocaInst *allocInst = dyn_cast > <AllocaInst> > (&*bbit)){ > PointerType *p = allocInst->getType(); > if ( p->getElementType()->isPointerTy()){ > StringRef name > allocInst->getName(); > Type *type > allocInst->getOperand(0)->getType();; > errs() << type->getName() << " " > << name << "\n"; > } > } > > but i am getting the output in the following format > > i32 line > i32 temp > i32 p > i32 filename > i32 arrays > i32 label > i32 fp > i32 head > i32 b > > here line is char* ,temp is char* , p is int pointer,fp is file pointer > ,head is pointer to list node structure and so on > > but why i am getting i32 for all the pointers . > > please help me out.Hi , I am using the following code to get the Type of Pointer element allocated- if ( (AllocaInst *AI = dyn_cast<AllocaInst> (Inst)) ) if ( AI->getType()->getElementType()->isPointerTy() ) errs() << "\nType :- " << *AI->getType()->getElementType() << "\tName:- " << AI->getName(); "allocInst->getOperand(0)" contains the number of elements of that type to be allocated , so its type is always i32.. -- View this message in context: http://llvm.1065342.n5.nabble.com/How-To-Get-The-Name-of-the-type-the-popinter-is-pointing-to-tp49121p49159.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
NAKAMURA Takumi
2012-Sep-21 04:34 UTC
[LLVMdev] How To Get The Name of the type the popinter is pointing to
2012/9/21 amitjai <amitjaiswal.knit at gmail.com>:> i am using llvm , > i did this > > if ( AllocaInst *allocInst > dyn_cast<AllocaInst>(&*bbit)){ > PointerType *p = allocInst->getType(); > if ( p->getElementType()->isPointerTy()){ > StringRef name > allocInst->getName(); > Type *type > allocInst->getOperand(0)->getType();;(AllocaInst)getOperand(0) is "array size". It must be (ConstantInt)(i32 1) in most case. Please try AllocaInst::getAllocatedType(). ...Takumi
Seemingly Similar Threads
- [LLVMdev] How To Get The Name of the type the popinter is pointing to
- [LLVMdev] Adding function call in LLVM IR using IRBuilder causes assertion error
- [LLVMdev] Adding function call in LLVM IR using IRBuilder causes assertion error
- Converting expression to a function
- [LLVMdev] A way to pass const char* arg without creating a GlobalVariable