[LLVMdev] RE: printing constants

Chris Lattner sabre at nondot.org
Thu Mar 2 09:53:23 PST 2006


On Thu, 2 Mar 2006, anubham suresh wrote:
> here I have a question regarding printing of the
> constants( like  2 .63 etc.,) present in the
> instruction while iterating over the instructions
> within a basic block .
> I am able to print the vaiables but not the
> constants.
> Can you please tell me how to get the constants
> printed out while iterating over the instructions
> because the constants do not have names as the
> variables do( like temp12,temp131 etc.,).

I'm not really sure what you want to do.  If you're trying to print out 
all of the literal constants in instructions in a function, you can use 
the llvm/Analysis/ConstantsScanner.h interface to do this.  Something like 
this:

   Function *F = ...
   for (constant_iterator I = constant_begin(F), E = constant_end(F);
        I != E; ++I)
     std::cerr << *I;

Given code like:

   X = add int Y, 1
   Z = mul int X, 17

It will print out 1 and 17.

Is this what you mean?

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/




More information about the llvm-dev mailing list