get value

Hello !

This may be a trivial question, but I cannot get fields from a Value type.

If my Value is i32 1, how can I store 1 in a different structure (an integer) ? For the type, I have getType(). For the value, I see no method in Value.h.

I tried to cast to ConstantExpr and then to get operands, or cast to ConstantDataArray and then use getAsString(), but is not working. How should I get the value?

Thank you !

Hi Alexandru,

if you have a Value pointer named v, you could use the method v->getValue().getLimitedValue(), which returns uint64_t, that can be casted as int.

Hope I could help,

Hi Cristianno,

Thank you, it works :slight_smile:

with an extra cast:
Value v …
ConstantInt
RR = (ConstantInt *)v;
uint64_t VV = (RR->getValue()).getLimitedValue();
errs()<<"\nRR “<<VV<<”\n";

Oops, that’s true: I forgot about that XD sorry =)

Glad I could help,

Thank you for the help :smiley:

Alexandru Ionut Diaconescu wrote:

Hi Cristianno,

Thank you, it works :slight_smile:

with an extra cast:
Value *v ......
ConstantInt* RR = (ConstantInt *)v;

Please use "cast<ConstantInt>(v)" instead. See http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates .

Nick

Thank you !