[LLVMdev] get the value of a Constant in LLVM IR

582 views
Skip to first unread message

Eirini Psallida

unread,
Oct 17, 2013, 9:42:30 AM10/17/13
to llv...@cs.uiuc.edu
Hello,
i parse the llvm IR (llvm-3.3 version) and when i meet a constant, i want to get it's value.
eg i32 5,   i want to get the 5.
I am interested in ConstantInt-ConstantFP-ConstantArray-ConstantStruct subclasses.
Things are a bit easier with ConstantInt and ConstantFP constants but how
could i get the value of a ConstantArray?
says:
ConstantArray : This represents a constant array.
const std::vector<Use> &getValues() const: Returns a vector of component constants that makeup this array.
But i cannot find this method, i think that it is not implemented in the 3.3 version.
There is the method 'Value::print()' but this gives me also the type which is not what i want.
I found also the 'static void WriteConstantInternal()' method in llvm/lib/IR/AsmWriter.cpp which is called
by 'Value::print()' but it is 'static' so i cannot access it.  I need something like the 'WriteConstantInternal' method.
Any ideas?

Thanks

Eirini

John Criswell

unread,
Oct 17, 2013, 11:00:54 AM10/17/13
to Eirini Psallida, llv...@cs.uiuc.edu
On 10/17/13 8:42 AM, Eirini Psallida wrote:
Hello,
i parse the llvm IR (llvm-3.3 version) and when i meet a constant, i want to get it's value.
eg i32 5,   i want to get the 5.
I am interested in ConstantInt-ConstantFP-ConstantArray-ConstantStruct subclasses.
Things are a bit easier with ConstantInt and ConstantFP constants but how
could i get the value of a ConstantArray?
says:
ConstantArray : This represents a constant array.

ConstantArray is a subclass of Constant.  Constant, in turn, has a method called getAggregateElement() that will return the Constant * value at the specified offset within the aggregate constant (be it an array, vector, etc.).

For more information, consult the Constant class doxygen page:

http://llvm.org/doxygen/classllvm_1_1Constant.html

-- John T.

Reply all
Reply to author
Forward
0 new messages