How To Get The Name of the type the popinter is pointing to

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How To Get The Name of the type the popinter is pointing to

amitjai
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: How To Get The Name of the type the popinter is pointing to

Óscar Fuentes
amitjai <[hidden email]> 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.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: How To Get The Name of the type the popinter is pointing to

Óscar Fuentes
In reply to this post by amitjai
[resending message. somehow the address of llvmdev was corrupted when it
reached some intermediate server]

amitjai <[hidden email]> 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.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: How To Get The Name of the type the popinter is pointing to

amitjai
In reply to this post by amitjai
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: How To Get The Name of the type the popinter is pointing to

Vinay M
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..
 
   
Reply | Threaded
Open this post in threaded view
|

Re: How To Get The Name of the type the popinter is pointing to

NAKAMURA Takumi
In reply to this post by amitjai
2012/9/21 amitjai <[hidden email]>:

> 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
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev